Sunday, August 25, 2013

IF Statement

Example 1:

// IF Statement

#include <stdio.h>
int main()
{
   int a,b,sum;
   printf("Enter the value of a and b \n");
   scanf("%d%d",&a,&b);
   sum = a + b;
   printf("Sum of a and b is %d\n", sum);
   if(sum > 50)
   {
       printf("Sum is greater than 50 \n");
   }
  /* else if(sum > 40)
   {
       printf("Sum is greater than 40\n");
   }
   else if(sum > 30)
   {
       printf("Sum is greater than 30\n");
   }

   else if(sum > 20)
   {
       printf("Sum is greater than 20\n");
   }
  else
   {
       printf("Sum is less than 10 \n");
   }*/
return 0;
}

//Video Tutorial for If Statement




Example 2:

#include <iostream>
using namespace std;
int main()
{
   int a,b,sum;
   cout <<"Enter the value of a and b \n";
   cin >> a >>b;
   sum = a + b;
   cout <<"Sum of a and b is "<<sum<<"\n";
   if(sum > 20)
   {
       cout <<"Sum is greater than 20 \n";
   }
   else if(sum > 10)
   {
       cout <<"Sum is greater than 10 and less than 20\n";
   }
   else
   {
       cout <<"Sum is less than 10 \n";
   }
return 0;
}

1 comment:

  1. This Website is Easy to Learn and usefull and my douts is remove after learn this website.

    ReplyDelete