Canna

Thursday, 27 September 2018

PRINT 2

  • 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 Output
    10
    
    9
    
    8
    
    7
    
    6
    
    5
    
    4
  • Test Case 2

    Input (stdin)
    5
    
    1
    
    
    Expected Output
    5
    
    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.