This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
for ( i=1 ; i<=10 ; ++i ) { | |
for ( j=1 ; j<=11 ; ++j ) { | |
block 1; | |
} | |
block 2; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
main() { | |
int i=1; | |
do { | |
printf("%d ", i); | |
i++; | |
} while(i <= 100); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
do { | |
loop body; | |
.... .... | |
} while (condition); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
main() { | |
int num, temp, digit, rev_num=0; | |
printf("Enter any number:\n"); | |
scanf("%d", &num); | |
temp=num; | |
while(num!=0){ | |
digit=num % 10; | |
rev_num=(rev_num*10)+digit; | |
num=num/10; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
main() { | |
int num, digit, rev_num=0; | |
printf("Enter any number:\n"); | |
scanf("%d", &num); | |
while(num!=0) { | |
digit=num % 10; | |
rev_num=(rev_num*10)+digit; | |
num=num/10; | |
} | |
printf("%d", rev_num); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
main() { | |
int i,n,sum=0; | |
printf("Enter the value of n:\n"); | |
scanf("%d", &n); | |
while(i<=n) { | |
sum=sum+i; | |
++i; | |
} | |
printf("Sum=%d",sum); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
while (condition) { //execution will only enter while loop when the condition is satisfied | |
block 1; | |
block 2; //we can also use inc/dec operator for incrementing or decrementing the value | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
for(i = 1 ; i < 10 ; ++i) { | |
if( i == 5 ) { | |
continue; | |
printf("%d",i); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
for (i = 0 ; i < 10 ; ++i) { | |
if ( i == 5 ) { | |
break; | |
printf("%d",i); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
main(){ | |
long int i,n,factorial=1; | |
printf("Enter any number to find it's factorial:"); | |
scanf("%d", &n); | |
for( i=1 ; i<=n ; ++i ) { | |
factorial=factorial*i; | |
} | |
printf("%ld",factorial); | |
} |