-->

WAP to enter student id, student name and address for any 10 students. Then search a data and its location.

in codeblocks:
--------------------------------------------------------------------------------------------------
// program to search data in given  detail of some  students       //comment abt. program
#include <stdio.h>                                 //header file
#include<string.h>
struct data                                        //struct tag named data
{
    char name[80];                                //member1 of struct
    char address[80];                             //member2 of struct
    int roll;                                     //member3 of struct
    int english,maths,physics,chemistry,nepali,total;   //marks member declaration
    float percentage;                       //member for total and percentage

}access[100];                 //'access' is a variable to access members. This can hold maximum 100 members.it is called array of struct.
int main()
{
   int n,i,loc=0;                                         //variable declaration
   char naam[70];
    printf("enter total value of n\n");
   scanf("%d",&n);                                  //accepts total value
   for(i=0;i<n;i++)
   {                                                 //execution of loop with inputs
    puts("enter roll number \n");
   scanf("%d",&access[i].roll);                      //gets data in different member
   puts("enter name \n");
   scanf("%s",access[i].name);                       //gets name
   puts("enter address \n");
   scanf("%s",access[i].address);                    //gets address
   printf("enter english marks\n");
   scanf("%d",&access[i].english);                  //gets respective marks
   printf("enter maths marks\n");
   scanf("%d",&access[i].maths);
   printf("enter Physics marks\n");
   scanf("%d",&access[i].physics);
   printf("enter chemistry marks\n");
   scanf("%d",&access[i].chemistry);
   printf("enter nepali marks\n");
   scanf("%d",&access[i].nepali);
   access[i].total=access[i].english+access[i].maths+access[i].physics+access[i].chemistry+access[i].nepali;//finds total and stores
      access[i].percentage=(float)access[i].total/5;               //finds percentage and stores in respective member
   }
   printf("entered data are\n");                  //loop execution to display data
   for(i=0;i<n;i++)
   {
   printf("roll=%d,name=%s,address=%s, english=%d,maths=%d,physics=%d,chemistry=%d,nepali=%d\n",access[i].roll,access[i].name,access[i].address,access[i].english
          ,access[i].maths,access[i].physics,access[i].chemistry,access[i].nepali);
   }                                                //displays data

   printf(" data with total and percentage are\n");     // displays data with total and percentage
  for(i=0;i<n;i++)
   {
   printf("roll=%d,\tname=%s,\taddress=%s,\tenglish=%d,\tmaths=%d,\tphysics=%d,\tchemistry=%d,\tnepali=%d,\ttotal=%d,\tpercentage=%f\n",access[i].roll,access[i].name,access[i].address,access[i].english
          ,access[i].maths,access[i].physics,access[i].chemistry,access[i].nepali,access[i].total,access[i].percentage);
   }
   printf("to be searched is\n");
   scanf("%s",naam);         //data input to be searched
   for(i=0;i<n;i++)
   {
       if(strcmp(naam,access[i].name)==0)//data comparison
        {
           loc=1;
           break;                    //terminating the loop
        }
   }
   if(loc==1)
   {
       printf("data found and location=%d",i);//printing the location of data
       printf("and data are,roll=%d,\tname=%s,\taddress=%s,\tenglish=%d,\tmaths=%d,\tphysics=%d,\tchemistry=%d,\tnepali=%d,\ttotal=%d,\tpercentage=%f\n",access[i].roll,access[i].name,access[i].address,access[i].english
          ,access[i].maths,access[i].physics,access[i].chemistry,access[i].nepali,access[i].total,access[i].percentage);
")
   }
   else
   {
       printf("not found\n");
   }

    return 0;
}

No comments:

Post a Comment