Program to find out the average of three numbers

//Program to find out the average of three numbers
#include<stdio.h>
#include<conio.h>
int main()
{
int a,b,c;
float d;
clrscr();
printf("Enter Three numbers ");
scanf("%d%d%d",&a,&b,&c);
d=(a+b+c)/3;
printf("Average is = %f",d);

getch();
return 0;

}

To Run this Program Copy it in text editor and save as .c
Then double click on it and then it will get opened in your compiler.
Click on run.




5 comments:

  1. #include
    int main()
    {
    int a,b,c,d,e,sum;
    float avg;
    printf("enter a: ");
    scanf("%d", &a);
    printf("enter b: ");
    scanf("%d", &b);
    printf("enter c: ");
    scanf("%d", &c);
    printf("enter d: ");
    scanf("%d", &d);
    printf("enter e: ");
    scanf("%d", &e);
    sum= a+b+c+d+e;
    printf("Sum is: %d\n", sum);
    avg=sum/5;
    printf("Avg is: %f\n", avg);
    return 0;
    }

    ReplyDelete
  2. Result of arithmetic operation between integers can't be float. So this programme will not work perfectly incase your average is in float.
    The solution is that declare every variable (i.e. a b c and d as float in above programme ) as float if your result can be in float.
    Khanvai...

    ReplyDelete
  3. It's very good and very easily explained

    ReplyDelete