print N number in increment or decrement order using while loop in c language.

print N number in increment or decrement order using while loop in "c language".

syntex of while loop is:

while (/* condition */)
{
    /* code */
}

 take one variable and asign to 1 and put condition (i <= N) in while loop. then using printf function print (i)

 go through solution below and understand better

SOURCE CODE (INCREMENT):

#include<stdio.h>
int main(){
    int i=1,n;
    printf("enter a number to get output in increasing order :");
    scanf("%d",&n);
    while(i<=n){
        printf("%d\t",i);
        i++;
    }
    return 0;
}
OUTPUT:
enter a number to get output in increasing order :20
1       2       3       4       5       6       7       8       9       10    11 
12      13      14      15      16      17      18      19      20
SOURCE CODE(DECREMENT):
#include<stdio.h>
int main(){
    int n,i;
    printf("enter a number to get output in decreasing order :");
    scanf("%d",&n);
    i = n;
    while(i>=1){
        printf("%d\t",i);
        i--;
    }
    return 0;
}
OUTPUT:
enter a number to get output in decreasing order :20
20      19      18      17      16      15      14      13      12      11    10
9       8       7       6       5       4       3       2       1

0 Comments