Problem Description
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.Test Case 1
Input (stdin)10 4
Expected Output10 9 8 7 6 5 4
Test Case 2
Input (stdin)5 1
Expected Output5 4 3 2 1
Program
#include <stdio.h> int main() { int a,b,i; scanf("%d",&a); scanf("%d",&b); if(a>=b) for(i=a;i>=b;i--) printf("%d\n",i); if(a<=b) for(i=a;i<=b;i++) printf("%d\n",i); return 0; }
No comments:
Post a Comment
Note: only a member of this blog may post a comment.