The if statement is a simple decision-making and branching statement and it is used to control the flow of the program execution. An if statement consists of a Boolean expression followed by one or more statements. The if statement is written with the if keyword, followed by a condition in parentheses, with the code to be executed in between curly brackets.
Syntax:
if( condition )
{
// body of the statements will execute if the condition is true ;
}
The code is a C program that demonstrates the use of the if statement in C. Here is an explanation of each line of the code:
//if statement #include<stdio.h> int main() { char name[10]; int age; printf("\nEnter Your Name : "); scanf("%s",name); printf("\nEnter The Age : "); scanf("%d",&age); if(age>=18) { printf("\n %s age is %d Eligible For Vote",name,age); } return 0; }To download raw file Click Here
Enter Your Name : Siva Enter The Age : 21 Siva age is 21 Eligible For Vote
1.while purchasing certain items, a discount of 10% is offered if the quantity purchased is more than 1000. If quantity and price per item are input through the keyboard, write a program to calculate the total expenses.
2. The current year and the year in which the employee joined the organization are entered through the keyboard. If the number of years for which the employee has served the organization is greater than 3 then a bonus of Rs. 2500/- is given to the employee. If the years of service are not greater than 3, then the program should do nothing.
3. If his basic salary is less than Rs. 1500, then HRA = 10% of basic salary and DA = 90% of basic salary. If his salary is either equal to or above Rs. 1500, then HRA = Rs. 500 and DA = 98% of basic salary. If the employee's salary is input through the keyboard write a program to find his gross salary
4. The marks obtained by a student in 5 different subjects are input through the keyboard. The student gets a division as per the following rules: Write a program to calculate the division obtained by the student.
5. A company insures its drivers in the following cases:
6.Write a program to calculate the salary as per the following table
| Gender | Years of Service | Qualifications | Salary |
|---|---|---|---|
| Male | >= 10 | Post-Graduate | 15000 |
| Male | >= 10 | Graduate | 10000 |
| Male | < 10 | Post-Graduate | 10000 |
| Male | < 10 | Graduate | 7000 |
| Female | >= 10 | Post-Graduate | 12000 |
| Female | >= 10 | Graduate | 9000 |
| Female | < 10 | Post-Graduate | 10000 |
| Female | < 10 | Graduate | 6000 |
7.If cost price and selling price of an item is input through the keyboard, write a program to determine whether the seller has made profit or incurred loss. Also determine how much profit he made or loss he incurred.
8.Any integer is input through the keyboard. Write a program to find out whether it is an odd number or even number. (Hint: Use the % (modulus) operator)
9.A five-digit number is entered through the keyboard. Write a program to obtain the reversed number and to determine whether the original and reversed numbers are equal or not.
10.If the ages of Ram, Shyam and Ajay are input through the keyboard, write a program to determine the youngest of the three.
11.Write a program to check whether a triangle is valid or not, when the three angles of the triangle are entered through the keyboard. A triangle is valid if the sum of all the three angles is equal to 180 degrees.
12.Find the absolute value of a number entered through the keyboard.
13.Given the length and breadth of a rectangle, write a program to find whether the area of the rectangle is greater than its perimeter. For example, the area of the rectangle with length = 5 and breadth = 4 is greater than its perimeter
14.Any year is entered through the keyboard, write a program to determine whether the year is leap or not. Use the logical operators && and ||.
15.A certain grade of steel is graded according to the following conditions:
A certain grade of steel is graded according to the following conditions:
(i) Hardness must be greater than 50
(ii) Carbon content must be less than 0.7
(iii) Tensile strength must be greater than 5600
The grades are as follows:
Grade is 10 if all three conditions are met
Grade is 9 if conditions (i) and (ii) are met
Grade is 8 if conditions (ii) and (iii)
Grade is 7 if conditions (i) and (iii) are met
Grade is 6 if only one condition is met
Grade is 5 if none of the conditions are met
Write a program, which will require the user to give values of hardness, carbon content
and tensile strength of the steel under consideration and output the grade of the steel.
16. A library charges a fine for every book returned late. For the first 5 days the fine is 50 paise, for 6-10 days fine is one rupee and above 10 days fine is 5 rupees. If you return the book after 30 days your membership will be cancelled. Write a program to accept the number of days the member is late to return the book and display the fine or the appropriate message.
17.In a company, worker efficiency is determined on the basis of the time required for a worker to complete a particular job. If the time taken by the worker is between 2 – 3 hours, then the worker is said to be highly efficient. If the time required by the worker is between 3 – 4 hours, then the worker is ordered to improve speed. If the time taken is between 4 – 5 hours, the worker is given training to improve his speed, and if the time taken by the worker is more than 5 hours, then the worker has to leave the company. If the time taken by the worker is input through the keyboard, find the efficiency of the worker.
Learn All in Tamil © Designed & Developed By Tutor Joes | Privacy Policy | Terms & Conditions