01 February 2022

Pointers

 QUESTION :

Write a program using a Function that calculates the Sum And Average of two numbers. 

Use pointers and print the value of Sum and Average in main ().


#include<stdio.h>

void sumAndAvg(int a, int b, int*sum, float*avg){
            *sum = a + b;
            *avg = (float) (*sum/2);
}
 
int main()
{
    int i,j,sum;
    float avg;
    i = 7;
    j = 3;

    sumAndAvg(i,j, &sum, &avg);
    printf("The sum of two numbers is %d\n", sum);
    printf("The average of two numbers is %f\n", avg);
 
return 0;
}

OUTPUT--->

The sum of two numbers is 10 The average of two numbers is 5.000000








No comments:

Post a Comment