programs for c language practical

Upload: gaurav-pathak

Post on 03-Apr-2018

218 views

Category:

Documents


0 download

TRANSCRIPT

  • 7/28/2019 Programs for C language Practical

    1/15

    Program 1- To check whether the inputed character is an alphabet or a digit

    or a special symbol.

    #include

    #include

    char char_is(char a);

    void main()

    {

    clrscr();

    char ch,ct;

    printf("Enter a character= ");

    ch=getchar();

    ct=char_is(ch);

    if(ct=='A')

    printf("It is an Alphabet.");

    else if(ct=='D')

    printf("It is a Digit.");

    else if(ct=='X')

    printf("It is a Special Character.");

    getch();

    }

    /* Function Declaration to determine character type*/

    char char_is(char a)

    {

    if((a>='a' && a='A' && a='0'&&a

  • 7/28/2019 Programs for C language Practical

    2/15

    Program 2- To read a line of text and count the number of vowels,

    consonants digits and blank spaces.

    #include

    #include

    void main()

    {

    clrscr();

    char line[50],ch;

    int vow=0,con=0,dig=0,bs=0,count=0;

    printf("Enter a line of text:\n");

    gets(line);

    for(;(ch=line[count])!='\0';count++){

    if(ch=='A'||ch=='E'||ch=='I'||ch=='O'||ch=='U'||ch=='a'||ch=='e'||ch=='i'||ch=='o'||ch=='u')

    vow++;

    else if(ch>'A'&&ch'a'&&ch='0'&&ch

  • 7/28/2019 Programs for C language Practical

    3/15

    Program 3-To print the inputted number of 2-3 digits in its word equivalent.

    #include

    #includevoid main()

    {

    long int num;

    int i,j,a,c[10],d[10],f=0;

    clrscr();

    printf("Enter any 1-3 digit number= ");

    scanf("%ld",&num);

    printf("Word Equivalent= ");

    for(i=0;num!=0;num=num/10)

    {

    a=num%10;

    c[i]=a;

    f++;

    d[i]=f;

    i++;

    }

    for(i;i>=0;i--)

    {

    if(d[i]==3){

    switch(c[i])

    {

    case 1: printf("One Hundred "); break;

    case 2: printf("Two Hundred "); break;

    case 3: printf("Three Hundred "); break;

    case 4: printf("Four Hundred "); break;

    case 5: printf("Five Hundred "); break;

    case 6: printf("Six Hundred "); break;

    case 7: printf("Seven Hundred "); break;

    case 8: printf("Eight Hundred "); break;

    case 9: printf("Nine Hundred "); break;

    }

    }

    else if(d[i]==2)

    {

    switch(c[i])

    {

    case 0: break;

    case 2: printf("Twenty "); break;

  • 7/28/2019 Programs for C language Practical

    4/15

    case 3: printf("Thirty "); break;

    case 4: printf("Fourty "); break;

    case 5: printf("Fifty "); break;

    case 6: printf("Sixty "); break;

    case 7: printf("Seventy "); break;

    case 8: printf("Eighty "); break;

    case 9: printf("Ninety "); break;

    }

    }

    else if(d[i]==1)

    {

    switch(c[i])

    {

    case 1: printf("One "); break;

    case 2: printf("Two "); break;case 3: printf("Three "); break;

    case 4: printf("Four "); break;

    case 5: printf("Five "); break;

    case 6: printf("Six "); break;

    case 7: printf("Seven "); break;

    case 8: printf("Eight "); break;

    case 9: printf("Nine "); break;

    }

    }

    else if(c[1]==1)

    {

    switch(c[0])

    {

    case 0: printf("Ten "); break;

    case 1: printf("Eleven "); break;

    case 2: printf("Twelve "); break;

    case 3: printf("Thirteen "); break;

    case 4: printf("Fourteen "); break;

    case 5: printf("Fifteen "); break;

    case 6: printf("Sixteen "); break;

    case 7: printf("Seventeen "); break;

    case 8: printf("Eighteen "); break;

    case 9: printf("Nineteen "); break;

    }

    }

    }

    getch();

    }

  • 7/28/2019 Programs for C language Practical

    5/15

    OUTPUT:

  • 7/28/2019 Programs for C language Practical

    6/15

    Program 4- To check the inputted word for palindrome.

    #include

    #includevoid main()

    {

    clrscr();

    char strg[10],k[10];

    int i,f=0;

    printf("enter any word= ");

    scanf("%s",strg);

    for(i=0;strg[i]!='\0';i++)

    k[i]=strg[i];

    for(i;i>=0;i--)

    {

    if(strg[i]!=k[i])

    {

    printf("the word is not a palindrome\n");

    f++;

    break;

    }

    }

    if(f==0)printf("the word is palindrome\n");

    getch();

    }

    OUTPUT:

  • 7/28/2019 Programs for C language Practical

    7/15

    Program 5- To generate the following alphabetical pattern.

    A B C D E F G F E D C B A

    A B C D E F F E D C B A

    A B C D E E D C B A

    A B C D D C B A

    A B C C B A

    A B B A

    A A

    #include

    #include

    void main()

    {

    clrscr();

    int n,i,j,x=13,y=1;

    for(i=7;i>=1;i--)

    {n='A';

    for(j=i;j>=1;j--)

    {

    printf(" %c",n);

    n=n+1;

    }

    gotoxy(x,y);

    for(j=n-1;j>='A';j--)

    {

    printf(" %c",j);

    }

    x=x+2;

    y++;

    printf("\n");

    }

    getch();

    }

  • 7/28/2019 Programs for C language Practical

    8/15

    Output:

  • 7/28/2019 Programs for C language Practical

    9/15

    Program 6- To reverse the inputted string.

    #include

    #includevoid main()

    {

    clrscr();

    char str[100];

    register int i;

    printf("enter any string= ");

    scanf("%s",str);

    for(i=0;str[i]!='\0';i++)

    str[i];

    printf("the reverse string is= ");

    for(;i>=0;i--)

    printf("%c",str[i]);

    getch();

    }

    OUTPUT:

  • 7/28/2019 Programs for C language Practical

    10/15

    Program 7- To enter marks of 10 students and finding the division of each

    student with the help of structure.

    #include

    #include

    struct stu

    {

    int h,e,m,s,c;

    long int rn;

    float sum;

    float per;

    };

    stu s[10];void main()

    {

    clrscr();

    int i,n;

    s:

    printf("Enter the number of students= ");

    scanf("%d",&n);

    if(n>10)

    {

    printf("Too many records to enter. Try again\n");goto s;

    }

    printf("Enter the Roll Number & Marks of each student.\n");

    for(i=0;i=(50.0)&&s[i].per=40&&s[i].per

  • 7/28/2019 Programs for C language Practical

    11/15

    else if(s[i].per

  • 7/28/2019 Programs for C language Practical

    12/15

    Program 8- To print the number of vowels in a set of string.

    #include

    #include

    void main()

    {

    char str[25];

    int i,j,vow_cont=0,n,count;

    printf("Enter the number of Strings= ");

    scanf("%d",&n);

    for(i=1;i

  • 7/28/2019 Programs for C language Practical

    13/15

    Program 9- To sort the inputted names in ascending order.

    #include

    #include#include

    void main()

    {

    char name[20][20],temp[20];

    int num,i,j,result,index;

    clrscr();

    printf("Enter the number of names in the list(Max 20): ");

    scanf("%d",&num);

    printf("Enter the names:\n");

    for(i=0;i

  • 7/28/2019 Programs for C language Practical

    14/15

    Program 10- To check the inputted name in a list of names stored in string

    array.

    #include#include

    #include

    #define FOUND 1

    #define NOTFOUND 0

    void main()

    {

    char masterlist*6+*10+=akshay,parag,raman,srinivas,gopal,rajesh-;

    int I,flag,a;

    char yourname[10];

    printf(Enter Your Name:);

    scanf(%s,yourname);

    flag=NOTFOUND;

    for(i=0;i

  • 7/28/2019 Programs for C language Practical

    15/15