If Else Programs With Examples List

 List of If Else Programs With Examples And Explanation:
\\ If you have any query or questions on my post, then please comment below //

Program: Write a program to read 4 values a, b, c, d and evaluate the ratio of (a+b) to (c-d) and print the result if (c-d) is not equal to 0, otherwise print a message ”Value Of Denominator Is 0”.

 ---------------------------------------------------------------------------
#include<stdio.h>
#include<conio.h>
Void main()
{
int a, b, c, d, e;
clrscr();
printf("Enter The Value Of a, b, c, d");
scanf(“%d%d%d%d”, &a, &b, &c, &d);

e = ((a+b) / (c-d));
if ((c-d)!=0)
 {
 printf("%d",e);
 }
else
 {
 printf("Value Of Denominator Is 0");
 }
getch();
}
---------------------------------------------------------------------------


Program: Write a program to enter a number and check whether that number is divisible by 7 or not.
Solution: For Checking Number is divisible by 7 or not, I am using the module division concept, Here if any number is divisible by 7 then it will give the remainder 0, and in module division it store the remainder value.
Example Of Simple Division:
If we divide 40 by 2 then the answer is 20. Because 40 is divided by 2 in 20 times.

Example Of Modules Division:
If we module divides 40 by 2 then the answer is 0. Because if we divide 40 by 2 than remained would be 0. In module division it stores the remained resulting value.
---------------------------------------------------------------------
#include<stdio.h>
#include<conio.h>
Void main()
{
int a;
clrscr();
printf("Enter The Number:");
scanf(“%d”, &a);

a = a%7;                 // Using Module Divison Checking and storing the result into same variable a.
if (a == 0)
 {
 printf("Number is divisible by 7");
 }
else
 {
 printf("Number is not divisible by 7 - Enter Another Number");
 }
getch();
}
---------------------------------------------------------------------------


Program: Write a program to input a number and check whether it is even number or an odd number by using the module division method. 
Solution: We have to write a program in module division method, then if any number we module divides by 2 and we get the remained 0 then the number is an even number.  
---------------------------------------------------------------------------
#include<stdio.h>
#include<conio.h>
Void main()
{
int a, b;
clrscr();
printf("Enter The Number:");
scanf(“%d”, &a);

b=a%2;       // If any number we module divides by 2 and we get the remained 0 then it is even number.
if (b == 0)
 {
 printf(" Even Number");
 }
else
 {
 printf("Odd Number");
 }
getch();
}
---------------------------------------------------------------------------


Program: Write a program to input two numbers and find out the largest among two in c. 
Solution: By using less than "<" and greater than, ">" sign we can check, Which number is largest among two numbers.
---------------------------------------------------------------------------
#include<stdio.h>
#include<conio.h>
Void main()
{
int a, b;
clrscr();
printf("Enter The Numbers:");
scanf(“%d%d”, &a, &b);

if (a>b)               // Checking a is greater if yes than print the if block code otherwise print else block code.
 {
 printf(" a is greater");
 }
else
 {
 printf("b is greater");
 }
getch();
}
---------------------------------------------------------------------------


Program: Write a program to enter a character & check whether it is a vowel or consonant. 
Solution: By checking vowels in if statement, we can say entered character is a vowel or not. If not, then it will print the message "number is consonant".
---------------------------------------------------------------------------
#include<stdio.h>
#include<conio.h>
Void main()
{

char ch;
clrscr();
printf("Enter The Character:");
scanf(“%c”, &ch);
if (ch=='a'|| ch=='e' ||ch=='i' ||ch=='o' ||ch=='u' ||ch=='A' ||ch=='E' ||ch=='I' ||ch=='O' ||ch=='U') )              
 {
 printf(" Enter Character Is Vowel");
 }
else
 {
 printf("Enter Character Is Consonant");
 }
getch();
}
---------------------------------------------------------------------------


Click Here To Know How To Download Above Video Tutorials Or YouTube Videos Free


 Enter Your Email Id To Get Our Programming, Web Development, Video Tutorial, Job Updates In Mail :

Labels: