0% found this document useful (0 votes)
0 views8 pages

C Language If-Else (Selection) Program-2

The document contains multiple C language programs that demonstrate the use of if-else statements for various tasks, such as checking voting eligibility, determining if a number is odd or even, and identifying triangle types based on side lengths. It also includes programs for evaluating student performance based on percentage, finding the largest of three numbers, and solving quadratic equations. Each program is structured with input prompts and conditional logic to provide appropriate outputs.

Uploaded by

swapnilpatra09
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
0 views8 pages

C Language If-Else (Selection) Program-2

The document contains multiple C language programs that demonstrate the use of if-else statements for various tasks, such as checking voting eligibility, determining if a number is odd or even, and identifying triangle types based on side lengths. It also includes programs for evaluating student performance based on percentage, finding the largest of three numbers, and solving quadratic equations. Each program is structured with input prompts and conditional logic to provide appropriate outputs.

Uploaded by

swapnilpatra09
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

Avijit Pramanik 9038652152

C Language if-else (selection) program


// 1. Program to check whether a person is eligible to vote or not.

#include <stdio.h>
void main()
{ Avijit Pramanik 9038652152

int age;
printf("Enter your age:");
scanf("%d",&age);
Avijit Pramanik 9038652152
if(age>=18)
printf("You are eligible for voting");
else
printf("Sorry you have to wait...");
}
// 2. WAP to check a given number is odd or even?
#include<stdio.h>
void main()
{ Avijit Pramanik 9038652152
int n;
printf("Enter any number:");
scanf("%d",&n); Avijit Pramanik 9038652152
if(n%2==0)
printf("Given number is even");
else
printf("Given number is odd");
}

Avijit Pramanik 9038652152 Page 1 of 8


Avijit Pramanik 9038652152
// 3. WAP to accept a character and decide it is a vowel or not?
#include<stdio.h>
void main()
{ Avijit Pramanik 9038652152
char ch;
printf("Enter any character:");
scanf("%c",&ch);
if (ch=='a'|| ch=='A'||ch=='e'||ch=='E'||
ch=='i'||ch=='I'||ch=='o'||ch=='O'||ch=='u'||ch=='U')
printf("\nGiven character is a vowel") ;
else Avijit Pramanik 9038652152

printf("\nGiven character is not a vowel");


}
// 4. WAP to accept three sides and check triangle can be possible or not?

#include<stdio.h>
void main()
Avijit Pramanik 9038652152
{
int a,b,c;
printf("Enter three sides:");
scanf("%d %d %d",&a,&b,&c);
if(a+b>c && b+c>a && c+a>b)
printf("Triangle possible");
Avijit Pramanik 9038652152
else
printf("Triangle cannot be possible");
}

Avijit Pramanik 9038652152 Page 2 of 8


Avijit Pramanik 9038652152
//5. WAP to accept three sides and decided triangle type

#include<stdio.h>
void main()
Avijit Pramanik 9038652152
{
int a,b,c;
printf("Enter three sides:");
scanf("%d %d %d",&a,&b,&c);
if(a+b>c && b+c>a && c+a>b)
{
Avijit Pramanik 9038652152
if(a==b && b==c)
printf("\nIt is an equilateral triangle");
else if(a==b || b==c || c==a)
printf("\nIt is a isosceles triangle");
else
printf("\nIt is an scalene triangle");
}
else
printf("\nTriangle is not possible");
}

Avijit Pramanik 9038652152 Page 3 of 8


Avijit Pramanik 9038652152
//6. WAP to check a given value is +ve or –ve
#include<stdio.h>
void main()
{ Avijit Pramanik 9038652152
int n;
printf("Enter any number:");
scanf("%d",&n);
if(n>0)
printf("Given value is +ve");
else if(n<0) Avijit Pramanik 9038652152

printf("Given value is -ve");


else
printf("Given value is zero");
}
// 7. WAP to check a given year is leap year or not

