Tuesday 25 September 2012

Function002

Write a function to input two numbers and print there sum and average.

#include <stdio.h>
#include <conio.h>
int        sum ( int, int );                         /* Function prototype declaration */
float     avg  ( int );                              /* Function prototype declaration */
void main ( )
{
        int           i, j, k;
        float        p;
        clrscr ( );
                  
        printf("\n\n\t\t Enter first number....:"); scanf("%d", &i);
        printf("\n\n\t\t Enter second number...:"); scanf("%d", &j);
                                      
        k = sum ( i, j );                         /* Function calling */
        p = avg ( k );                            /* Function calling */
                
        printf("\n\n\t\t SUM = %d", k);
        printf("\n\n\t\t AVERAGE = % .2f", p);
        getch ( );
}              
                
int    sum ( int    x, int    y )                /* Function Definition */
{                     
        int    z;
        z = x + y;
        return ( z );
}                                                                      
                                 
float  avg ( int    m )                         /* Function Definition */
{                  
        float    n;
        n = m / 2;
        return ( n );
}
Click here to contact us

No comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...