Wednesday, December 30, 2015

C program to add two numbers using ++ and -- operators

First method using ++ and -- operators
#include <stdio.h>
int main(void) {
  int a=3,b=6;
  while(b--){
     a++;
  }
  printf("%d",a);
  return 0;
}


Second method using ++ operator only
#include <stdio.h>
int main(void) {
  int i, iNo1, iNo2;
  iNo1=5;
  iNo2=6;
  for(i=0;i<=iNo2;i++)
      iNo1++;
  printf("%d",iNo1);
  return 0;
}

No comments:

Post a Comment