Logo 
Search:

C Programming Articles

Submit Article
Home » Articles » C Programming » Homework HelpRSS Feeds

Program to find average of two numbers

Posted By: Hilma Miller     Category: C Programming     Views: 31536

Write a program to find average of two numbers

Code for Program to find average of two numbers in C Programming

#include<stdio.h>

void main()
{
        int number1,number2,number3;
        float average;
        int sum=0;
        for(number3=1;number3<=7;number3++)
        {
                printf("Enter the number:");
                if(scanf("%d",&number1)==1)
                {
                sum=sum+number1;
                average=sum/number3;
                printf(" The sum :%d\t The average:%f\n",sum, average);
                }
                else
                {
                        printf("Error,Enter the correct number.");
                }

        }
        printf("\nThe aggregate average is:%6.2f",average);
}

=========================================OUTPUT====================================



Enter the number:23
 The sum :23     The average:23.000000
Enter the number:45
 The sum :68     The average:34.000000
Enter the number:76
 The sum :144    The average:48.000000
Enter the number:34
 The sum :178    The average:44.000000
Enter the number:29
 The sum :207    The average:41.000000
Enter the number:30
 The sum :237    The average:39.000000
Enter the number:966
 The sum :1203   The average:171.000000

The aggregate average is:171.00
  
Share: 


Didn't find what you were looking for? Find more on Program to find average of two numbers Or get search suggestion and latest updates.

Hilma Miller
Hilma Miller author of Program to find average of two numbers is from Frankfurt, Germany.
 
View All Articles

 
Please enter your Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

 
No Comment Found, Be the First to post comment!