Posts

Showing posts from May, 2020

‘C’ program to check if a number is perfect

C File => /* Write a ‘C’ program to check if a number is perfect (number = sum of its factors) */ #include <stdio.h> int main()  {      int n, i,sum=0;      printf("\n Enter a positive integer: ");      scanf("%d",&n);      printf("\n Factors of %d are: ", n);      for (i = 1; i<n; ++i)      {         if (n % i == 0)         {               printf("%d\t", i);               sum=sum+i;          }      } //end for      if(sum==n)           printf("\n %d is perfect number",n);      else           printf("\n %d is Not a perfect number",n);      return 0; }

‘C’ program to check given year is leap year or not.

C File => /* Write a ‘C’ program to check whether the given year is leap year or not. */ #include<stdio.h> int main()  {       int year;       printf("Enter year: ");       scanf("%d",&year);         if(year % 4 == 0)      {           //Nested if else         if( year % 100 == 0)         {             if ( year % 400 == 0)                 printf("\n%d is a Leap Year", year);             else                 printf("\n%d is not a Leap Year", year);           }           else                printf("\n%d is a Leap Year", year );         }         else                printf("\n%d is not a Leap Year", year);           return 0; }

‘C’ program to check if character is alphabet, digit or special symbol.

C File => /* Write a ‘C’ program to accept a character and check if it is alphabet,  digit or special symbol. If it is an alphabet, check if it is uppercase or  lowercase. */ #include<stdio.h> #include<ctype.h> int main()  {       char c;         printf("\n Enter any character : ");       scanf("%c",&c);         if(isalpha(c))      {           if(islower(c))              printf("\n Lowercase alphabet");          else              printf("\n Uppercase alphabet");       }       else if(isdigit(c))             printf("\n You entered Digit");       else             printf("It is a special symbol");         return 0; }

‘C’ function to calculate x^y. Use this function to calculate the sum of first n terms of the series x + x^3/3 + x^5/5 + ...

C File => /* Write a ‘C’ function to calculate xy. Use this function to calculate the sum  of first n terms of the series x + x^3/3 + x^5/5 + ... */ #include<stdio.h> int main()  {       int n,x,i,sum=0;      // defining function to compute x^y      int cal_pow(int x, int y)     {         if (y == 0)             return 1;         else if (y%2 == 0)             return cal_pow(x, y/2)*cal_pow(x, y/2);         else            return x*cal_pow(x, y/2)*cal_pow(x, y/2);       }        printf("\n Enter value of x : ");      scanf("%d",&x);        printf("\n Enter value of n : ");      scanf("%d",&n);        for(i=1;i<=n;i=i+2)              sum=sum+(cal_pow(x,i)/i);      printf("\n Sum of series = %d",sum);          return 0; }

‘C’ program to accept real number x and integer n and calculate the sum of first n terms of the series x+ x/3!+ x/5!+ x/7!+…

C File => /* Write a ‘C’ program to accept real number x and integer n and calculate  the sum of first n terms of the series x+ x/3!+ x/5!+ x/7!+… */ #include<stdio.h> int main()  {       int x,n,i;       float sum=0;         printf("\n Enter value of x : ");       scanf("%d",&x);       printf("\n Enter value of n : ");       scanf("%d",&n);        printf("\n\n Sum of series x+x/3!+x/5!...\n");     // defining function to compute factorial       int fact(int n)      {           if(n==1)               return 1;          else               return (n*fact(n-1));       }        // computing sum of series       for(i=1;i<=n;i=i+3)           sum=sum+x/fact(i);         printf("\n %f",sum);         return 0; }

‘C’ program to calculate the GCD of two numbers.

C File => /* Write a ‘C’ program to calculate the GCD of two numbers. */ #include<stdio.h> int main()  {       int m, n;         printf("Enter two positive integers: ");       scanf("%d %d",&m,&n);         while(m!=n)       {            if(m > n)                 m = m - n;           else                 n = n - m;        }         printf("GCD = %d",m);         return 0; }

‘C’ program to display n lines of the pattern.

