Clouds
Home
Tutorial of C language
Computer Language
Introduction to C
Programming in C
Structure of C program
Variable in C
Datatypes in C
Token in C
Operator in C
Precedence of C Operator
Assignment Operator in C
Logical Operator in C
Bitwise Operator in C
Ternary Operator in C
C Input Output
Pointers in C
Storage Classes of C
Control Structure of C
C Decision Making Statement
C Looping Statement
C Jumping Statement
C Function
Function Call By Value
Function Call By Reference
C Input Output Function
C Structure
Array in C
Union in C

Decision Making Statements

if-Statement

Syntax: -

				if(condition)
				{
					
				}
				

Example:-

				#include<stdio.h>
				#include<conio.h>
				void main()
				{
				  	int a=5;
				  	If(a>6)
				  	Printf("Hello");
				  	Printf("Bye");
				 	getch();
				}
				
Output: Bye

Example:-

				#include<stdio.h>
				#include<conio.h>
				void main()
				{
				  	int a=5;
				  	If(a<6)
				  	Printf("Hello");
				  	Printf("Bye");
				 	getch();
				}
				
Output: HelloBye

Example:-

				#include<stdio.h>
				#include<conio.h>
				void main()
				{
				  	int n;
				  	printf("Enter the value of n:");
				  	scanf("%d",&n);
				  	if(n%2==0)
				  	{
				   	 	printf("Number is even");
				  	}
				   	if(n%2==1)
				   	{
				    	printf("Number is odd");
				    }
				  	getch();
				}
				

Question: write a program enter the value of a & b then print the highest value.

				#include<stdio.h>
				#include<conio.h>
				void main()
				{
				 	Int a,b;
				 	printf("Enter the value of a:");
				 	scanf("%d",&a);
				 	printf("Enter the value of b:");
				 	scanf("%d",&b);
				 	if(a>b)
				 	{
				 		printf("Highest value is a");
				 	}
				 	if(a<b)
				 	{
				  		printf("Highest value is b");
				 	}
					getch();
				}
				

if..else condition

The expression following if evaluates to true and performs else part if it evaluates to false.

Syntax:-

				if(condition)
				{
					
				}
				else
				{
					
				}
				

Example:-

				#include<stdio.h>
				#include<conio.h>
				void main()
				{
				  	int a;
				  	printf("Enter the value of a:");
				  	scanf("%d",&a);
				  	if(a>5)
				  	{
				    	printf("Hello");
				 	}
				 	else
				 	{
				  		printf("Bye");
					}
					getch();
				}
				

Question: WAP enter the value of n then check whether the number even or odd

				#include<stdio.h>
				#include<conio.h>
				void main()
				{
				 	int n;
				  	printf("Enter the value of n:");
				  	scanf("%d",&n);
				  	if(n%2==0)
				  	{
				    	printf("Number is even");
				 	}
				 	else
				 	{
				  		printf("Number is odd");
					}
					getch();
				}
				

Question: WAP enter the year then check weather the year is Leap year or Not.

				#include<stdio.h>
				#include<conio.h>
				void main()
				{
				 	int year;
					clrscr();
				 	printf("Enter the Year:");
					scanf("%d",&year);
				 	if(year%4==0)
					{
				  		printf("year is Leap year");
					}
					else
					{
				  		printf("Not Leapyear");
					}
					getch();
				}
				

Question: write a program enter the value of a & b then print the highest value.

				#include<stdio.h>
				#include<conio.h>
				void main()
				{
				 	Int a,b;
				  	printf("Enter the value of a:");
				  	scanf("%d",&a);
				  	printf("Enter the value of b:");
				  	scanf("%d",&a);
				  	if(a>b)
				  	{
				  	 	printf("Highest value is a");
				  	}
				  	else
				  	{
				   		printf("Highest value is b");
				  	}
					getch();
				}
				

else - if condition

Syntax:-

				if(condition)
				{
					
				}
				else
				{
				    If(Condition)
				    {
				     	
				    }
				   	else
				    {
				    	
				    }
				}
				

Question: WAP enter the value of a, b and c then print the highest value.

				#include<stdio.h>
				#include<conio.h>
				void  main()
				{
				 	clrscr();
					printf("Enter the value of a: ");
					scanf("%d",&a);
					printf("Enter the value of b: ");
					scanf("%d",&a);
					printf("Enter the value of c: ");
					scanf("%d",&c);
					if(a>b && a>c)
					{
				 		printf("Heghest value is=",a);
					}
					else
					{
				 		if(b>c)
				 		{
				  			printf("Highest value=",b);
				 		}
				 		else
				 		{
				  			printf("Highest value=",c);
				 		}
						getch();
					}
				}
				

Question: WAP enter the value of a, b and c then print the highest value using logical operator.

				#include<stdio.h>
				#include<conio.h>
				void main()
				{
					clrscr();
				 	printf("Enter the value of a: ");
				 	scanf("%d",&a);
				 	printf("Enter the value of b: ");
				 	scanf("%d",&b);
				 	printf("Enter the value of c: ");
					scanf("%d",&c);
					if(a>b)
					{
				 		if(a>c)
				 		{
				 			printf("Heghest value is=",a);
				 		}
				 		else
				 		{
				 			printf("Highest value=",c;
				 		}
					}
					else
					{
						if(b>c)
						{
				 			printf("Highest value=",b;
				 		}
				 		else
				 		{
				 			printf("Highest value=",c);
				 		}
					}
					getch();
				}
				

C Looping Statement >>
C Jumping Statement >>
C Function >>
Function Call By Value >>
Function Call By Reference >>


Home Clouds