Learn C With Me Beginners C Tutorial If Statement

July 19th, 2012 | No Comments | Posted in Programming

//w.a.p to take quantity and price per item and if quantity is greater than 1000 then 10% discount will be gievn.

#include
#include
void main()
{

int qnt,dis=10;
float rate,total=0;
printf(“Enter Quantity:”);
scanf(“%d”,&qnt);
printf(“Enter rate”);
scanf(“%f”,&rate);
if(qnt>1000)
{
printf(“Total Rate Is :%f”,total=((qnt*rate)-(qnt*rate*dis/100)));
}
else
{
printf(“Quantity is less than 1000″);
}

getch();
}
/*w.a.p to take current year and joining year of an employee in a organization.
if service year is greater than 3 then the employee will get Rs.2500/- bonus and
service year is less than no bonus.*/

#include
#include
void main()
{
int cy,jy,ty,bonus=2500;
clrscr();
printf(“Enter Your Current Year:”);
scanf(“%d”,&cy);
printf(“Enter Youe Joining Year:”);
scanf(“%d”,&jy);
ty=cy-jy;
if(ty>3)
{
printf(“Bonus=%d”,bonus);
}
else
{
printf(“Current Year is less than 3 year”);
}
getch();
}
/*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 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.
his gross salary.*/

#include
#include
void main()
{
float sal,hra=0,da=0,grosssal=0;
clrscr();
printf(“Enter Salary:”);
scanf(“%f”,&sal);
if(sal {
hra=sal*10/100;
da=sal*90/100;
}
else
{
hra=500;
da=sal*98/100;
}
grosssal=grosssal+hra+da;
printf("Gross Salary is %f",grosssal);
getch();

}
/*The marks obtained by a studentin 5 different subjects are input through the keyboard.The student
gets a division as per the following rules:
percentage above or equal to 60-1st division
percentage between 50 and 59-2nd division
percentage between 40 and 49-3rd division
percentage less than 40-Fail*/

#include
#include
void main()
{
int sub1,sub2,sub3,sub4,sub5;
int tol=0,per=0;
clrscr();
printf(“Enter marks of 1st subject:”);
scanf(“%d”,&sub1);
printf(“Enter marks of 2nd subject:”);
scanf(“%d”,&sub2);
printf(“Enter marks of 3rd subject:”);
scanf(“%d”,&sub3);
printf(“Enter marks of 4th subject:”);
scanf(“%d”,&sub4);
printf(“Enter marks of 5th subject:”);
scanf(“%d”,&sub5);

tol=(sub1+sub2+sub3+sub4+sub5);
per=tol/5;

if (per>=60)
{
printf(“1st Division”);
}
else if (per>=50)
{
printf(“2nd Division”);
}
else if (per>=40)
{
printf(“3rd Division”);
}
else
{
printf(“Fail”);
}
getch();

}
//w.a.p to take two numbers and check both numbers are equal or not if not then find which number is greater//

#include
#include
void main()
{
float num1,num2;
clrscr();
printf(“Enter 1st Number:”);
scanf(“%f”,&num1);
printf(“Enter 2nd Number:”);
scanf(“%f”,&num2);
if(num1==num2)
{
printf(“Both numbers are equal”);
}
else if(num1>num2)
{
printf(“%f is greater number”,num1);
}
else
{
printf(“%f is greater number”,num2);
}
getch();
}

Leave a Reply 75 views, 1 so far today |

Most Commented Posts

Leave a Reply

CAPTCHA Image
Refresh Image
*