ge6161 (1)

Upload: shrishalini-kumar

Post on 09-Feb-2018

223 views

Category:

Documents


0 download

TRANSCRIPT

  • 7/22/2019 GE6161 (1)

    1/75

    1. Write a C program to find the sum of digits of a number.

    #include

    #include

    void main(){

    int n,r,sum=0;

    clrscr();

    printf("Enter the number:");

    scanf("%d",&n);while(n!=0)

    {

    r=n%10;

    sum=sum +r;

    n=n/10;}

    printf ("\n The Sum of digits is %d", sum);

    getch();

    }

    2. Write a C program to reverse the digits of a number.

    #include

    #includevoid main()

    {

    int n,r,sum=0;

    clrscr();

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

    scanf("%d",&n);

    while(n!=0){

    r=n%10;n=n/10;

    sum=sum*10+r;

    }printf("\nThe reverse is %d",sum);

    getch();

    }

    3. Write a C program to find the largest digit of a number.

    #include#include

  • 7/22/2019 GE6161 (1)

    2/75

    void main()

    {

    int n,r,large=-1;

    clrscr();

    printf("Enter the number:\n");scanf("%d",&n);while(n!=0)

    {

    r=n%10;

    if(r>large)

    {large=r;

    }

    n=n/10;

    }

    printf("\nThe Largest digit is %d",large);

    getch();

    }

    4. Write a C program to check whether the number and its reverse are

    same. (Palindrome number)

    #include#include

    void main(){

    int n,r,a,sum=0;

    clrscr();

    printf("Enter the number:\n");scanf("%d",&n);

    a=n;

    while(n!=0)

    {

    r=n%10;n=n/10;

    sum=sum*10+r;

    }

    printf("\nThe given number is %d",a);

    printf("\nThe reverse is %d",sum);

    if(a==sum)

    {

    printf("\nThe entered number and reverse are same\n");

    }else

  • 7/22/2019 GE6161 (1)

    3/75

    {

    printf("\nThe entered number and reverse are not same\n");

    }

    getch();

    }

    5. Write a C program to check whether the given number is Armstrong

    or not.

    #include

    #includevoid main()

    {

    int n,a,r,sum=0;

    clrscr();

    printf("Enter the number.");

    scanf("%d",&n);a=n;

    while(a>0)

    {

    r=a%10;

    sum+=r*r*r;a=a/10;

    }if(sum==n)

    {

    printf("\nThe number %d is armstrong",n);

    }else

    {

    printf("\nThe number %d is not armstrong",n);

    }

    getch();}

    6. Write a C program to find the sum of odd-positioned digits and even

    positioned digits of a number separately.

    #include#include

    void main()

    { int n,r,count=0,odd=0,even=0;

  • 7/22/2019 GE6161 (1)

    4/75

    clrscr();

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

    scanf("%d",&n);

    while(n!=0)

    {r=n%10;count=count+1;

    if(count%2==0)

    {

    even=even+r;

    }else

    {

    odd=odd+r;

    }

    n=n/10;

    }

    printf("\nThe sum of odd positioned digits is %d",odd);

    printf("\nThe sum of even positioned digits is %d",even);

    getch();

    }

    7. Write a C program to find the second highest number from a set of

    numbers.

    #include

    #include

    void main(){

    int list[20],n,i,firstlarge,seclarge,num;

    clrscr();

    printf("\nEnter the size of the list\n");

    scanf("%d",&n);printf("\nEnter the elements one by one\n");

    scanf("%d",&num);

    firstlarge=num;

    seclarge=-9999;

    for(i=1;i

  • 7/22/2019 GE6161 (1)

    5/75

    firstlarge=num;

    }

    else

    {

    if(seclarge

  • 7/22/2019 GE6161 (1)

    6/75

    printf("\nThe numbers between 1 and 100 which are divisible by 2 and not

    divisible by 3 and 5 are ");

    for(i=1;i

  • 7/22/2019 GE6161 (1)

    7/75

    #include

    #include

    void main()

    {

    int n,r,digit,count=0;clrscr();

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

    scanf("%d",&n);

    printf("Enter the digit u want to count:\n");

    scanf("%d",&digit);

    while(n!=0){

    r=n%10;

    if(r==digit)

    {

    count=count+1;

    }

    n=n/10;

    }

    printf("\n%d times the digit is present in the given number",count);

    getch();

    }

    12. Write a C program to interchange the elements of an array with the

    elements of another array without using the third array.

    #include

    #includevoid main()

    {

    int a[20],b[20],i,n;

    clrscr();

    printf("Enter the number of elements(Max 20)");scanf("%d",&n);

    printf("\nEnter the elements of first array one by one");

    for(i=0;i

  • 7/22/2019 GE6161 (1)

    8/75

    }

    printf("\nBefore Swapping\n");

    printf("\nElements of Array 1: ");

    for(i=0;i

  • 7/22/2019 GE6161 (1)

    9/75

    printf("\nEnter the line of text");

    gets(text);

    n=strlen(text);

    for(i=0;i

  • 7/22/2019 GE6161 (1)

    10/75

    do

    {

    printf("\nEnter the order of 2nd matrix \n");

    scanf("%d%d",&m2,&n2);

    }while(n1!=m2);printf("\nEnter the elements of 2nd matrix\n");for(i=0;i

  • 7/22/2019 GE6161 (1)

    11/75

    {

    for(j=0;j

  • 7/22/2019 GE6161 (1)

    12/75

    printf("\n");

    }

    printf("\nThe elements of 2nd matrix\n");

    for(i=0;i

  • 7/22/2019 GE6161 (1)

    13/75

    getch();

    }

    16. Write a C program to get a matrix of order 3X3 and display a matrix oforder 4X4 with the fourth row and column as the sum of rows and columns

    respectively.

    #include

    #include

    void main()

    {

    int a[4][4],i,j;

    clrscr();

    printf("\nEnter the elements of input matrix\n");

    for(i=0;i

  • 7/22/2019 GE6161 (1)

    14/75

    {

    printf("%d\t",a[i][j]);

    }

    printf("\n");

    }getch();

    }

    17. Write a C program to arrange the set of numbers in descending order.

    #include

    #include

    void main()

    {

    int list[20],n,i,j,temp;clrscr();

    printf("\nEnter the number of elements (max 20)\n");

    scanf("%d",&n);

    printf("\nEnter the elements\n");

    for(i=0;i

  • 7/22/2019 GE6161 (1)

    15/75

    18. Write a function to find the product of two values without using *

    operator.

    #include

    #includevoid main(){

    int a,b,i,product=0;

    clrscr();

    printf("Enter the 1st number: ");

    scanf("%d",&a);printf("Enter the 2nd number: ");

    scanf("%d",&b);

    for(i=1;i

  • 7/22/2019 GE6161 (1)

    16/75

    20. Write a C program to arrange the digits of a number in ascending

    order.

    #include

    #includevoid bubblesort(int list[],int no);void main()

    {

    int n,r,a[10],i=0,j;

    clrscr();

    printf("\nEnter the number:");scanf("%d",&n);

    while(n!=0)

    {

    r=n%10;

    a[i]=r;

    n=n/10;i++;

    }

    bubblesort(a,i);

    printf("\nAfter sorting the digits the number is: ");

    for(j=0;j

  • 7/22/2019 GE6161 (1)

    17/75

    b) Check whether the given year is leap year or not.

    #include

    #include

    #includevoid main(){

    int a,b,c,year,ch;

    clrscr();

    do

    {printf("\nMenu");

    printf("\n1.Biggest of 3 Numbers\n2.Leap year or Not\n3.exit");

    printf("\nEnter ur choice");

    scanf("%d",&ch);

    switch(ch)

    {

    case 1:

    printf("\nEnter 3 nos\n");

    scanf("%d%d%d",&a,&b,&c);

    if(a>b&&a>c)

    {

    printf("\n %d is biggest",a);

    }else if(b>a&&b>c)

    {

    printf("\n %d is biggest",b);

    }else

    {

    printf("\n %d is biggest",c);

    }

    break;case 2:

    printf("\nEnter the year\t");

    scanf("%d",&year);

    if(((year%4==0)&&(year%100!=0))||(year%400==0))

    {

    printf("%d year is a leap year",year);

    }else

    {printf("%d year is not a leap year",year);

  • 7/22/2019 GE6161 (1)

    18/75

    }

    break;

    case 3:

    exit(0);

    default:printf("\nInvalid Input");

    }

    }while(ch!=3);

    getch();

    }

    22. Write a C program to (i) find whether the given number is even or odd.

    (ii) Find the square root of a number.

    #include

    #include

    #include //for exit()

    #include //for sqrt()

    void main()

    {

    int n,ch;

    clrscr();

    do

    {printf("\nMenu");

    printf("\n1.Odd or Even\n2.Square Root\n3.exit");

    printf("\nEnter ur choice");

    scanf("%d",&ch);switch(ch)

    {

    case 1:

    printf("\nEnter a number\n");

    scanf("%d",&n);if(n%2==0)

    {

    printf("\nThe number %d is even",n);

    }

    else

    {

    printf("\nThe number %d is odd",n);}

    break;case 2:

  • 7/22/2019 GE6161 (1)

    19/75

    printf("\nEnter the number\t");

    scanf("%d",&n);

    printf("\nthe square root of %d is %f",n,sqrt(n));

    break;

    case 3:exit(0);

    default:

    printf("\nInvalid Input");

    }

    }while(ch!=3);

    getch();}

    23. Write a C program to (i) check whether the given number is Armstrong

    or not. (ii) to reverse the digits of a given number.

    #include

    #include

    void main()

    {

    int a,n,r,sum=0,rev=0;

    clrscr();

    printf("Enter the number.");scanf("%d",&n);

    a=n;

    while(a!=0)

    {r=a%10;

    sum=sum+r*r*r;

    rev=rev*10+r;

    a=a/10;

    }if(sum==n)

    {

    printf("\nThe number %d is armstrong",n);

    }

    else

    {

    printf("\nThe number %d is not armstrong",n);}

    printf("\nThe reverse of %d is %d",n,rev);getch();

  • 7/22/2019 GE6161 (1)

    20/75

    }

    24. Write a C program to check the given name is palindrome or not

    without using string function.

    #include#include

    void main()

    {

    int len,i,j,count=0;

    char str[15];clrscr();

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

    scanf("%s",str);

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

    {

    count=count+1;

    }

    len=count;

    for(i=0,j=len-1;i

  • 7/22/2019 GE6161 (1)

    21/75

    scanf("%d",&num1);

    printf("\nEnter the Second number : ");

    scanf("%d",&num2);

    printf("\nBefore Swapping\n");

    printf("\nFirst number : %d",num1);printf("\nSecond number : %d\n",num2);swap() ;

    getch();

    }

    void swap()

    {num1=num1+num2;

    num2=num1-num2;

    num1=num1-num2;

    printf("\nAfter Swapping\n");

    printf("\nFirst number : %d",num1);

    printf("\nSecond number : %d\n",num2);

    }

    26. Write a C program to find the factorial of given number using recursive

    function.

    #include

    #includeint fact(int);

    void main()

    {

    int num,f;clrscr();

    printf("\nEnter a number: ");

    scanf("%d",&num);

    f=fact(num);

    printf("\nFactorial of %d is: %d",num,f);getch();

    }

    int fact(int n)

    {

    if(n==1)

    return 1;

    else

    return(n*fact(n-1));

    }

  • 7/22/2019 GE6161 (1)

    22/75

    27. Write a C program to sort the given number in ascending order using

    arrays.

    #include

    #includevoid main(){

    int list[20],n,i,j,temp;

    clrscr();

    printf("\nEnter the number of elements (max 20)\n");

    scanf("%d",&n);printf("\nEnter the elements\n");

    for(i=0;i

  • 7/22/2019 GE6161 (1)

    23/75

    printf("\nEnter the order of matrix\n");

    scanf("%d%d",&m,&n);

    printf("\nEnter the elements one by one\n");

    for(i=0;i

  • 7/22/2019 GE6161 (1)

    24/75

    #include

    void main()

    {

    int a[10],n,i,oddsum=0,evensum=0;

    clrscr();printf("\nENTER THE NUMBER OF ELEMENTS:\t");scanf("%d",&n);

    printf("\nENTER THE ELEMENTS ONE BY ONE\n");

    for(i=0;i

  • 7/22/2019 GE6161 (1)

    25/75

    };

    void main()

    {

    struct employee payroll;

    int grosspay,netpay;clrscr();

    printf("\nEnter the employee details");

    printf("\nEmployee Number:\t");

    scanf("%d",&payroll.empno);

    printf("\nEmployee Name:\t");

    scanf("%s",payroll.name);printf("\nEnter Basic pay:\t");

    scanf("%d",&payroll.basicpay);

    printf("\nEnter DA:\t");

    scanf("%d",&payroll.da);

    printf("\nEnter HRA:\t");

    scanf("%d",&payroll.hra);

    printf("\nEnter TA:\t");

    scanf("%d",&payroll.ta);

    printf("\nEnter PF:\t");

    scanf("%d",&payroll.pf);

    printf("\nEnter CCA:\t");

    scanf("%d",&payroll.cca);

    grosspay=payroll.basicpay+payroll.da+payroll.ta+payroll.hra+payroll.cca;netpay=grosspay-payroll.pf;

    printf("\nEmployee Payroll\n");

    printf("\nEmployee Number: %d",payroll.empno);

    printf("\nEmployee Name: %s",payroll.name);printf("\nBasic Pay: %d",payroll.basicpay);

    printf("\nHRA: %d",payroll.hra);

    printf("\nDA: %d",payroll.da);

    printf("\nTA: %d",payroll.ta);

    printf("\nCCA: %d",payroll.cca);printf("\nPF: %d",payroll.pf);

    printf("\nNet pay: %d",netpay);

    getch();

    }

    31. Write a C program to generate student mark sheets with subject details

    and the grades using Structure.

    #include#include

  • 7/22/2019 GE6161 (1)

    26/75

    #define max 10

    int gradepoint(char x);

    struct student

    {

    char name[max];int reg;int c[max];

    char g[max];

    char s[max][max];

    float gpa;

    }stud[max];void main()

    {

    int n,ns,i,j,sum=0,credit_total=0,x;

    clrscr();

    printf("\nEnter the no.of students\t");

    scanf("%d",&n);

    for(i=0;i

  • 7/22/2019 GE6161 (1)

    27/75

    stud[i].gpa=(float)sum/credit_total;

    }

    for(i=0;i

  • 7/22/2019 GE6161 (1)

    28/75

    break;

    case 'U':

    case 'u':

    gp=0;

    break;}return gp;

    }

    32. Write a function to arrange the numbers in decreasing order. Provide

    Input and Outputs only in the main method.

    #include

    #include

    void bubblesort(int a[], int no);

    void main()

    {

    int list[20],n,i;

    clrscr();

    printf("\nEnter the number of elements (max 20)\n");

    scanf("%d",&n);

    printf("\nEnter the elements\n");

    for(i=0;i

  • 7/22/2019 GE6161 (1)

    29/75

    a[j]=a[j+1];

    a[j+1]=temp;

    }

    }

    }}

    33. Write a C program to generate the first 50 Fibonacci numbers.

    #include

    #includevoid main()

    {

    unsigned long int n,count,a=0,b=1,c;

    clrscr();

    printf("\nFirst 50 numbers in the fibonacci series are\n");

    printf("%lu %lu ",a,b);

    for(count=2;count

  • 7/22/2019 GE6161 (1)

    30/75

    printf("%d ",factorial(i)/(factorial(c)*factorial(i-c)));

    printf("\n");

    }

    getch();

    }int factorial(int n)

    {

    int i,fact=1;

    for(i=1;i

  • 7/22/2019 GE6161 (1)

    31/75

    36. Write a program to find the area and circumference of the circle. Test

    your program and report the results obtained.

    #include

    #include

    float area(float r);

    float circumference(float r);

    void main()

    {

    float r;

    clrscr();

    printf("\nEnter the radius of a circle");

    scanf("%f",&r);

    printf("\nArea=%f",area(r));printf("\nCircumference=%f",circumference(r));

    getch();

    }

    float area(float r)

    {

    return 3.14*r*r;}

    float circumference(float r)

    {return 2*3.14*r;

    }

    37. Write a program to find sum of Digits, Reverse and the given Number

    is Palindrome or not. Test your program and report the results obtained.

    #include

    #include

    void main(){

    int a,n,r,sum=0,rev=0,arm=0;

    clrscr();

    printf("Enter the number.");

    scanf("%d",&n);

    a=n;while(a!=0)

    {

    r=a%10;arm=arm+r*r*r;

  • 7/22/2019 GE6161 (1)

    32/75

    rev=rev*10+r;

    sum=sum+r;

    a=a/10;

    }

    if(arm==n){

    printf("\nThe number %d is armstrong",n);

    }

    else

    {

    printf("\nThe number %d is not armstrong",n);}

    printf("\nThe reverse of %d is %d",n,rev);

    printf("\nthe sum of digits of %d is %d",n,sum);

    getch();

    }

    38. Write a program to find the string length and concatenation of string.

    Test your program and report the results obtained.

    #include#include

    #include

    void main(){

    char str1[]="Saveetha ",str2[]="College";int b;

    clrscr();

    printf("\nString 1: ");

    puts(str1);

    printf("\nString 2: ");puts(str2);

    strcat(str1,str2);printf("\nConcatenated String: ");

    puts(str1);

    b=strlen(str1);printf("\nThe length of the new string is %d",b);

    getch();}

    39. Write a program to assigning values to the structures variables and

    retrieving values. Test your program and report the results obtained.

    #include

  • 7/22/2019 GE6161 (1)

    33/75

    #include

    struct student

    {

    char name[20];

    int rollno,m1,m2,m3,m4,m5;float avg;

    };

    void main()

    {

    struct student stud;

    clrscr();printf("\nEnter student name: ");

    scanf("%s",stud.name);

    printf("\nEnter roll number: ");

    scanf("%d",&stud.rollno);

    printf("\nEnter the marks\n");

    scanf("%d%d%d%d%d",&stud.m1,&stud.m2,&stud.m3,&stud.m4,&stud.m5);

    stud.avg=(stud.m1+stud.m2+stud.m3+stud.m4+stud.m5)/5.0;

    printf("\nStudent name is %s\n",stud.name);

    printf("\nStudent rollno %d\n",stud.rollno);

    printf("\nMarks1 %d\n",stud.m1);

    printf("\nMarks2 %d\n",stud.m2);

    printf("\nMarks3 %d\n",stud.m3);printf("\nMarks4 %d\n",stud.m4);

    printf("\nMarks5 %d\n",stud.m5);

    printf("\nAverage %0.2f\n",stud.avg);

    getch();}

    40. Write a C program to check the given number is prime or not. Test

    your program and report the results obtained.

    #include

    #include

    void main(){

    int n, i, flag=0;clrscr();

    printf("\nEnter a positive integer: ");

    scanf("%d",&n);

    for(i=2;i

  • 7/22/2019 GE6161 (1)

    34/75

    printf("i=%d ",i);

    if(n%i==0)

    {

    flag=1;

    break;}

    }

    if (flag==0)

    printf("%d is a prime number.",n);

    else printf("%d is not a prime number.",n);

    getch();}

    41.Write a function program to search a given element from a set of values.

    #include

    #include

    void main()

    {

    int list[20],n,val,i,pos=-1;

    clrscr();

    printf("\t\t\tLINEAR SEARCH\n");

    printf("\nEnter the size of the list\n");scanf("%d",&n);

    printf("\nEnter the elements one by one\n");

    for(i=0;i

  • 7/22/2019 GE6161 (1)

    35/75

    printf("\nSearch Failed\n");

    getch();

    }

    42. Write a C program to simulate the calculator using Function. Test yourprogram and report the results obtained.

    #include#include

    #include

    int add(int,int);

    int sub(int,int);

    int mul(int,int);int divide(int,int);void main()

    {

    int a,b,ch;

    clrscr();

    printf("\nMenu Driven Calculator\n");do

    {

    printf("\nMenu");

    printf("\n1.Add\n2.Substract\n3.Multiply\n4.Divide\n5.Exit");

    printf("\nEnter your choice");

    scanf("%d",&ch);switch(ch)

    {

    case 1:

    printf("\nEnter two numbers");

    scanf("%d%d",&a,&b);printf("\nThe sum is %d",add(a,b));

    break;case 2:

    printf("\nEnter two numbers");

    scanf("%d%d",&a,&b);

    printf("\nThe difference is %d",sub(a,b));

    break;

    case 3:

    printf("\nEnter two numbers");

    scanf("%d%d",&a,&b);

    printf("\nThe product is %d",mul(a,b));break;

  • 7/22/2019 GE6161 (1)

    36/75

    case 4:

    printf("\nEnter two numbers");

    scanf("%d%d",&a,&b);

    printf("\nThe Quotient is %d",divide(a,b));

    break;case 5:

    exit(0);

    default:

    printf("\nInvalid Input!!!Please Try Again!!!");

    }

    }while(ch!=5);getch();

    }

    int add(int x,int y)

    {

    return x+y;

    }

    int sub(int x,int y)

    {

    return x-y;

    }

    int mul(int x,int y)

    {

    return x*y;}

    int divide(int x,int y)

    {

    return x/y;}

    43. Write a C program to find the roots of given quadratic equation.

    #include

    #include#includevoid main()

    {

    int a,b,c,d;

    float r1,r2;

    printf("\nEnter the coefficients a, b and c\t");

    scanf("%d%d%d",&a,&b,&c);d=b*b-4*a*c;

    if(d>0){

  • 7/22/2019 GE6161 (1)

    37/75

    r1=(-b+sqrt(d))/(2*a);

    r2=(-b-sqrt(d))/(2*a);

    printf("Roots are real and unequal\n");

    printf("\nRoots are: %f%f",r1,r2);

    }else if(d==0){

    r1=-b/(2*a);

    printf("\nRoots are real and equal\n");

    printf("\nRoots are %f %f",r1,r1);

    }else

    {

    printf("\nNo real roots; roots are imaginary");

    }

    getch();

    }

    44. Write a C program to create a structure called employee with name,

    employee id, age, designation and salary as data members. Accept five

    employee details and display it.

    #include

    #include

    struct employee{

    char name[20];

    int empid;

    int age;char designation[20];

    int salary;

    };

    void main()

    {struct employee emp[5];

    int i;

    printf("\nEnter employee details");

    for(i=0;i

  • 7/22/2019 GE6161 (1)

    38/75

    printf("\nEnter employee designation: ");

    scanf("%s",emp[i].designation);

    printf("\nEnter employee age: ");

    scanf("%d",&emp[i].age);

    printf("\nEnter employee salary: ");scanf("%d",&emp[i].salary);

    }

    printf("\n\t\t\tEmployee Details\n\n");

    printf("\n\t\tName\tID\tDesignation\tAge\tSalary\n");

    for(i=0;i

  • 7/22/2019 GE6161 (1)

    39/75

    46. Write a C program to accept a string in any case and convert it to

    another case. Test your program with at least three data and provide

    output.

    #include#include

    #include

    void main()

    {

    char str[20];

    clrscr();

    printf("\nEnter a string in lowercase: ");

    scanf("%s",str);

    strupr(str);printf("\nThe sring in uppercase is %s",str);

    printf("\nEnter a string in uppercase: ");

    scanf("%s",str);

    strlwr(str);

    printf("\nThe sring in lowercase is %s",str);

    getch();

    }

    47. Write a C program to accept any single digit number and print it in

    words. Test your program and report the results obtained.

    #include

    #include

    void main()

    {

    int n;

    clrscr();printf("\nEnter a single digit number");

    scanf("%d",&n);

    switch(n)

    {

    case 0:

    printf("\nZero");

    break;

    case 1:

    printf("\nOne");break;

  • 7/22/2019 GE6161 (1)

    40/75

    case 2:

    printf("\nTwo");

    break;

    case 3:

    printf("\nThree");break;

    case 4:

    printf("\nFour");

    break;

    case 5:

    printf("\nFive");break;

    case 6:

    printf("\nSix");

    break;

    case 7:

    printf("\nSeven");

    break;

    case 8:

    printf("\nEight");

    break;

    case 9:

    printf("\nNine");

    break;default:

    printf("\nEnter correct no and try again");

    }getch();

    }

    48. Write a C program to accept a number and print mathematical table of

    the given number. Test your program with at least three data and provide

    output.

    #include

    #include

    void main()

    {

    int n,i;clrscr();

    printf("\nEnter the number");scanf("%d",&n);

  • 7/22/2019 GE6161 (1)

    41/75

    printf("The mathematical Table of given number is\n");

    for(i=1;i

  • 7/22/2019 GE6161 (1)

    42/75

    if(sum>=100&&sum

  • 7/22/2019 GE6161 (1)

    43/75

    #include

    #include

    void main()

    {int num;char ch;

    clrscr();

    printf("Printing ASCII values Table...\n\n");

    num = 1;

    printf("\nValue:%d = ASCII Character:%c", num, num);num++;

    printf("\nDo u want to continue(y/n)");

    ch=getche();

    while(ch=='Y'||ch=='y')

    {

    printf("\nValue:%d = ASCII Character:%c", num, num);

    num++;

    printf("\nDo u want to continue(y/n)");

    ch=getche();

    }

    getch();

    }

    53.Write a C program to (i) Calculate the area of a circle (ii) Convert the

    C0to F

    0.

    #include

    #includevoid main ()

    {

    float c, f, r;

    char ch;clrscr();

    printf("Instructions:\n");

    printf("Enter 'A' to find the area of circle:\n");

    printf("Enter 'C' to convert Celsius to Farenheit:\n");

    printf("\nEnter a character: ");

    scanf("%c",&ch);

    if (ch=='a' || ch=='a'){

    printf("Enter the radius: ");scanf("%f",&r);

  • 7/22/2019 GE6161 (1)

    44/75

    printf("\nThe area is: %f",3.14*r*r);

    }

    if (ch=='c' || ch=='C')

    {

    printf ("Enter the value of Temperature in Celcius: ");scanf ("%f", &c);f = (1.8 * c) + 32;

    printf ("The value of Temperature in Fahreinheit is: %f", f);

    }

    getch();

    }

    54. Write a C program to get todays date as input and print the

    tomorrows date.

    #include

    #include

    void main()

    {

    int dd,mm,yyyy,dd1,mm1,yyyy1;

    int nd[]={31,28,31,30,31,30,31,31,30,31,30,31};

    clrscr();

    printf("\nTodays date in the format(DD MM YYYY)\n");

    scanf("%d%d%d",&dd,&mm,&yyyy);

    if(dd12)

    {

    mm1=mm1-12;

    yyyy1=yyyy+1;

    }else

    {yyyy1=yyyy;

  • 7/22/2019 GE6161 (1)

    45/75

  • 7/22/2019 GE6161 (1)

    46/75

    Test your program and report the results obtained.

    #include

    #includevoid main(){

    char ans[10],correctans[]="meter";

    int attempt=0;

    do

    {printf("\nWhat is the unit of distance ?");

    scanf("%s",ans);

    attempt=attempt+1;

    }while(strcmp(ans,correctans)!=0&&attempt!=3);

    if(attempt==3)

    printf("\nThe correct answer is \"Meter\"");

    getch();

    }

    57. Write a C Program to create a structure called Time with hour, minute

    and second as data members. Find the difference between two time values

    with valid time.

    #include

    #include

    struct time

    {int hrs;

    int mins;

    int secs;

    };

    void main(){

    struct time t1,t2,t3;

    clrscr();

    printf("\nEnter time 1 in 24 hrs format(HH MM SS): ");

    scanf("%d%d%d",&t1.hrs,&t1.mins,&t1.secs);

    printf("\nEnter time 2 in 24 hrs format(HH MM SS): ");

    scanf("%d%d%d",&t2.hrs,&t2.mins,&t2.secs);t3.secs=t2.secs-t1.secs;

    if(t3.secs

  • 7/22/2019 GE6161 (1)

    47/75

    t3.secs=t3.secs+60;

    t2.mins=t2.mins-1;

    }

    t3.mins=t2.mins-t1.mins;

    if(t3.mins

  • 7/22/2019 GE6161 (1)

    48/75

    {

    for(j=0;j

  • 7/22/2019 GE6161 (1)

    49/75

    }

    59.Write a C program to arrange the given names in the alphabetical order

    using arrays. Test your program and report the results obtained.

    #include#include

    #include

    void main()

    {

    char name[10][20],temp[20];int i,j,n;

    clrscr();

    printf("Enter the total number of names\n");

    scanf("%d",&n);

    printf("\nEnter the names one by one.....\n");

    for(i=0;i

  • 7/22/2019 GE6161 (1)

    50/75

    #include

    #include

    void main()

    {

    int arr[10][10], arrT[10][10];int i,j,n;clrscr();

    printf("\nA symmetric matrix is a square matrix that is equal to its

    transpose.\n");

    printf("\nEnter the no.of rows of square matrix\n");

    scanf("%d",&n);for(i=0;i

  • 7/22/2019 GE6161 (1)

    51/75

    }

    for(i=0;i

  • 7/22/2019 GE6161 (1)

    52/75

    case 'E':

    case 'I':

    case 'O':

    case 'U':

    v++;break;

    case ' ':

    s++;

    break;

    default:

    c++;break;

    }

    if((str[i]==' ')&&(str[i-1] !=' '))

    w++;

    }

    printf("\n\n Entered string is %s",str);

    printf("\n\n No. of Vowels:%d",v);

    printf("\n\n No. of Consonants:%d",c);

    printf("\n\n No. of Spaces:%d",s);

    printf("\n\n No. of Words:%d",w);

    getch();

    }

    62.Write a C program to create a structure called date with day, month

    and year as data member and find the difference between two dates.

    #include

    #include

    struct date

    {

    int dd;int mm;

    int yyyy;

    };

    void main()

    {

    struct date dob,c_date,diff;

    printf("\nEnter your Date of Birth(DD MM YYYY)\n");scanf("%d%d%d",&dob.dd,&dob.mm,&dob.yyyy);

    printf("\nEnter Current Date (DD MM YYYY)");scanf("%d%d%d",&c_date.dd,&c_date.mm,&c_date.yyyy);

  • 7/22/2019 GE6161 (1)

    53/75

    if(c_date.dd>=dob.dd)

    diff.dd = c_date.dd-dob.dd;

    else

    {

    c_date.dd+=30;c_date.mm-=1;diff.dd = c_date.dd-dob.dd;

    }

    if(c_date.mm>=dob.mm)

    diff.mm = c_date.mm-dob.mm;

    else{

    c_date.mm+=12;

    c_date.yyyy-=1;

    diff.mm = c_date.dd-dob.mm;

    }

    diff.yyyy = c_date.yyyy-dob.yyyy;

    printf("\nYour age is: %d years %d months and %d

    days\n",diff.yyyy,diff.mm,diff.dd);

    getch();

    }

    63. Write a C program to print the abbreviation for a given sentence.

    (American Standard Code for Information Interchange as ASCII)

    #include

    #include

    void main(){

    char str[100],len,i;

    clrscr();

    printf("Enter any string\n(Format: American Standard Code for Information

    Interchange)\n");gets(str);

    len=strlen(str);

    for(i=0;i

  • 7/22/2019 GE6161 (1)

    54/75

    64. Write a C program to print all combinations of a 4-digit number.

    #include

    #include

    void main(){

    int a,b,c,d;

    printf("The Combinations of a 4 digit number 1234 \n");

    clrscr();

    for(a=1; a

  • 7/22/2019 GE6161 (1)

    55/75

    }

    }

    getch();

    }

    66. Write a C program to find the largest element in a row and largest

    element in a column of a given matrix.

    #include

    #includevoid main()

    {

    int a[5][5],rbig[5],cbig[5];

    int i,j,m,n;

    clrscr();

    printf("\nEnter the order of Input matrix\n");scanf("%d%d",&m,&n);

    printf("\nEnter the elements of Input matrix one by one\n");

    for(i=0;i

  • 7/22/2019 GE6161 (1)

    56/75

    cbig[i]=a[j][i];

    }

    printf("\n");

    }

    printf("\tNo\tRowMax\tColMax\n");for(i=0;i

  • 7/22/2019 GE6161 (1)

    57/75

    }

    68.Write a C program to find the sum of the following series (cosine series)

    1-x2/2!+x

    4/4!-x

    6\6!+

    #include#include

    #include

    float factorial(int n);

    void main()

    {int i,n,j;

    float sum=1.0,x,nr,dr;

    clrscr();

    printf("\nEnter the Value of x in radians: \n");

    scanf("%f",&x);

    printf("\nEnter the power of end term: \n");

    scanf("%d",&n);

    j=-1;

    for(i=2;i

  • 7/22/2019 GE6161 (1)

    58/75

    float factorial(int n);

    void main()

    {

    int i,n,j;

    float sum=0.0,x,nr,dr;clrscr();

    printf("\nEnter the Value of x in radians: \n");

    scanf("%f",&x);

    printf("\nEnter the power of end term: \n");

    scanf("%d",&n);

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

  • 7/22/2019 GE6161 (1)

    59/75

    scanf("%s",b);

    while(a[i]!='\0'||b[i]!='\0')

    {

    dif=(a[i]-b[i]);

    if(dif!=0)break;

    i++;

    }

    if(dif>0)

    {

    printf("\n%s comes after %s\n",a,b);}

    else if(dif

  • 7/22/2019 GE6161 (1)

    60/75

    i = j = k = 0;

    /* get the input string from the user */

    printf("\nEnter your input string:");

    gets(str);

    /* get the word that needs to be removed from i/p string */

    printf("\nEnter the word you want to remove:");

    gets(text);

    /* copying each and every word from the string */

    while (str[i] !='\0')

    {

    if (str[i] ==' ')

    {

    words[j][k] ='\0';

    k = 0;

    j++;

    }

    else

    {

    words[j][k++] = str[i];

    }i++;

    }

    words[j][k] = '\0';

    /* print all words except the word that needs to be removed */

    for (i = 0; i

  • 7/22/2019 GE6161 (1)

    61/75

    #include

    #include

    int factorial(int);

    void main(){

    int i,j,c,n;

    clrscr();

    printf("\nEnter the number of rows you wish to print in numeric

    pyramid\n");

    scanf("%d",&n);for ( i = 0 ; i < n ; i++ )

    {

    for (j= 0; j

  • 7/22/2019 GE6161 (1)

    62/75

    {

    scanf("%d",&a[i][j]);

    }

    }

    printf("\nThe elements of input matrix\n");for(i=0;i

  • 7/22/2019 GE6161 (1)

    63/75

    int hex_binary(char hex[]);

    void main()

    {

    int binary[16][4]={

    {0},{0},{0},{0},{0},{0},{0},{0},{0},{0},{0},{0},{0},{0},{0},{0}};int i,j,a,r;char hex[16]={'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};

    clrscr();

    for(i=1;i

  • 7/22/2019 GE6161 (1)

    64/75

    #include

    #include

    void main()

    {

    int a[10][10],i,j,n;int flag=0,flag1=0;clrscr();

    printf("\nEnter the no.of rows of the Square Matrix\n");

    scanf("%d",&n);

    printf("\nEnter the elements of input square matrix 1 by 1\n");

    for(i=0;i

  • 7/22/2019 GE6161 (1)

    65/75

    for(j=i+1;j

  • 7/22/2019 GE6161 (1)

    66/75

    return(x*fact(x-1));

    }

    77.Write a C program to generate the following triangle.

    11 2 3

    1 2 3 4 5

    1 2 3 4 5 6 7

    #include

    #include

    void main()

    {

    int i,j,k,c,n,bs=0;clrscr();

    printf("\nEnter the number of rows you wish to print in the triangle\n");

    scanf("%d",&n);

    /*

    bs -> number of blank spaces.

    the following for loop is used to find the

    no.of blank spaces in the first line.

    */

    for(i=1;i

  • 7/22/2019 GE6161 (1)

    67/75

    }

    78.Write a C program to generate the following triangle.

    55 5

    5 5 5

    5 5 5 5

    #include

    #includevoid main()

    {

    int i,j,c,n,no;

    clrscr();

    printf("\nEnter the element u want to print\n");scanf("%d",&no);

    printf("\nEnter the number of rows you wish to print in the triangle\n");

    scanf("%d",&n);

    for ( i = 0 ; i < n ; i++ )

    {

    for (j= 0; j

  • 7/22/2019 GE6161 (1)

    68/75

    {

    struct library book[5];

    int n,i;

    char str[25];

    clrscr();printf("\nEnter the no.of Category\n");scanf("%d",&n);

    for(i=0;i

  • 7/22/2019 GE6161 (1)

    69/75

    }

    80.Write a C program to find the GCD and LCM by using Euclids

    Algorithm. Test your program and report the results obtained.

    #include

    #include

    int gcd(int a,int b);

    void main()

    {int num1,num2,lcm,gc;

    clrscr();

    printf("Enter two numbers\n");scanf("%d %d", &num1,&num2);

    if(num1>num2)

    {

    gc=gcd(num1,num2);}

    else

    {

    gc=gcd(num1,num2);

    }printf("\nGCD=%d",gc);

    lcm=num1*num2/gc;

    printf("\nLCM=%d",lcm);

    getch();

    }int gcd(int a,int b)

    {

    int t;

    while(b!=0)

    {t=b;

    b=a%b;

    a=t;

    }

    return a;

    }

    81.Write a C program to calculate and display total cost of 4 models of

    Pentium PC. Use the single dimensional array for PC codes their price andquantity available. Test your program and report the results obtained.

  • 7/22/2019 GE6161 (1)

    70/75

    #include

    #include

    void main()

    {

    int code[4], quantity[4];float price[4],totalcost=0;int i;

    clrscr();

    for(i=0;i

  • 7/22/2019 GE6161 (1)

    71/75

    float length;

    float breadth;

    float area;

    }rect;

    struct triangle{

    float base;

    float height;

    float area;

    }trian;

    void main(){

    int choice;

    clrscr();

    do

    {

    printf("\n1.Area of circle");

    printf("\n2.Area of rectangle");

    printf("\n3.Area of triangle");

    printf("\n4.Exit");

    printf("\nEnter your choice\n");

    scanf("%d",&choice);

    switch(choice)

    {case 1:

    printf("\nEnter the radius\n");

    scanf("%f",&circ.radius);

    circ.area=3.14*pow(circ.radius,2);printf("\nArea of circle is %f",circ.area);

    break;

    case 2:

    printf("\nEnter the length and breadth of the rectangle\n");

    scanf("%f%f",&rect.length,&rect.breadth);rect.area=rect.length*rect.breadth;

    printf("\nArea of rectangleis %f",rect.area);

    break;

    case 3:

    printf("\nEnter the base and height of right

    angled triangle\n");scanf("%f%f",&trian.base,&trian.height);

    trian.area=(trian.base*trian.height)/2;printf("\nArea of rectangleis %f",trian.area);

  • 7/22/2019 GE6161 (1)

    72/75

    break;

    case 4:

    exit(0);

    default:

    printf("\nInvalid input!Please try again!!!");}

    }while(choice!=4);

    getch();

    }

    83. Write a C program to sort the elements using Quick Sort.

    #include

    #include

    #define N 20

    void partition(int key,int list[],int lb,int ub);

    void quicksort(int list[],int lb,int ub);

    void main()

    {

    int list[N];

    int i,size,temp;

    clrscr();

    printf("\nEnter the size of the list(

  • 7/22/2019 GE6161 (1)

    73/75

    }

    void partition(int key,int list[],int lb,int ub)

    {

    int i,j,temp;

    i=lb;j=ub;while(i

  • 7/22/2019 GE6161 (1)

    74/75

    for(i=0;i

  • 7/22/2019 GE6161 (1)

    75/75

    }

    }

    while(ptr1