hello friends....
TAKE THE FIRST STEP TO KNOWLEDGE FRIENDS BECAUSE KNOWLEDGE IS FREE.
>> /* WRITE A C PROGRAM TO DISPLAY THE SUM OF FIRST 10 NATURAL NUMBER BY USING LOOP AND GO-TO FUNCTION */
#include<stdio.h>
#include<conio.h>
void main()
{
int i=0, sum =0, j=0, ans=0;
clrscr();
// using loop
while(i<=10){
printf("%d\n",i);
sum = sum + i;
i++;
}
printf("ans is : %d\n",sum);
// end loop program
printf("===============================\n");
// without using loop
// using goto function
start:
if(j<11){
printf("%d\n",j);
ans = ans + j;
j++;
}
if(j<11) {
goto start;
}
printf("final ans is : %d\n",ans);
//end goto function
getch();
}
/* OUTPUT */
===========================
/* BOTH TWO PROGRAM ARE OUTPUT IS SAME */
0
1
2
3
4
5
6
7
8
9
10
ans is : 55
* * * * * * * * * * * * * *http://www.dnpdeveloper.com
if you have like this blog so share and subscribe, comment for this blog.
if your any question, so comment pleass.
MY INSTAGRAM ID : dnp176
Comments
Post a Comment