c program to find the average of n numbers using goto

Description


This program is used to find the average of n numbers using goto statement. The value for n is read into the variable n and the value of i is initially set to 1. Then the numbers are read one by one each time adding it to the variable sum and incrementing the value of i. This process continues until the value of i reaches n. Then the average is calculated by using the statement avg=sum/n;


Program


#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int a;
float n,sum=0,avg,i=1;
printf("enter the value of n");
scanf("%f",&n);
printf("enter the numbers");
l:
scanf("%d",&a);
sum=sum+a;
i=i+1;
if(i<=n)
{
goto l;
}
else
{
avg=sum/n;
printf("average is %f",avg);
}
getch();
}

No comments: