PROCEDURE:-
CODE:-
#include<stdio.h>
void main()
{
int n, i=1, sum=0;
printf(“enter value for n”);
scanf(“%d”,&n);
abc:
sum=sum+i;
i=i+1;
if (i<=n) goto abc;
printf(“sum upto %d numbers is %d”,n,sum);
}
Input:- enter value for n
n=5
Output:- sum upto 5 numbers is 15
- input value for n
- set initial values for sum as 0 and I as 1
- add I to sum and increment I by 1
- if I is less than or equal to n goto step 3
- print the sum
CODE:-
#include<stdio.h>
void main()
{
int n, i=1, sum=0;
printf(“enter value for n”);
scanf(“%d”,&n);
abc:
sum=sum+i;
i=i+1;
if (i<=n) goto abc;
printf(“sum upto %d numbers is %d”,n,sum);
}
Input:- enter value for n
n=5
Output:- sum upto 5 numbers is 15
Comments
Post a Comment