0% found this document useful (0 votes)
2 views6 pages

C Programs 1

The document contains multiple C programming exercises focusing on conditional statements. Each exercise includes a problem statement, test data, expected output, and sample code to implement the solution. Topics covered include voting eligibility, integer comparison, height categorization, and finding the largest of three numbers.

Uploaded by

Debabrata Dutta
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)
2 views6 pages

C Programs 1

The document contains multiple C programming exercises focusing on conditional statements. Each exercise includes a problem statement, test data, expected output, and sample code to implement the solution. Topics covered include voting eligibility, integer comparison, height categorization, and finding the largest of three numbers.

Uploaded by

Debabrata Dutta
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/ 6

}

Flowchart :

C Conditional Statement: Exercise-5 with Solution


Write a C program to read age of a candiadte and detrermine whether it is eligible for casting his/her own vote.
Test Data :
21
Expected Output :
Congratulation! You are eligible for casting your vote..

Sample Solution :-

Flowchart :
Sample Solution :-

C Code :

#include <stdio.h>

void main()
{
int vote_age;

printf("Input the age of the candidate : ");


scanf("%d",&vote_age);
if (vote_age<18)
{
printf("Sorry, You are not eligible to caste your vote.\n");
printf("You would be able to caste your vote after %d year.\n",18-vote_age);
}
else
printf("Congratulation! You are eligible for casting your vote.\n");

C Conditional Statement: Exercise-6 with Solution


Write a C program to read the value of an integer m and display the value of n is 1 when m is larger than 0, 0 when
m is 0 and -1 when m is less than 0.
Test Data : -5
Expected Output :
The value of n = -1

Sample Solution :-
C Code:

#include <stdio.h>

void main()
{
int m,n;
printf("Input the value of m :");
scanf("%d",&m);
if(m!=0)
if(m>0)
n=1;
else
n=-1;
else
n=0;
printf("The value of m = %d \n",m);
printf("The value of n = %d \n",n);
}

Flowchart :

C Conditional Statement: Exercise-7 with Solution


Write a C program to accept the height of a person in centimeter and categorize the person according to their
height.
Test Data :
135
Expected Output :
The person is Dwarf.

Sample Solution :-

C Code:

#include <stdio.h>

void main()
{
float PerHeight;

printf("Input the height of the person (in centimetres) :");


scanf("%f", &PerHeight);
if (PerHeight < 150.0)
printf("The person is Dwarf. \n");
else if ((PerHeight >= 150.0) && (PerHeight <= 165.0))
printf("The person is average heighted. \n");
else if ((PerHeight >= 165.0) && (PerHeight <= 195.0))
printf("The person is taller. \n");
else
printf("Abnormal height.\n");
}

Flowchart :
C Conditional Statement: Exercise-8 with Solution
Write a C program to find the largest of three numbers.

Test Data :
12 25 52

Expected Output :
1st Number = 12, 2nd Number = 25, 3rd Number = 52
The 3rd Number is the greatest among three

Sample Solution :-
C Code:

#include <stdio.h>

void main()
{
int num1, num2, num3;

printf("Input the values of three numbers : ");


scanf("%d %d %d", &num1, &num2, &num3);
printf("1st Number = %d,\t2nd Number = %d,\t3rd Number = %d\n", num1, num2, num3);
if (num1 > num2)
{
if (num1 > num3)
{
printf("The 1st Number is the greatest among three. \n");
}
else
{
printf("The 3rd Number is the greatest among three. \n");
}
}
else if (num2 > num3)
printf("The 2nd Number is the greatest among three \n");
else
printf("The 3rd Number is the greatest among three \n");
}

OR

#include <stdio.h>

void main() {
int num1, num2, num3;

printf("Input the values of three numbers : ");


scanf("%d %d %d", &num1, &num2, &num3);
printf("1st Number = %d,\t2nd Number = %d,\t3rd Number = %d\n", num1, num2, num3);

if ((num1 > num2) && (num1 > num3))


printf("The 1st Number is the greatest among three. \n");

if ((num2 > num3) && (num2 > num1))


printf("The 2nd Number is the greatest among three \n");

if ((num3 > num1) && (num3 > num2))


printf("The 3rd Number is the greatest among three. \n");

OR

#include <stdio.h>

void main() {
int num1, num2, num3,ctr;

printf("Input the values of three numbers : ");


scanf("%d %d %d", &num1, &num2, &num3);
printf("1st Number = %d,\t2nd Number = %d,\t3rd Number = %d\n", num1, num2, num3);

if (num1 > num2 && num1 > num3) ctr=num1;

You might also like