×

C Programs

C Basic & Conditional Programs

C Looping Programs

C String Programs

C Miscellaneous Programs

C program to find SUM and AVERAGE of two numbers.

In this C program, we are going to learn how to find sum and average of two integer numbers? Here, we are taking input from the user of two integer number, first number will be stored in the variable a and second number will be stored in the variable b.

Sum of the numbers is calculating by a+b and assigning into variable sum and average of numbers in calculating by (float)(a+b)/2 and assigning to variable avg. Here, float is using to cast type.

Sum and Average of two numbers

Note: Only integer values should be entered as input.

/* c program find sum and average of two numbers*/
#include <stdio.h>
 
int main()
{
    int a,b,sum;
    float avg;
 
    printf("Enter first number :");
    scanf("%d",&a);
    printf("Enter second number :");
    scanf("%d",&b);
 
    sum=a+b;
    avg= (float)(a+b)/2;
 
    printf("\nSum of %d and %d is = %d",a,b,sum);
    printf("\nAverage of %d and %d is = %f",a,b,avg);
 
    return 0;
}

Output

    Enter first number :10
    Enter second number :15

    Sum of 10 and 15 is = 25
    Average of 10 and 15 is = 12.500000

C Basic Programs »

Related Programs

Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.