In this article, you will learn how to get the sum and average of two numbers using the C Programming Language. The program will prompt the user to enter two numbers, then output the sum and average of those numbers.
#include <stdio.h> int main() { int num1,num2,sum; float average; printf("Please enter the first number:"); scanf("%d",&num1); printf("Please enter the second number:"); scanf("%d",&num2); sum = num1 + num2; average = (float)(sum)/2; printf("\nSum of %d and %d is %d",num1,num2,sum); printf("\nAverage of %d and %d is = %.2f",num1,num2,average); return 0; }
Output
Please enter the first number:2 Please enter the second number:3 Sum of 2 and 3 is 5 Average of 2 and 3 is = 2.50
Happy Coding!