#include <stdio.h>
int main()
{
int num1, num2;
float avg;
printf("Enter first number: ");
scanf("%d",&num1);
printf("Enter second number: ");
scanf("%d",&num2);
avg= (float)(num1+num2)/2;
//%.2f is used for displaying output upto two decimal places
printf("Average of %d and %d is: %.2f",num1,num2,avg);
return 0;
}
Enter first number: 16
Enter second number: 39
Average of 16 and 39 is: 27.50
average()
for the calculation of average. The numbers entered by user are passed to this function during function call.#include <stdio.h>
float average(int a, int b){
return (float)(a+b)/2;
}
int main()
{
int num1, num2;
float avg;
printf("Enter first number: ");
scanf("%d",&num1);
printf("Enter second number: ");
scanf("%d",&num2);
avg = average(num1, num2);
//%.2f is used for displaying output upto two decimal places
printf("Average of %d and %d is: %.2f",num1,num2,avg);
return 0;
}
Enter first number: 12
Enter second number: 19
Average of 12 and 19 is: 15.50