Canna

Tuesday, 25 September 2018

IO 5

  • Problem Description

    Write a program to scan the given input and perform unary prefix increment and decrement operators. Condition : Variable name to be used: Preadd, Presub, Postadd, Postsub

    Perform the following operations:
    1. Preadd = ++a
    2. Presub = --a
    3. Postadd =a++
    4. Postsub =a--
  • Test Case 1

    Input (stdin)
    2
    
    
    Expected Output
    3
    
    2
    
    2
    
    3
  • Test Case 2

    Input (stdin)
    7
    
    
    Expected Output
    8
    
    7
    
    7
    
    8
  • Program
  • #include <stdio.h>
    int main()
    {
      int a,preadd,presub,postadd,postsub;
      scanf("%d",&a);
      preadd=++a;
       presub=--a;
         postadd=a++;
      postsub=a--;
      printf("%d\n",preadd);
        printf("%d\n",presub);
        printf("%d\n",postadd);
        printf("%d\n",postsub);
     
    
     return 0;
    }

No comments:

Post a Comment

Note: only a member of this blog may post a comment.