Sunday 4 November 2012

Pointer005

Input three numbers in main function calculate there sum & average in a user defined function and print the result in the main function.

#include <stdio.h>
#include <conio.h>
void sumavg ( int   n1, int    n2, int    n3, int*s, float*avg )
{              
        *s = n1 + n2 + n3;
        *avg = ( *s ) / 3.0;
}                   
             
void main ( )
{                           
        int          n1, n2, n3, s = 0;
        float       avg;
        clrscr ( );
        printf("\n\n\n\t\t Enter 1st number..:"); scanf("%d",&n1);
        printf("\n\t\t Enter 2nd number..:"); scanf("%d",&n2);
        printf("\n\t\t Enter 3rd number..:"); scanf("%d",&n3);
        sumavg ( n1, n2, n3, &s, &avg );
        printf("\n\n\n\t\t Sum = %d",s);
        printf("\n\t\t Average = %f",avg);
        getch();
}
Click here to contact us

No comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...