#include<stdio.h>
void main()
{ Avijit Pramanik 9038652152
int y;
printf("Enter any year:");
scanf("%d",&y); Avijit Pramanik 9038652152
if(y%400==0)
printf("Given year is leap year");
else if(y%100==0)
printf("Given year is not leap year");
else if (y%4==0)
printf("Given year is leap year");
else
printf("Given year is not leap year");
}

Avijit Pramanik 9038652152 Page 4 of 8


Avijit Pramanik 9038652152
// 8. WAP to evaluate the student performance

#include<stdio.h>
void main()
{ Avijit Pramanik 9038652152
float p;
printf("Enter percentage of marks of a subject:");
scanf("%f",&p);
if(p<50)
printf("Grade is:F");
else if(p>=50 && p<60)
printf("Grade is:E");
else if(p>=60 && p<70)
printf("Grade is:D");
else if(p>=70 && p<80) Avijit Pramanik 9038652152

printf("Grade is:C");
else if(p>=80 && p<90)
printf("Grade is:B");
else
printf("Grade is:A");
}
Alternate Answer
#include<stdio.h>
void main()
{ Avijit Pramanik 9038652152

float p;
printf("Enter marks percentage:");
scanf("%f",&p);
if(p>=90)
printf("\nGrade is:A");
else if(p>=80)

Avijit Pramanik 9038652152 Page 5 of 8


Avijit Pramanik 9038652152
printf("\nGrade is:B");
else if(p>=70)
printf("\nGrade is:C");
else if(p>=60)
printf("\nGrade is:D");
else if(p>=50)
printf("\nGrade is:E");
else Avijit Pramanik 9038652152

printf("\nGrade is:F");
}
//9. WAP to find biggest among three numbers
#include <stdio.h>
void main()
{
int a,b,c; Avijit Pramanik 9038652
printf("Enter three numbers:");
scanf("%d%d%d",&a,&b,&c);
if(a>b)
Avijit Pramanik 9038652152
{
if(a>c)
printf("Big value is:%d",a);
else
printf("Big value is:%d",c);
}
else
{
if(b>c)
printf("Big value is:%d",b);
else
printf("Big value is:%d",c);
}
}

Avijit Pramanik 9038652152 Page 6 of 8


Avijit Pramanik 9038652152
Alternate Answer
#include <stdio.h>
void main()
{ Avijit Pramanik 9038652152

int a,b,c;
printf("Enter three numbers:");
scanf("%d%d%d",&a,&b,&c);
if(a>=b && a>=c)
printf("Big Value is:%d",a);
else if(b>=a && b>=c)
printf("Big value is:%d",b);
else if(c>=a && c>=b)
printf("Big value is:%d",c);
}

Alternate Answer
#include <stdio.h>

void main()
{
Avijit Pramanik 9038652152
int a,b,c,max;
printf("Enter three numbers:");
scanf("%d%d%d",&a,&b,&c);
max=a;
if(b>max)
max=b; Avijit Pramanik 9038652152
if(c>max)
max=c;
printf("\nBig value is:%d",max);
}

Avijit Pramanik 9038652152 Page 7 of 8


Avijit Pramanik 9038652152
//10. wap to finds roots of a quadratic equation
#include<stdio.h>
#include<math.h>
#include<stdlib.h>
void main() Avijit Pramanik 9038652152
{
float a,b,c,d,x1,x2;
printf("Enter value of a,b,c:");
scanf("%f %f %f",&a,&b,&c);
if(a==0)
{
printf("Given equation is not Quadratic equation");
exit(0);
}
d=b*b-4*a*c;
if(d>=0) Avijit Pramanik 9038652152

{
x1=(-b+sqrt(d))/(2*a);
x2=(-b-sqrt(d))/(2*a);
if(d>0)
{
printf("\nRoots are real and unequal");
printf("\nRoots are:%f, %f",x1,x2);
}
else
{
printf("\nRoots are real and equal");
printf("\nRoot is:%f",x1);
}
}
else
{
printf("\nRoots are imaginary");
}
}

Avijit Pramanik 9038652152 Page 8 of 8

You might also like