Skip to main content

Conditional statement in c language

Conditional statement


This is very simple.you face these problem daily.if you want to go to market and go to park .
But at a time you can go only one place either market or park.
In programming you also face these problems.

These are given below

1.if
2.if-else
3.if-else-if
4.nested if

If statement-

statement is execute when condition is true other wise it will terminated from loop.
#include<stdio.h>
int main( )
{
if(condition)
          {
             statement;
          }
}

FLOW CHART OF IF STATEMENT-

2.if-else statement-

general syntax of if-else statement-

#include<stdio.h>
int main( )
{
if(condition)
{
statement1;
}
else
{
statement 2;
}

EXPLAINATION-
if condition true than  statement 1 execute otherwise it will be terminated.

flow chart of if-else-


3.if-else-if

General  syntax of if else if
#include<stdio.h>
int main( )
{
if(condition1)
{
statement1;
}
else if(condition 2)
{
statement 2;
}
 else
{ statement 3;
}

Explaination

if the condition1 is true than statement1 is execute or condition2 is true than statement2 is execute otherwise statement 3 will be execute.


flow chart-

4.nested-

general syntax of nested-
if (testExpression1) 
{
   statement1;
}
else if(testExpression2) 
{
   statement2;
}
else if (testExpression 3) 
{
    statement3;
}

else 
{
    statement4;
}

thanks.


Comments

Popular posts from this blog

solution of TRICOUNT - Counting Triangles on spoj

  TRICOUNT - Counting Triangles solution- #include<stdio.h> int main() {     int t;     scanf("%d",&t);     while(t--)     {         long long unsigned num,sum;         scanf("%llu",&num);         if(num%2==0)         sum=(num*(num+2)*((2*num)+1))/8;         else         sum=((num*(num+2)*((2*num)+1))-1)/8;         printf("%llu\n",sum);     }     return 0; }

solution of PRIME1 - Prime Generator on spoj

PRIME1 - Prime Generator solution- #include<stdio.h> #include<math.h> int main() {int t; long long int l,h,i,flag; scanf("%d",&t); while(t--) { scanf("%lld%lld",&l,&h); while(l<=h) { flag=0; for(i=2;i<=sqrt(l);i++) { if(l%i==0) { flag=1;     break; } } if(flag==0) { if(l!=1) printf("%lld\n",l); } l++; } printf("\n"); } return 0; }