Search This Blog

Friday, October 7, 2011

Write a program to read an integer from the keyboard, add 1 to it if the Num in Even and again Add 1 to it if the Num is less 20 otherwise keep it as it is

   1:  #include<stdio.h>
   2:  #include<conio.h>
   3:  void main()
   4:  {
   5:  int n,k;
   6:  clrscr();
   7:  printf("Enter the int num:\n");
   8:  scanf("%d",&k);
   9:  n=k;
  10:  if(k%2==0)
  11:  {
  12:  n=n+1;
  13:      if(n<20)
  14:      n=n+1;
  15:  }
  16:  printf("Original value of num: %d\n",k);
  17:  printf("Final value of num: %d",n);
  18:  getch();
  19:  }

No comments:

Post a Comment