C Program to find Sum and Average of two numbers

In this article, I will show you how you can write a C Program to find Sum and Average of two numbers. I will explain the algorithm, and concepts and then help you to write C Program to find Sum and Average of two numbers.

1. Program Outline

In this program, you’ll have to take two numbers as input from the user and then calculate the sum and then print the average of both the numbers in the terminal.

2. Concepts

To write this C program to find Sum and Average of two numbers, you need to learn the following concepts of C Programming:

  1. Input
  2. Variables
  3. Loop

3. Algorithm

To write this C program, follow this Algorithm:

Step 1: Input n
Step 2: If n is invalid, display error message, go to step 1, else step 3
Step 3: Sum=0
Step 4: count=0
Step 5: Input x
Step 6: If x is invalid, display error message, go to step 5, else step 7
Step 7: count=count+1
Step 8: Sum=Sum+x
Step 9: If ( count< n) go to step 5, else step 10
Step 10: Av=Sum /n
Step 11: Output Av

4. Program

Here’s the C Program to find Sum and Average of two numbers:

#include <stdio.h>
  
int main()
{
    int x,y,sum;
    float average;
  
    printf("Enter first number :");
    scanf("%d",&x);
    printf("Enter second number :");
    scanf("%d",&y);
  
    sum=x+y;
    average= (float)(x+y)/2;
  
    printf("\nSum of %d and %d is = %d",x,y,sum);
    printf("\nAverage of %d and %d is = %f",x,y,average);
  
    return 0;
}

5. Output

Here’s the output of the above C Program:

C Program to find Sum and Average of two numbers
groot
groot

Leave a Reply

Your email address will not be published. Required fields are marked *