Program in C and C++ to find sum of nth numbers Using goto statement
C
CPP
#include<stdio.h>
#include<conio.h>
int main()
{
int i=1,sum=0,n;
printf("Enter a integer number:-");
scanf("%d",&n);
start:
if(i<=n)
{
sum=sum+i;
i++;
goto start;
}
printf("sum of %d numbers = %d",n,sum);
getch();
}
#include<iostream>
using namespace std;
int main()
{
int i=1,sum=0,n;
cout<<"Enter a integer number:-";
cin>>n;
start:
if(i<=n)
{
sum=sum+i;
i++;
goto start;
}
cout<<"sum of "<<n<<" numbers = "<<sum;
return 0;
}
Output:-
Related programs
0 Comments