adsense

Hii, welcome to my site. My name is Om prakash kartik. This blog helps you to learn programming languages concepts.

Program in C and C++ to find sum of nth numbers Using goto statement

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

  1.   Program in C to print 1 to 10 Using goto statement

Post a Comment

0 Comments