Monday 14 March 2016

Print 2


Write a C program to print all numbers between a and b (a and b inclusive) using a while loop.

Input Format: 
Input consists of 2 integers. The first integer corresponds to a and the second integer corresponds to b. Assume a>=b.

Output Format: 
Refer Sample Input and Output for formatting specifications.
[All text in bold corresponds to input and the rest corresponds to output]

Sample Input and Output: 
Enter the value of a
10
Enter the value of b
4
10
9
8
7
6
5
4

Code:
  #include<stdio.h>
int main(){
    int a,b;
    printf("Enter the value of a\n");
    scanf("%d",&a);
    printf("Enter the value of b\n");
    scanf("%d",&b);
    while(b<=a)
    {
      printf("%d\n",a);
      a--;
    }
    return 0;
  }
    
    

1 comment:

  1. if input is 49 or 7 and we useing for loop instead of while loop how much times for loop iterate

    ReplyDelete