{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Structures - Enter name Dave Enter 3 test 55 Enter name...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
//array of structures using parameter passing #include <stdio.h> #define SIZE 4 struct Student { char name [20]; int t1,t2,t3; float avg; }; void load(struct Student s[],int n) { for(int i=0;i<n;i++) { printf("Enter name "); gets(s[i].name); printf("Enter 3 test scores "); scanf("%d%d%d",&s[i].t1,&s[i].t2,&s[i].t3); s[i].avg=(s[i].t1+s[i].t2+s[i].t3)/(float)3; fflush(stdin); } } void print(struct Student s[],int n) { for(int i=0;i<n;i++) printf("%s %d %d %d %f\n",s[i].name,s[i].t1,s[i].t2,s[i].t3,s[i].avg); } void main() { struct Student s[SIZE]; load(s,SIZE); print(s,SIZE); } /* Enter name John Enter 3 test scores 85 97 88 Enter name Steve Enter 3 test scores 66 99 88
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Enter name Dave Enter 3 test scores 99 77 55 Enter name Allen Enter 3 test scores 88 44 22 John 85 97 88 90.000000 Steve 66 99 88 84.333336 Dave 99 77 55 77.000000 Allen 88 44 22 51.333332 Press any key to continue . . . */ /* Sum+avg using structures #include <stdio.h> struct Student { char name [20]; int t1,t2,t3; float avg; }; void main() { struct Student s; printf("Enter name "); gets(s.name); printf("Enter 3 test scores "); scanf("%d%d%d",&s.t1,&s.t2,&s.t3); s.avg=(s.t1+s.t2+s.t3)/(float)3; printf("%s %d %d %d %f\n",s.name,s.t1,s.t2,s.t3,s.avg); } */...
View Full Document

{[ snackBarMessage ]}

Page1 / 2

Structures - Enter name Dave Enter 3 test 55 Enter name...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon bookmark
Ask a homework question - tutors are online