Return Statements

Return Statements - } void print(int x,int y, int z,float...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
//This program funds sum and avg of 3 numbers demonstrating return statements #include <stdio.h> void load(int*,int*,int*); void print(int,int,int,float); float calc(int,int,int); void main() { int a,b,c; float avg; load(&a,&b,&c); avg=calc(a,b,c); print(a,b,c,avg); //printf("The average is %f\n",calc(a,b,c)); (shorter way) } void load(int*z,int*b,int*t) { printf("Enter 3 values "); scanf("%d%d%d",&*z,&*b,&*t);
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: } void print(int x,int y, int z,float avg) { printf(&quot;The 3 numbers are %d %d %d\n&quot;,x,y,z); printf(&quot;The average is %f\n&quot;,avg); } float calc(int a,int b,int c) { int sum; float avg; sum=a+b+c; avg=sum/(float)3; return avg; // return(a+b+c)/(float)3; (shorter way) } /* Enter 3 values 1 2 3 The 3 numbers are 1 2 3 The average is 2.000000 Press any key to continue . . . */...
View Full Document

Ask a homework question - tutors are online