2 Aug 2019

  • August 02, 2019
  • Amitraj




* Structure:- 

   A structure is a collection of  Dissimilar data elements hence also  known as Heterogeneous            data type.
 1. The keyword used to declare a structure is 'struct'.
 2. The general syntax of structure declaration is as follows:
              
              struct  tagname
               {
                      datatype 1       variable 1;
                      datatype 2       variable 2
                      datatype 3       variable 3;
                      .
                      .
                      datatype n        variable n;
               }structure variable 1,var 2,var 3..var n;


/*  C Program to store student records into structure and calculate percentage      By Amit raj purohit*/

http://codevidyalay.blogspot.com 

#include<stdio.h>
struct student
{
char name[10];
int rollno;
int m1,m2,m3;
float p;
char grade;
}s[100];
int main()
{

int n,i;
printf("enter how many student records:");
scanf("%d",&n);
for(i=0;i<n;i++)
{

printf("enter a student %d details name, rollno,m1,m2,m3\n",i+1);
scanf("%s%d%d%d%d",&s[i].name,&s[i].rollno,&s[i].m1,&s[i].m2,&s[i].m3);
}
for(i=0;i<n;i++)
{

s[i].p=(s[i].m1+s[i].m2+s[i].m3)/3.0;
if(s[i].p>=60)

s[i].grade='A';
else
if(s[i].p>=50)
s[i].grade='B';
else
if(s[i].p>=35)
s[i].grade='C';
else
s[i].grade='D';
}

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

printf("Rollno=%d\n name=%s\n grade=%c\n
percentage=%f\n",s[i].rollno,s[i].name,s[i].grade,s[i].p);

return 0;
}


INPUT/OUTPUT:
enter how many student records:2
enter a student 1 details name, rollno,m1,m2,m3
AKSHAY 1 99 88 77
enter a student 2 details name, rollno,m1,m2,m3
AMRIT 2 88 99 77
Rollno=1
name=AKSHAY
grade=A
percentage=88.000000
Rollno=2
name=AMRIT
grade=A
percentage=88.000000







Translate

Popular Posts