Return Statements

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

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("The 3 numbers are %d %d %d\n",x,y,z); printf("The average is %f\n",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

{[ snackBarMessage ]}

Ask a homework question - tutors are online