Structures - Enter name Dave Enter 3 test scores 99 77 55...

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 DocumentRight 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 &lt;stdio.h&gt; struct Student { char name [20]; int t1,t2,t3; float avg; }; void main() { struct Student s; printf(&quot;Enter name &quot;); gets(s.name); printf(&quot;Enter 3 test scores &quot;); scanf(&quot;%d%d%d&quot;,&amp;s.t1,&amp;s.t2,&amp;s.t3); s.avg=(s.t1+s.t2+s.t3)/(float)3; printf(&quot;%s %d %d %d %f\n&quot;,s.name,s.t1,s.t2,s.t3,s.avg); } */...
View Full Document

This note was uploaded on 10/05/2011 for the course CS 36 taught by Professor Sethhochwald during the Spring '09 term at Irvine Valley College.

Page1 / 2

Structures - Enter name Dave Enter 3 test scores 99 77 55...

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

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