C program to find sum and average of two numbers

C program to find sum and average of two numbers with repeating the calculation as log as the user wants to calculate any number of calculation.
Algorithm

  1. Accept the first number
  2. Accept the second number
  3. Calculate sum and average
  4. Ask the user if he/she wants to compute again
  5. If yes, repeat the above steps else display the output and exit

Code
#include<stdio.h>
#include<conio.h>
#include<process.h>
void main()
{
clrscr();
int n1,n2,sum,choice;
float avg;
label:printf("Enter the first number \n");
scanf("%d",&n1);
printf("Enter the second number \n");
scanf("%d",&n2);
sum=n1+n2;
avg=float(sum)/2;
printf("\n Sum= %d",sum);
printf(" \n Average= %f \n",avg);
printf("\n Do you want to compute again? \n");
printf("\n Press \"1\" to repeat the routine again or press \"0\" to exit. \n");
scanf("%d",&choice);
if(choice==1)
goto label;
else
exit(0);
getch();
}

Share this article:
Previous Post: C Programming code to convert inches to centimeters

October 1, 2014 - In Academics, Computers

Next Post: C Programming code to calculate area of a circle

October 1, 2014 - In Academics, Computers

Related Posts

Leave a Reply

Your email address will not be published.