Loading...

Average of Two numbers C Program


C Program which takes input of two integer number and print their average.

#include<stdio.h>
void main()
{
    int a,b;
    float avg;

    printf("Enter 1st no.");
    scanf("%d",&a);

    printf("Enter 2nd no.");
    scanf("%d",&b);

    avg=(a+b)/2.0;

    printf("The average is %.2f",avg);
}

You can also do this by an easy method Like this:

#include <stdio.h>
main()
{
int a,b;

    printf("Enter two numbers: ");
    scanf("%d %d",&a,&b);

    printf("Average is %.2f",float(a+b)/2);
}

Also by making Function of Sum:

#include<stdio.h>
float avg(int,int);
main()
{
    int a,b;
    float c;

    printf("Enter two numbers: ");
    scanf("%d %d",&a,&b);

    c=avg(a,b);

    printf("Average is %.2f",c);
}
float avg(int a,int b)
{
    return (a+b)/2.0;
}
Rate this posting:
{[['']]}

0 comments:

Post a Comment

 
TOP