PROGRAM'S USING STRUCTURE Example 1://To print the student details// normal structure variable #include<stdio.h> struct student { char name[30]; int reg_no[15]; char branch[30]; }; void main() { struct student s1; printf("\n Enter the student name::"); scanf("%s",s1.name); printf("\n Enter the student register number::"); scanf("%s",&s1.reg_no); printf("\n Enter the student branch::"); scanf("%s",s1.branch); printf("\n Student Name::",s1.name); printf("\n Student Branch::",s1.branch); printf("\n Student reg_no::",s1.reg_no); getch(); } 7 GE 6151 COMPUTER PROGRAMMING UNIT_5 Example 2://To print the student details// pointer structure variable #include <stdio.h> struct name{ int a; float b; }; int main() { struct name *ptr,p; ptr=&p; /* Referencing pointer to memory address of p */ printf("Enter integer: "); scanf("%d",&(*ptr).a); printf("Enter number: "); scanf("%f",&(*ptr).b); printf("Displaying: "); printf("%d%f",(*ptr).a,(*ptr).b); return 0; } Example 3://To print the Mark sheet for a student// #include<stdio.h> struct student { char name[30]; int reg_no[15]; char branch[30]; int m1,m2,m3,total; float avg; }; 8 GE 6151 COMPUTER PROGRAMMING UNIT_5 void main() { int total; float avg; struct student s1; printf("\n Enter the student name::"); scanf("%s",s1.name); printf("\n Enter the student register number::"); scanf("%s",&s1.reg_no); printf("\n Enter the student branch::"); scanf("%s",s1.branch); printf("\n Enter the 3 subjects Marks:"); scanf("%d%d%d", &s1.m1,&s1.m2,&s1.m3); s1.total=s1.m1+s1.m2+s1.m3; printf("\n Ur Total mark is.%d", s1.total); s1.avg=a1.total/3; printf("\n Ur Average mark is.%f", s1.avg); getch(); } Example_4: /* To Print Students Mark Sheet's using Structures*/ #include"stdio.h" #include"conio.h" struct student { char name[25],grade; int reg_no[15]; int s1,s2,s3,s4,s5,total; float avg; }sa[20]; 9 GE 6151 COMPUTER PROGRAMMING UNIT_5 void main() { int i,n,total; float avg; printf("\n Enter the count of Students need marksheet::"); scanf("%d",&n); printf("\n Enter the name of students:,reg_no, 5 sub marks::"); for(i=0;i<n;i++) { printf("\n Enter the name of students,reg_no, 5 sub marks::%d",i+1); scanf("%s%d%d%d%d%d%d", &sa[i].name, &sa[i].reg_no, &sa[i].s1, &sa[i].s2, &sa[i].s3, &sa[i].s4, &sa[i].s5); sa[i].total=sa[i].s1+sa[i].s2+sa[i].s3+sa[i].s4+sa[i].s5; sa[i].avg=sa[i].total/5; if((sa[i].s1<50)||(sa[i].s2<50)||(sa[i].s3<50)||(sa[i].s4<50)||(sa[i].s5<50)) { sa[i].grade='U'; printf("Ur grade is %c", sa[i].grade); } else { if(sa[i].avg==100) { sa[i].grade='S'; printf("Ur Grade is %c", sa[i].grade); } if((sa[i].avg>90)&&(sa[i].avg<=99)) { sa[i].grade='A'; printf("Ur Grade is %c", sa[i].grade); } 10 |
No comments:
Post a Comment