C File => /* Write a ‘C’ program to display n lines of the following pattern.   1   2 3   4 5 6 */ #include<stdio.h> int main()  {       int i,j,n=1;         for(i=1;i<4;i++)      {          for(j=1;j<=i;j++)          {              printf("%d\t",n);              n++;           }          printf("\n");      }      return 0; }

‘C’ function to check if a number is prime.

C File => /* Write a ‘C’ function to check if a number is prime. Use this function to  display all prime numbers between 100 and 500. */ #include<stdio.h> int main()  {        int i;     // function to check if number is prime        int isprime(int n)       {            int flag=1,i;            for(i=2;i<n-1;i++)            {                if(n%i==0)               {                   flag=0;                   break;                }            }           return flag;        }           printf("\n Prime numbers between 100 and 500 :\n");         for(i=100;i<500;i++)       {           if(isprime(i)==1)                printf("%d\t",i);       }         return 0; }

‘C’ program to display n terms of the Fibonacci series.

C File => /* Write a ‘C’ program to display n terms of the Fibonacci series. */ #include<stdio.h> int main()  {       int n,i,a=0,b=1,c;         printf("\n Enter value of n : ");       scanf("%d",&n);         if(n==1)          printf("\n %d",a);       else if(n==2)          printf("\n%d\t%d",a,b);       else if(n>2)       {           printf("\n%d\t%d\t",a,b);           for(i=3;i<=n;i++)           {               c=a+b;               printf("%d\t",c);               a=b;               b=c;           } //end for        }          return 0; }

‘C’ to calculate sum of digits of an integer.

C File => /* Write a function in ‘C’ to calculate sum of digits of an integer. Use this function in main */ #include<stdio.h> int main()  {       int num;      // defining function        void sum_digits(int n)       {            int r,sum=0;            int num=n;              while(n>0)            {                r=n%10;                sum=sum+r;                n=n/10;             }            printf("\n Sum of digits in %d is %d",num,sum);        }          printf("\n Enter number : ");        scanf("%d",&num);         //calling function         sum_digits(num);                return 0; }

‘C’ to reverse an integer.

C File => /* Write a function in ‘C’ to reverse an integer. Use this in main */ #include<stdio.h> int main()  { int num;     // function to compute reverse      void reverse_num(int n)      {           int r,sum=0;           printf("\n Reverse of %d is ",n);            while(n>0)           {                r=n%10;                printf("%d",r);                n=n/10;            }        }        printf("\n Enter number : ");        scanf("%d",&num);       //calling function        reverse_num(num);       return 0; }

‘C’ to calculate factorial of a number using recursion.

C File => /* Write a recursive function in ‘C’ to calculate factorial of a number. Use  this function in main. */ #include<stdio.h> int main()  {       int num;      // defining recursive function       int fact(int n)     {          if(n==1 || n==0)                  return 1;          else                  return(n*fact(n-1));      }       printf("\n Enter number : ");       scanf("%d",&num);       printf("\n Factorial of %d is %d",num,fact(num));      return 0; }

‘C’ program to calculate the sum of factors of a number.

C File => /* Write a ‘C’ program to calculate the sum of  factors of a number. */ #include <stdio.h> int main()  {         int n, i,fact[100],sum=0;           printf("\n Enter a positive integer: ");         scanf("%d",&n);         printf("\n Factors of %d are: ", n);         for (i = 1; i < n; ++i)         {              if (n % i == 0)              {                    printf("%d\t", i);                    sum=sum+i;              }          }         printf("\n Sum of factors : %d",sum);  return 0; }

‘C’ program to check if number is divisible by 3 or 5.

C File => /* Write a ‘C’ program to accept an integer and check if it is divisible by  3 and 5. */ #include<stdio.h> int main()  {        int num;          printf("\n Enter number : ");        scanf("%d",&num);          if(num%3==0 && num%5==0)              printf("\n %d is divisible by both 3 and 5",num);       else if(num%3==0)              printf("\n %d is divisible by only 3",num);       else if(num%5==0)              printf("\n %d is divisible by only 5",num);      else              printf("\n %d is not divisible by 3 and 5",num);         return 0; }

