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

Assignment 2, Roll No. 91

The document contains a series of C programming examples that demonstrate various conditional statements and user input handling. Each example addresses a specific scenario, such as checking eligibility for scholarships, performing arithmetic operations based on user choice, validating login credentials, and assessing scores or attendance. The code snippets illustrate how to implement logic for different conditions and provide appropriate outputs based on user input.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views8 pages

Assignment 2, Roll No. 91

The document contains a series of C programming examples that demonstrate various conditional statements and user input handling. Each example addresses a specific scenario, such as checking eligibility for scholarships, performing arithmetic operations based on user choice, validating login credentials, and assessing scores or attendance. The code snippets illustrate how to implement logic for different conditions and provide appropriate outputs based on user input.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

1. What is your age?

If you are between 18 and 25,


you are eligible for our institute’s
scholarship program.

#include <stdio.h>
int main()
{
printf("Enter your age:-");
int a;
scanf("%d",&a);
if ((a>=18)&&(a<=25)){
printf("You are eligible for our institute
scholarship program");
}
return 0;
}

2. What is the user's choice? If they select option


1, add 2 no; if they select option 2, subtract 2
no; if they select option 3, multiply 2 no. else
invalid option.

#include <stdio.h>
int main()
{
printf("Enter the user choice(1,2,3):-");
int g;
scanf("%d", &g);
printf("Enter the two number:-");
float t, m;
scanf("%f%f", &t, &m);
if (g == 1)
{
printf("The addition of two number %f and %f is
%f", t, m, t + m);
}
else if (g == 3)
{
printf("The mulitplication of the two number %f and
%f is %f", t, m, t
* m);
}
else if (g == 2)
{
printf("The subtraction the two number %f and %f is
%f", t, m, t -m);
}
else
{
printf("Invalid option");
}
return 0;
}

3.What is the user's login credentials? If the


username is 1234 and password is same as
username, if its match, grant access; otherwise,
display an error message.

#include <stdio.h>
int main()
{
printf("Enter the username:- ");
int u;
scanf("%d",&g);
printf("\nEnter the password:- ");
int h;
scanf("%d",&h);
if (g==h){
printf("Matched access granted");
}
else{
printf("Wrong password ");
}
return 0;
}

4. What is the user's score on the test? If it's


above 90%, congratulate them; if it's below 60%,
encourage them to study harder.

#include <stdio.h>
int main()
{
printf("Enter the score in the test:- ");
float g;
scanf("%f",&g);
if (g>90){
printf("Congrats for this score");
}
else if (g<60){
printf("You need work even more harder");
}
return 0;
}

5. Take user's input as a radius? If it's a


positive number, calculate its area of circle; if
it's a
negative number, display an message its negative
value.

#include <stdio.h>
int main()
{
printf("Enter the radius of the circle :- ");
float g;
scanf("%f", &g);
if (g > 0)
{
printf("Area of the circle having radius %f is %f",
g, 3.14 * g * g);
}
else
{
printf("Oops its a negative value");
}
return 0;
}

6. What is the user's credit score? If it's above


700, approve their loan application; if it's below
600, reject their loan application; if it's between
600 and 700, require further information.

#include <stdio.h>
int main()
{
printf("Enter your credit score :- ");
float g;
scanf("%f", &g);
if (g > 700)
{
printf("Hurry your loan application is approved");
}
else if ((g>600)&&(g<700))
{
printf("We need more information");
}
else if (g<600){
printf("Sorry your loan application is rejected");
}
return 0;
}

7. What is the user's age? If they are under 13,


prompt them to ask their parents for permission
before proceeding; if they are 13 or older, grant
them access.

#include <stdio.h>
int main()
{
printf("Enter your age:- ");
int g;
scanf("%d", &g);
if (g <13)
{
printf("You need permission from your parent before
proceeding");
}
else if (g>13)
{
printf("Accesss granted");
}
return 0;
}

8. A shop will give discount of 10% if the cost of


purchased quantity is more than 1000. Ask
user for quantity Suppose, one unit will cost 100.
Judge and print total cost for user.

#include <stdio.h>
int main()
{
printf("Enter number of item you purchase:- ");
int g;
scanf("%d", &g);
int price = g * 100;
int t = (price * 0.1);
if (price > 1000)
{
printf("Congratulations you get discount \n your
final price is %d ",
(price - t));
}
return 0;
}

9. A company decided to give bonus of 5% to


employee if his/her year of service is more than 5
years. Ask user for their salary and year of
service and print the net bonus amount.

#include <stdio.h>
int main()
{
printf("Enter your salary:- ");
int g;
scanf("%d", &g);
printf("Enter the year of service:- ");
int f;
scanf("%d",&f);
float bonus = g * 0.05;
if (f>5)
{
printf("Your net bonus is %f", bonus);
}
return 0;
}

10. Take input of age of 3 people by user and


determine oldest and youngest them.

#include <stdio.h>
int main()
{
printf("Enter the age of the three people :- ");
int g,h,j;
scanf("%d%d%d", &g,&h,&j);
if ((g>h)&&(g>j))
{
printf("The age of the first is max");
}
else if ((h>g)&&(h>j))
{
printf("The age of the second is max");
}
else if ((j>g)&&(j>g))
{
printf("The age of the third is max");
}
return 0;
}

11. A student will not be allowed to sit in exam if


his/her attendance is less than 75%. Take
following input from user
Number of classes held
Number of classes attended.
And print
percentage of class attended
Is student is allowed to sit in exam or not.
#include <stdio.h>
int main()
{
printf("Number of classes held:- ");
float f;
scanf("%f",&f);
printf("Number of classes attend:-");
float h;
scanf("%f",&h);
float q;
q=h/f*100;
printf("Percentage of class attend is %f\n",q);
if (q>75)
{
printf("You are allowed to sit in the exam");
}
else {
printf("You are not allowed to sit in the exam");
}
return 0;
}

12.
If
x = 2;
y = 5;
z = 0;
then find values of the following expressions:

a)true
b)true
c)true
d)True
e)Flase

You might also like