‘C’ program to print the surface area and volume (surface area = 2Ļ€r2 + 2Ļ€rh, volume = Ļ€r2h) of Cylinder

C File = /* Write a ‘C’ program to accept dimensions of a cylinder and print the surface area and volume  (surface area = 2Ļ€r2 + 2Ļ€rh,  volume = Ļ€r2h) */ #include<stdio.h> #define pi 3.142 int main()  {       int r,h;       float sa,v;         printf("\n Enter radius of cylinder : ");       scanf("%d",&r);       printf("\n Enter height of cylinder : ");       scanf("%d",&h);         v=(pi*r*r*h);       sa=(2*pi*r*r)+(2*pi*r*h);         printf("\n Surface Area = %f",sa);       printf("\n Volume = %f",v);       return 0; }

‘C’ program to print surface area (surface area=2(lb+lh+bh) of cuboid.

C File => /* Write a ‘C’ program to accept three dimensions length (l), breadth(b)  and height(h) of a cuboid and print surface area (surface area=2(lb+lh+bh)*/ #include<stdio.h> int main()  {        int l,b,h;          printf("\n Enter length : ");        scanf("%d",&l);        printf("\n Enter breadth : ");        scanf("%d",&b);        printf("\n Enter height : ");        scanf("%d",&h);        printf("\n Surface Area of cuboid = %d",2*(l*b+l*h+b*h));        return 0; }

‘C’ program to check if character is uppercase or lowercase.

C File => /* Write a ‘C’ program to accept a character and check if it is uppercase  or lowercase */ #include<stdio.h> #include<ctype.h> int main()  {         char ch;         printf("\n Enter character : ");         scanf("%c",&ch);         if(islower(ch))               printf("\n Lower case character..");         else if(isupper(ch))               printf("\n Upper case character..");        else               printf("\n Invalid input...");       return 0; }

‘C’ program to search for a specific number in array.

C File => /* Write a ‘C’ program to accept n integers in an array and search for a  specific number. */ #include<stdio.h> int main()  {        int n,i,key,arr[30],flag=0;            printf("\n How many integers? ");        scanf("%d",&n);          for(i=0;i<n;i++)       {          printf("\n Enter element%d",i+1);          scanf("%d",&arr[i]);        }          printf("\n Enter element to search : ");          scanf("%d",&key);           // Searching for key         for(i=0;i<n;i++)        {             if(arr[i]==key)            {                flag=1;                break;             }         }       if(flag==1)           printf("\n %d is found in array",key);      else           printf("\n %d is Not found in array",key);      return 0; }

‘C’ program to find the maximum number from an array of n integers.

C File => /* Write ‘C’ program to find the maximum number from an array of n  integers. */ #include<stdio.h> int main()  {        int num[30],i,max=0,n;        printf("\n How many integers? ");        scanf("%d",&n);        printf("\n Enter integers :\n");          for(i=0;i<n;i++)             scanf("%d",&num[i]);          for(i=0;i<n;i++)       {            if(max<num[i])                   max=num[i];        }        printf("\n Maximum of given numbers is : %d",max);  return 0; }

‘C’ program to accept an array of n float values and display them in the reverse order.

C File => /* Write a ‘C’ program to accept an array of n float values and display  them in the reverse order. */ #include<stdio.h> int main()  {       int n,i;       float arr[30];       printf("\n How many elements? ");       scanf("%d",&n);      // Accepting input      for(i=0;i<n;i++)     {         printf("\n Enter element%d : ",i+1);         scanf("%f",&arr[i]);      }      printf("\n Array elements in Reverse order : \n");       for(i=n-1;i>=0;i--)             printf("%.2f\t",arr[i]);       return 0; }

‘C’ program to print digit into word

C File => /* Write ‘C’ program to accept a single digit and display it in words. For  example, Input = 9 Output = Nine */ #include<stdio.h> int main()  {       int n;       printf("\n Enter single digit number : ");       scanf("%d",&n);       switch(n)      {            case 0:printf("\n Zero");            break;            case 1:printf("\n One");            break;            case 3:printf("\n Three");            break;            case 4:printf("\n Four");            break;            case 5:printf("\n Five");            break;            case 6:printf("\n Six");            break;            case 7:printf("\n Seven");            break;            case 8:printf("\n Eight");            break;            case 9:printf("\n Nine");            break;           default:printf("\n Invalid input");         }     return 0; }

‘C’ program to calculate area and perimeter of a rectangle.

C File => /* Write a ‘C’ program to calculate area and perimeter  of a rectangle. */ #include<stdio.h> int main()  {     int l,b,a,p;     printf("\n Enter length and bredth of rectangle : ");     scanf("%d%d",&l,&b);     a=l*b;     p=2*(l+b);     printf("\n Area of rectangle = %d",a);     printf("\n Perimeter of rerectangle = %d",p);  return 0; }

‘C’ program to calculate area and circumference of a circle

C File => /* Write a ‘C’ program to calculate area and circumference of a circle. */ #include<stdio.h> #define PI 3.142 int main()  {      int r;      printf("\n Enter radius : ");      scanf("%d",&r);      printf("\n Area of circle = %f",PI*r*r);      printf("\n Circumference of circle : %f",2*PI*r);    return 0; }

Assignment I - Basic 'C'

Image
Assignment 1 Write a 'C' program to find maximum of two numbers . program to interchange numbers. To convert temperaturefrom farenheit to celcius. Best deals for Mobile To check if number is positive, negative orzero. Display all numbers between two given numbers. Write a 'C' program to calculate area and circumference of a circle. Write a ‘C’ program to calculate area and perimeter of a rectangle. Write ‘C’ program to accept a single digit and display it in words. Forexample, Input = 9 Output = Nine Write a ‘C’ program to accept an array of n floatvalues and display them in the reverse order. Write ‘C’ program to find the maximum number froman array of n integers. Write a ‘C’ program to accept n integers in an array and search for a specific number. Write a ‘C’ program to accept a character and checkif it is uppercase or lowercase. Write a ‘C’ program to accept three dimensionslength (l), breadth(b) and height(h) of a cuboid and prin

‘C’ program to display all numbers between two given numbers.

C File => /* Write a ‘C’ program to display all numbers between two given  numbers. */ #include<stdio.h> int main()  {       int n,m,i;       printf("\n Enter first number : ");       scanf("%d",&n);       printf("\n Enter last number : ");       scanf("%d",&m);         for(i=n+1;i<m;i++)             printf("%d\t",i);       return 0; }

‘C’ program to accept a number and check if it is positive, negative or zero.

C File => /* Write a ‘C’ program to accept a number and check if it is positive, negative or  zero. */ #include<stdio.h> int main()  {      int num;      printf("\n Enter an integer : ");      scanf("%d",&num);       if(num==0)           printf("\n Number is Zero");    else if(num>0)           printf("\n Number is positive");    else if(num<0)           printf("\n Number is negative");  return 0; }

‘C’ program to accept temperatures in Fahrenheit (F) and print it in Celsius (C) Formula C=5/9(F-32).

C File => /* Write a ‘C’ program to accept temperatures in Fahrenheit (F) and  print it in Celsius (C)  Formula C=5/9(F-32) */ #include<stdio.h> int main()  {       float c,f;       printf("\n Enter temperature in Fahrenheit : ");          scanf("%f",&f);        c=(5*(f-32))/9;        printf("\n Temperature in Celcius : %f",c);  return 0; }

'C' program to find maximum of two numbers.

C File => /* Write a ‘C’ program to find maximum of  two numbers. */ #include<stdio.h> int main()  {       int a,b;       printf("\n Enter number1 : ");       scanf("%d",&a);       printf("\n Enter number2 : ");       scanf("%d",&b);       if(a>b)             printf("\n Maximum of number is : %d",a);      else             printf("\n Maximum of number is : %d",b);   return 0; }

‘C’ program to accept two integers from the user and interchange them.

C File => /* Write a ‘C’ program to accept two integers from the user and interchange them. Display the interchanged numbers.*/ #include<stdio.h> int main()  {        int n1,n2,temp;        printf("\n Enter value for n1 : ");        scanf("%d",&n1);        printf("\n Enter value for n2 : ");        scanf("%d",&n2);        temp=n1;        n1=n2;        n2=temp;        printf("\n After swapping \n ");        printf("n1=%d\tn2=%d",n1,n2);    return 0; }

Assignment III - Advanced 'C'

Assignment III     1.   Write a menu driven program to perform the following operations on strings using standard library functions : 1. Convert string toupper case 2. Copy one string to another 3. Compare two strings 4. Concatenates two strings. 2.     A Write a program to  declare  a structure  person  (name, address)  which  contains another structure birthdate (day,month, year). Accept the details  of n persons and display them. 3.        Write a program to accept ‘n’ employee details (eno, ename, salary) an d   display all employee details whose salary is more than 10000, by passing    array of structure to the function. 4.     Write a C program to create structure employee (id, name,salary). Accept details of n employees and perform the following operations:a.      Display all employees.b.     Display details of all employees having  salary >           .   5.     Write a C program to accept details of n items (code, name,price) using structure. Perform

Program for addition of matrices

C File => /* Write a program to add two matrices and display the result. Use dynamic memory allocation.*/ #include<stdio.h> #include<stdlib.h> int main() {        int n,i,j,*ptr[50],*ptr1[50],sum[50][50];        printf("\n Enter order of matrix : ");        scanf("%d",&n);      //Dynamic allocation of memory       for(i=0;i<n;i++)      {         ptr[i]=(int*)malloc(n*sizeof(int));         ptr1[i]=(int*)malloc(n*sizeof(int));      }     // Accepting matrix     for(i=0;i<n;i++)    {      for(j=0;j<n;j++)     {        printf("\n Enter matrix element a%d%d : ",i+1,j+1);        scanf("%d",&ptr[i][j]);      }    }    printf("\n\n Given Matrix1 is : \n ");    for(i=0;i<n;i++)   {      for(j=0;j<n;j++)            printf("%d\t",ptr[i][j]);      printf("\n");    }    for(i=0;i<n;i++)   {    for(j=0;j<n;j++)   {      printf("\n Enter Matrix2 element b%d%d : ",i+1

Program to calculate sum of diagonal elements of matrix

C File => /* Write a C program to accept and display a matrix of order nXn. Use dynamic memory allocation. Also calculate sum of diagonal elements. */ #include<stdio.h> #include<stdlib.h> int main() {      int n,i,j,*ptr[50],sum=0;      printf("\n Enter order of matrix : ");      scanf("%d",&n);     // dynamic allocation of memory      for(i=0;i<n;i++)          ptr[i]=(int*)malloc(n*sizeof(int));     // Accepting matrix      for(i=0;i<n;i++)     {        for(j=0;j<n;j++)       {              printf("\n Enter matrix element a%d%d : ",i+1,j+1);              scanf("%d",&ptr[i][j]);        }     }     printf("\n\n Given Matrix is : \n ");     for(i=0;i<n;i++)    {        for(j=0;j<n;j++)           printf("%d\t",ptr[i][j]);        printf("\n");     }   // Calculating sum of diagonal     for(i=0;i<n;i++)   {      for(j=0;j<n;j++)     {         if(i==j)            sum=

Program to count number of occurrences of given character in the file using command line arguments.

C File => /* Write a C program to accept file name and character as command line arguments and count number of occurrences of given character in the file. */ #include<stdio.h> #include<stdlib.h> #include<string.h> int main(int argc,char *argv[]) {     char ch,cnt=0;     char c=argv[2];     FILE *fp;     fp=fopen(argv[1],"r");     while((ch=fgetc(fp))!=EOF)     {          if(ch==c)            cnt++;      }  printf("\n Count of %c = %d",argv[2],cnt); return 0; }

Program to illustrate nested union

C File => /* Write a program to accept details of ‘n’ cricket players (name, type). If type = 1 (batsman), accept batting_average. If type=2 (bowler), accept number_wickets. Use nested union. Display information of all batsmen and bowlers. */ #include<stdio.h> #include<string.h> typedef union player {     char name[30];     union type    {        int type;    }t; }; int main() {      union player p[50];      char batsman[50][50],bowler[50][50],s[30];      float avg[50];      int i,j=0,k=0,wkts[50],n1,n2,n;      printf("\n How many played? ");      scanf("%d",&n);     // Accepting input      for(i=0;i<n;i++)     {        printf("\n Enter player name : ");        scanf("%s",p->name);        strcpy(s,p->name);        printf("\n Enter type : ");        scanf("%d",&p->t.type);        if(p->t.type==1)       {           strcpy(batsman[j],s);           printf("\n Enter batting averag

Program to write user defined functions for string operations

C File => /* Write a program to perform the following operations on strings using user defined functions: a. Length of string b. Copy one string to another c. Convert string to uppercase*/ #include<stdio.h> #include<string.h> #include<stdlib.h> #include<ctype.h> int main() {       char s1[30],s2[30];       int i,len;      //Function to calculate length       int length(char str[30])      {          int len = 0;          while (str[len] != '\0')          len++;          return (len);       }    // Function to copy string to another      void copy(char s1[30],char s2[30])     {         int i=0;         for(i=0;i<strlen(s1);i++)               s2[i]=s1[i];         printf("\n Copied string = %s",s2);      }   // Function to convert string to uppercase     void case_upr(char s1[30])    {        char s[30];        for(i=0;i<strlen(s1);i++)          s[i]=toupper(s1[i]);        s[i]='\0';        printf("\n String in upp

Program to illustrate passing structure array as a function argument

C File => /* Write a C program to create a structure named book (book_name, author_name and price) and display all book details having price > 500 in a proper format by passing the structure array as function argument. */ #include<stdio.h> typedef struct book {     char name[50];     char author[50];     float price; }; int main() {     struct book b[50];     int i,n;     printf("\n How many books? ");     scanf("%d",&n);     for(i=0;i<n;i++)    {      printf("\n Enter book name%d : ",i+1);      scanf("%s",b[i].name);      printf("\n Enter author%d : ",i+1);      scanf("%s",b[i].author);      printf("\n Enter Price%d : ",i+1);      scanf("%f",&b[i].price);     }      void display(struct book b[50])     {        int i;        printf("\n\n Details of book :");        for(i=0;i<n;i++)       {          if(b[i].price>500)         {            printf("\n\n Book

Program to write function performing operations on integer

C File => /* Write a function which accepts a number and three flags as parameters if number is even set first flag to 1. If number is prime set second flag to 1 and if number is divisible by 3 or 7 set the third flag to 1(pass addresses of flags to the function.) */ #include<stdio.h> int main() {      int n,i,flag1=0,flag2=1,flag3=0;      void set_flag(int n,int *f1,int *f2,int *f3)     {          if(n%2==0)            *f1=1;          for(i=2;i<n-1;i++)         {               if(n%i==0)              {                   *f2=0;                   break;               }          }               if(n%3==0 || n%7==0)           *f3=1;        }        printf("\n Enter Number : ");        scanf("%d",&n);        set_flag(n,&flag1,&flag2,&flag3);        if(flag1==1)            printf("\n Number is even..");        if(flag2==1)            printf("\n Number is Prime..");        if(flag3==1)            printf("\n

Program to search for string having maximum characters

C File => /* Write a program to accept names of ‘n’ cities. Find the name of the city having maximum characters.*/ #include<stdio.h> #include<string.h> #include<stdlib.h> int main() {        int n,flag=0,i,max=0;        char str[50][50],s[50];        printf("\n Enter how many strings? ");        scanf("%d",&n);       for(i=0;i<n;i++)      {         printf("\n Enter String%d : ",i+1);         scanf("%s",str[i]);       }      for(i=0;i<n;i++)     {          if(max<strlen(str[i]))         {            max=strlen(str[i]);            strcpy(s,str[i]);          }      }      printf("\n String with maximum length : %s",s);   return 0; }

Program to read data from text file

C File => /* A file “student.txt” contains roll no, name and total_marks. Write a program to read this file to display all student details on screen. */ #include<stdio.h> #include<stdlib.h> int main() {     FILE *fp;     int rno,total;     char nm[30];    fp=fopen("student.txt","r");    if(!fp)       printf("\n Error in reading...");    else   {       do      {           fscanf(fp,"%d %s %d",&rno,nm,&total);           printf("\n\n Data in file : \n Roll no\t Name\t Total\n");           printf("%d\t%s\t%d\n",rno,nm,total);       }while(!feof(fp)); } return 0; }

Program to search for a character in a string

C File => /* Write a C program that accepts a string and character to search. The program will call a function, which will search for the position of occurrence of the character in the string and return its position. Function should return –1 if the character is not found in the string.*/ #include<stdio.h> #include<stdlib.h> #include<string.h> int main() {      char s[50];      char ch;      int pos;      printf("\n Enter String : ");      scanf("%s",s);      printf("\n Enter character to search : ");      scanf("%c",&ch);      int search(char str[50],char ch)     {          int i,flag=0;          for(i=0;i<strlen(str);i++)         {             if(str[i]==ch)            {                flag=1;                break;             }         }         if(flag==1)            return i+1;         else            return -1;      } //Calling function    pos=search(s,ch);    if(pos==-1)      printf("\n %c not fo

Program to calculate the total of marks and percentage.

C File => /* Write a C program to create a structure named student that accepts student roll no, name and marks of 3 subjects. Calculate the total of marks and percentage. Create an array of structures to enter information for n students and display the details. */ #include<stdio.h> typedef struct Student {     int rno;     char name[30];     int m1,m2,m3; }; int main() {     struct Student s[50];     int n,i,total[50];     float perc[50];     printf("\n How many students? ");     scanf("%d",&n);     for(i=0;i<n;i++)     {        printf("\n\n Enter Roll no %d : ",i+1);        scanf("%d",&s[i].rno);        printf("\n Enter name%d : ",i+1);        scanf("%s",s[i].name);        printf("\n Enter makrs1, marks2 and marks3 : ");        scanf("%d%d%d",&s[i].m1,&s[i].m2,&s[i].m3);        //calculating total and percentage        total[i]=s[i].m1+s[i].m2+s[i].m3;        perc[

Program to search particular element in structure

C File => /* Write a C program to accept details of n items (code, name, price) using structure. Perform the following operations: a. Display all items having price > ___ b. Search for an item by name.  */ #include<stdio.h> #include<stdlib.h> #include<string.h> typedef struct item {     int code;     char name[30];     float price; }; int main() {     struct item p[50];     int n,i,ch;     char key_name[30];     printf("\n Enter how many items? ");     scanf("%d",&n);     for(i=0;i<n;i++)    {      printf("\n\n Enter item code%d ",i+1);      scanf("%d",&p[i].code);      printf("\n Enter item name%d",i+1);      scanf("%s",p[i].name);      printf("\n Enter price%d",i+1);      scanf("%f",&p[i].price);     }     printf("\n\n 1. Display all items having price greater than 250\n 2. Search item     scanf("%d",&ch); do  {     switch(ch)    {      

Program to perform menu driven structure operations on structure employee

C File => /* Write a C program to create structure employee (id, name, salary). Accept details of n employees and perform the following operations: a. Display all employees. b. Display details of all employees having salary > 15000. */ #include<stdio.h> #include<stdlib.h> typedef struct employee {     int id;     char name[30];     float salary; }; int main() {     struct employee e[10];     int n,i,ch;     printf("\n How many employees? ");     scanf("%d",&n);    for(i=0;i<n;i++)   {           printf("\n\n Enter employee id%d : ",i+1);           scanf("%d",&e[i].id);           printf("\n Enter name%d : ",i+1);           scanf("%s",e[i].name);           printf("\n Enter Salary%d : ",i+1);           scanf("%f",e[i].salary);     }       printf("\n 1. Display details of all\n 2.Display employee having salary>15000");       printf("\n 3. Exit \n Selec