Chapter 2: The Decision control Structure (Let Us C)
(a) 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.
(c) Any year is input through the keyboard. Write a program to determine whether the year is a leap year or not. (Hint: Use the % (modulus) operator)
(e) 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.
(f) If the ages of Ram, Shyam and Ajay are input through the keyboard, write a program to determine the youngest of the three.
(g) 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.
(i) 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.
(j) Given three points (x1, y1), (x2, y2) and (x3, y3), write a program to check if all the three points fall on one straight line.
(k) Given the coordinates (x, y) of a center of a circle and it's radius, write a program which will determine whether a point lies inside the circle, on the circle or outside the circle.
(Hint: Use sqrt( ) and pow( ) functions)
(l) Given a point (x, y), write a program to find out if it lies on the x-axis, y-axis or at the origin, viz. (0, 0)
(m) Any year is entered through the keyboard, write a program to determine whether the year is leap or not. Use the logical operators && and ||
(n) Any character is entered through the keyboard, write a program to determine whether the character entered is a capital letter, a small case letter, a digit or a special symbol.
(o) An Insurance company follows following rules to calculate premium.
(i) If a person’s health is excellent and the person is between 25 and 35 years of age and lives in a city and is a male then the premium is Rs. 4 per thousand and his policy amount cannot exceed Rs. 2 lakhs.
(ii) If a person satisfies all the above conditions except that the sex is female then the premium is Rs. 3 per thousand and her policy amount cannot exceed Rs. 1 lakh.
(iii) If a person’s health is poor and the person is between 25 and 35 years of age and lives in a village and is a male then the premium is Rs. 6 per thousand and his policy cannot exceed Rs. 10,000.
(iv) In all other cases the person is not insured.
Write a program to output whether the person should be insured or not, his/her premium rate and maximum amount for which he/she can be insured.
(p) 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) are met
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.
(q) A library charges a fine for every book returned late. For 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.
(s) If the three sides of a triangle are entered through the keyboard, write a program to check whether the triangle is isosceles, equilateral, scalene or right angled triangle.
(t) 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.
(u) A university has the following rules for a student to qualify for a degree with A as the main subject and B as the subsidiary subject:
(i) He should get 55 percent or more in A and 45 percent or more in B.
(ii) If he gets less than 55 percent in A he should get 55 percent or more in B. However, he should get at least 45 percent in A.
(iii) If he gets less than 45 percent in B and 65 percent or more in A he is allowed to reappear in an examination in B to qualify.
(iv) In all other cases he is declared to have failed. Write a program to receive marks in A and B and Output whether the student has passed, failed or is allowed to reappear in B.
(v) The policy followed by a company to process customer orders is given by the following rules:
(i) If a customer order is less than or equal to that in stock and has credit is OK, supply has requirement.
(ii) If has credit is not OK do not supply. Send him intimation.
(iii) If has credit is Ok but the item in stock is less than has order, supply what is in stock. Intimate to him data the balance will be shipped.
Write a C program to implement the company policy.
// Let Us C (Chapter 2 : The Decision control Structure) : Program-1
/* 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 */
#include<stdio.h>
double C,S,P,L;
void main()
{
clrscr();
printf("Enter cost price of an item: ");
scanf("%lf",&C);
printf("Enter Selling price of the same: ");
scanf("%lf",&S);
if(S>C)
{
P=S-C;
printf("Seller made profit of Rs. %0.2lf",P);
}
else if(C>S)
{
L=C-S;
printf("Seller incurred loss of Rs. %0.2lf",L);
}
else if(S==C)
printf("Seller made no loss no profit");
}
(b) Any integer is input through the keyboard. Write a program to find out whether it is an odd number or even number.// Let Us C (Chapter 2 : The Decision control Structure) : Program-2
/* Any integer is input through the keyboard. Write a program to find out whether it is an odd number or even number */
#include<stdio.h>
long num;
void main()
{
clrscr();
printf("Enter any integer: ");
scanf("%ld",&num);
/* With modulus operator */
if(num%2 == 0)
{
printf("\n%ld is EVEN",num);
}
else
printf("\n%ld is ODD",num);
/* Without modulus operator : method 1 */
if((num/2)*2 == num)
{
printf("\n%ld is EVEN",num);
}
else
printf("\n%ld is ODD",num);
/* Without modulus operator : method 2 */
if(num&1 == 1) // If last bit is 0, it is even number
{
printf("\n%ld is ODD",num);
}
else
printf("\n%ld is EVEN",num);
}
// Let Us C (Chapter 2 : The Decision control Structure) : Program-3
/* Any year is input through the keyboard. Write a program to determine whether the year is a leap year or not.
(Hint: Use the % (modulus) operator) */
#include<stdio.h>
unsigned int YEAR;
void main()
{
clrscr();
printf("Enter any year: ");
scanf("%d",&YEAR);
if((YEAR%4==0)&&(YEAR%100 != 0)||(YEAR%400 == 0))
printf("%d is a Leap year",YEAR);
else
printf("%d is NOT a Leap year",YEAR);
}
(d) According to the Gregorian calendar, it was Monday on the date 01/01/1900. If any year is input through the keyboard write a program to find out what is the day on 1st January of this year.// Let Us C (Chapter 2 : The Decision control Structure) : Program-4
/* According to the Gregorian calendar, it was Monday on the date 01/01/1900. If any year is input through the
keyboard write a program to find out what is the day on 1st January of this year */
#include<stdio.h>
void main()
{
int year,odd_day,a,b,c;
clrscr();
printf("\nEnter Year: ");
scanf("%d",&year);
/* using Zeller's congreunce to find 1st day of the year*/
a = (year-1.0)/4.0;
b = (year-1.0)/100.0;
c = (year-1.0)/400.0;
odd_day = (year+a-b+c)%7;
switch(odd_day)
{
case 0: printf("1st Jan %d is Sunday",year);
break;
case 1: printf("1st Jan %d is Monday",year);
break;
case 2: printf("1st Jan %d is Tuesday",year);
break;
case 3: printf("1st Jan %d is Wednesday",year);
break;
case 4: printf("1st Jan %d is Thursday",year);
break;
case 5: printf("1st Jan %d is Friday",year);
break;
case 6: printf("1st Jan %d is Saturday",year);
break;
default: break;
}
}
// Let Us C (Chapter 2 : The Decision control Structure) : Program-5
/* 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 */
#include<stdio.h>
long num,rem,sum=0,temp;
void main()
{
clrscr();
printf("\nEnter a 5 digit Number:");
scanf("%ld",&num);
temp=num;
while(temp)
{
rem=temp%10;
sum=sum*10+rem;
temp=temp/10;
}
printf("\n Reverse of %ld is %ld",num,sum);
if(num==sum)
printf("\n Both are equal");
else
printf("\n Both are unequal");
}
// Let Us C (Chapter 2 : The Decision control Structure) : Program-6
/* If the ages of Ram, Shyam and Ajay are input through the keyboard, write a program to determine the youngest of the three */
#include<stdio.h>
int R,S,A;
void main()
{
clrscr();
printf("Enter age of Ram: ");
scanf("%d",&R);
printf("Enter age of Shyam: ");
scanf("%d",&S);
printf("Enter age of Ajay: ");
scanf("%d",&A);
if(R==S && S==A)
printf("\nAll have same age");
else
R<S?(R<A?printf("\nRam is Youngest"):printf("\nAjay is Youngest")):(S<A?printf("\nShyam is Youngest"):printf("\nAjay is Youngest"));
}
// Let Us C (Chapter 2 : The Decision control Structure) : Program-7
/* 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 */
#include<stdio.h>
float A,B,C,SUM;
void main()
{
clrscr();
printf("Enter 3 angles of triangle: ");
scanf("%f%f%f",&A,&B,&C);
SUM=A+B+C;
if(SUM==180)
printf("\nTriangle is valid");
else
printf("\nTriangle is NOT valid");
}
(h) Find the absolute value of a number entered through the keyboard.// Let Us C (Chapter 2 : The Decision control Structure) : Program-8
/* Find the absolute value of a number entered through the keyboard */
#include<stdio.h>
float num,abs;
void main()
{
clrscr();
printf("Enter a no. to find it absolute value: ");
scnaf("%f",&num);
if(num<0)
abs = num*(-1); // Absolute value is distance of that number from 0
else
abs = num;
printf("Absolute value of %f if %f",num,abs);
}
(i) 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.
// Let Us C (Chapter 2 : The Decision control Structure) : Program-9
/* 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 */
#include<stdio.h>
float L,B,A,P;
void main()
{
clrscr();
printf("Enter LENGTH of rectangle: ");
scanf("%f",&L);
printf("Enter BREADTH of rectangle: ");
scanf("%f",&B);
A=L*B;
P=2*(L+B);
printf("Area = %f, Perimeter = %f",A,P);
if(A>P)
printf("\nArea of rectangle is greater than Perimeter");
else if(A<P)
printf("\nArea of rectangle is smaller than Perimeter");
else if(A==P)
printf("\nArea of rectangle = Perimeter");
}
(j) Given three points (x1, y1), (x2, y2) and (x3, y3), write a program to check if all the three points fall on one straight line.
// Let Us C (Chapter 2 : The Decision control Structure) : Program-10
/* Given three points (x1, y1), (x2, y2) and (x3, y3), write a program to check if all the three points fall on one straight line */
#include<stdio.h>
unsigned int x1,x2,x3,y1,y2,y3,slope1,slope2;
void main()
{
clrscr();
printf("\nEnter co-ordinates of 3 points:");
scanf("%d%d%d%d%d%d",&x1,&y1,&x2,&y2,&x3,&y3);
slope1=((y2-y1)/(x2-x1)); // Slope of 1st line
slope2=((y3-y1)/(x3-x1)); // Slope of 2nd line
if(slope2==slope1)
printf("\nNumbers are on one straight line.");
else
printf("\nNumbers are not on one straight line.");
}
(Hint: Use sqrt( ) and pow( ) functions)
// Let Us C (Chapter 2 : The Decision control Structure) : Program-11
/* Given the coordinates (x, y) of a center of a circle and it's radius, write a program which will determine
whether a point lies inside the circle, on the circle or outside the circle
(Hint: Use sqrt( ) and pow( ) functions) */
#include<stdio.h>
#include<math.h> // Header file for maths functions (sqrt & pow in this program)
unsigned int x,y,rad,a,b,dist;
void main()
{
clrscr();
printf("Enter co-ordinates of center of circle: ");
scanf("%d%d",&x,&y);
printf("\nEnter radius of circle: ");
scanf("%d",&rad);
printf("\nEnter co-ordinates of a point: ");
scanf("%d%d",&a,&b);
dist=sqrt(pow((a-x),2)+pow((b-y),2)); // Distance b/w center & point
if(dist<rad)
printf("Point (%d,%d) lies inside the circle",a,b);
else if(dist==rad)
printf("Point (%d,%d) lies on the circle",a,b);
else
printf("Point (%d,%d) lies outside the circle",a,b);
}
(l) Given a point (x, y), write a program to find out if it lies on the x-axis, y-axis or at the origin, viz. (0, 0)
// Let Us C (Chapter 2 : The Decision control Structure) : Program-12
/* Given a point (x, y), write a program to find out if it lies on the x-axis, y-axis or at the origin, viz. (0, 0) */
#include<stdio.h>
float X,Y;
void main()
{
clrscr();
printf("Enter X & Y co-ordinates of a point: ");
scanf("%f%f",&X,&Y);
if(X==0 && Y==0)
printf("Point lies on Origin");
else if(X==0 && (Y>0 || Y<0))
printf("Point lies on Y-Axis");
else if(Y==0 && (X>0 || X<0))
printf("Point lies on X-Axis");
else if(X>0 && Y>0)
printf("Point lies in 1st quadrant");
else if(X>0 && Y<0)
printf("Point lies in 4th quadrant");
else if(X<0 && Y>0)
printf("Point lies in 2nd quadrant");
else if(X<0 && Y<0)
printf("Point lies in 3rd quadrant");
}
// Let Us C (Chapter 2 : The Decision control Structure) : Program-13
/* Any year is entered through the keyboard, write a program to determine whether the year is leap or not.
Use the logical operators && and || */
#include<stdio.h>
unsigned int YEAR,
void main()
{
clrscr();
printf("Enter any year: ");
scanf("%d",YEAR);
if((YEAR%400 == 0)||((YEAR%4==0)&&(YEAR%100 != 0)))
printf("%d is Leap year",YEAR);
else
printf("%d is NOT a Leap year",YEAR);
}
// Let Us C (Chapter 2 : The Decision control Structure) : Program-14
/* Any character is entered through the keyboard, write a program to determine whether the character entered is
a capital letter, a small case letter, a digit or a special symbol */
#include<stdio.h>
char ch;
void main()
{
clrscr();
printf("Enter any character : ");
scanf("%c",&ch);
if((ch>64)&&(ch<91))
printf("\nCharacter is a CAPITAL LETTER");
else if((ch>96)&&(ch<123))
printf("\nCharacter is a SMALL LETTER");
else if((ch>47)&&(ch<58))
printf("\nCharacter is a NUMBER");
else if((ch>0 && ch<48)||(ch>57 && ch<65)||(ch>90 && ch<97)||(ch>122 && ch<128))
printf("\nCharacter is SPECIAL SYMBOL");
}
(i) If a person’s health is excellent and the person is between 25 and 35 years of age and lives in a city and is a male then the premium is Rs. 4 per thousand and his policy amount cannot exceed Rs. 2 lakhs.
(ii) If a person satisfies all the above conditions except that the sex is female then the premium is Rs. 3 per thousand and her policy amount cannot exceed Rs. 1 lakh.
(iii) If a person’s health is poor and the person is between 25 and 35 years of age and lives in a village and is a male then the premium is Rs. 6 per thousand and his policy cannot exceed Rs. 10,000.
(iv) In all other cases the person is not insured.
Write a program to output whether the person should be insured or not, his/her premium rate and maximum amount for which he/she can be insured.
// Let Us C (Chapter 2 : The Decision control Structure) : Program-15
/* An Insurance company follows following rules to calculate premium.
(i) If a person’s health is excellent and the person is between 25 and 35 years of age and lives in a city and is a male then the premium is Rs. 4 per
thousand and his policy amount cannot exceed Rs. 2 lakhs.
(ii) If a person satisfies all the above conditions except that the sex is female then the premium is Rs. 3 per thousand and her policy amount cannot exceed Rs. 1 lakh.
(iii) If a person’s health is poor and the person is between 25 and 35 years of age and lives in a village and
is a male then the premium is Rs. 6 per thousand and his policy cannot exceed Rs. 10,000.
(iv) In all other cases the person is not insured.
Write a program to output whether the person should be insured or not, his/her
premium rate and maximum amount for which he/she can be insured. */
#include<stdio.h>
char HEALTH,LOC,GENDER;
float AGE;
void main()
{
clrscr();
printf("Welcome to XYZ Insurance Co.");
printf("\nPlease select appropriate options");
printf("\nHow is health of person(P=Poor,E=Excellant): ");
scanf("%c",&HEALTH);
printf("\nWhat is his/her age: ");
scanf("%f",&AGE);
printf("\nWhere does he/she lives(C=City,V=village):");
scanf("%c",&LOC);
printf("\nEnter gender(M=Male,F=Female):");
scanf("%c",&GENDER);
if((HEALTH=='E'||HEALTH=='e')&&(AGE>=25 && AGE<=35)&&(LOC=='C' || LOC=='c')&&(GENDER=='M' || GENDER=='m'))
printf("\nPremium = Rs.4 per 1000 & Max insurance is Rs. 2 Lakhs");
else if((HEALTH=='E'||HEALTH=='e')&&(AGE>=25 && AGE<=35)&&(LOC=='C' || LOC=='c')&&(GENDER=='M' || GENDER=='m'))
printf("\nPremium = Rs.3 per 1000 & Max insurance is Rs. 1Lakh");
else if((HEALTH=='P'||HEALTH=='p')&&(AGE>=25 && AGE<=35)&&(LOC=='V' || LOC=='v')&&(GENDER=='M' || GENDER=='m'))
printf("\nPremium = Rs.6 per 1000 & Max insurance is Rs. 10,000");
else
printf("\nPerson can not be insured");
}
(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) are met
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.
// Let Us C (Chapter 2 : The Decision control Structure) : Program-16
/* 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) are met
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 */
#include<stdio.h>
float H,C,T;
void main()
{
clrscr();
printf("Enter following data for steel:\n");
printf("Hardness: ");
scanf("%f",&H);
printf("Carbon content: ");
scanf("%f",&C);
printf("Tensile strength: ");
scanf("%f",&T);
if(H>50 && C<0.7 && T>5600) // Condition 1
printf("\nSteel has grade 10");
else if(H>50 && C<0.7 && T<=5600) // Condition 2
printf("\nSteel has grade 9");
else if(H<50 && C<0.7 && T>5600) // Condition 3
printf("\nSteel has grade 8");
else if(H>50 && C>0.7 && T>5600) // Condition 4
printf("\nSteel has grade 7");
else if(H>50 || C<0.7 || T>5600) // Condition 5
printf("\nSteel has grade 6");
else // Condition 6
printf("\nSteel has grade 5");
}
// Let Us C (Chapter 2 : The Decision control Structure) : Program-17
/* A library charges a fine for every book returned late. For 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 */
#include<stdio.h>
int D;
void main()
{
clrscr();
printf("Enter no. of late days for returning book: ");
scanf("%d",D);
if(D<=5)
printf("\nFine is 50 paise");
if(D>5&&D<=10)
printf("\nFine is 1 Rupee");
if(D>10 && D<=30)
printf("\nFine is 5 Rupees");
if(D>30)
printf("\nYour membership cancelled");
}
(r) If the three sides of a triangle are entered through the keyboard, write a program to check whether the triangle is valid or not. The triangle is valid if the sum of two sides is greater than the largest of the three sides.
// Let Us C (Chapter 2 : The Decision control Structure) : Program-18
/* If the three sides of a triangle are entered through the keyboard, write a program to check whether the triangle
is valid or not. The triangle is valid if the sum of two sides is greater than the largest of the three sides */
/******************** 1 ********************/
#include<stdio.h>
int A,B,C;
void main()
{
clrscr();
printf("Enter 3 sides of triangle: ");
scanf("%d%d%d",&A,&B,&C);
if((A+B>C) && (A+C>B) && (B+C>A))
printf("\nTriangle is Valid");
else
printf("\nTriangle is Invalid");
}
/******************** 2 ********************/
#include<stdio.h>
int A,B,C,Largest;
void main()
{
clrscr();
printf("Enter 3 sides of triangle: ");
scanf("%d%d%d",&A,&B,&C);
Largest=0;
(A>B)?(A>C?(Largest=A):(Largest=C)):(B>C?(Largest=B):(Largest=C));
printf("Largest = %f\n",Largest);
if(Largest==A)
{
if(A>(B+C))
printf("\nTriangle is Valid");
else
printf("\nTriangle is In-valid");
}
else if(Largest==B)
{
if(B>(A+C))
printf("\nTriangle is Valid");
else
printf("\nTriangle is In-valid");
}
else if(Largest==C)
{
if(C>(A+B))
printf("\nTriangle is Valid");
else
printf("\nTriangle is In-valid");
}
}
// Let Us C (Chapter 2 : The Decision control Structure) : Program-19
/* If the three sides of a triangle are entered through the keyboard, write a program to check whether the
triangle is isosceles, equilateral, scalene or right angled triangle */
#include<stdio.h>
int A,B,C;
void main()
{
clrscr();
printf("Enter 3 sides of triangle: ");
scanf("%d%d%d",&A,&B,&C);
if((A+B>C) && (A+C>B) && (B+C>A))
{
if(A==B && B==C)
printf("\nTriagnle is Equilateral");
else if(A==B || B==C || A==C)
printf("\nTriagnle is Isoscele");
else
printf("\nTriagnle is Scalene");
if((A*A==(B*B+C*C))||(B*B==(A*A+C*C))||(C*C==(A*A+B*B)))
printf("\nTriagnle is Right Angled");
}
else
printf("\nTriangle is Invalid");
}
// Let Us C (Chapter 2 : The Decision control Structure) : Program-20
/* 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 */
#include<stdio.h>
float T;
void main()
{
clrscr();
printf("Enter time taken by worker to complete the job(in hrs): ");
scanf("%f",&T);
if(T>=2 && T<=3)
printf("\nWorker is Highly efficient");
if(T>3 && T<=4)
printf("\nWorker need to improve speed");
if(T>4 && T<=5)
printf("\nWorker need training to improve speed");
if(T>5)
printf("\nWorker is Highly inefficient & need to leave the company");
}
(i) He should get 55 percent or more in A and 45 percent or more in B.
(ii) If he gets less than 55 percent in A he should get 55 percent or more in B. However, he should get at least 45 percent in A.
(iii) If he gets less than 45 percent in B and 65 percent or more in A he is allowed to reappear in an examination in B to qualify.
(iv) In all other cases he is declared to have failed. Write a program to receive marks in A and B and Output whether the student has passed, failed or is allowed to reappear in B.
// Let Us C (Chapter 2 : The Decision control Structure) : Program-21
/* A university has the following rules for a student to qualify for a degree with A as the main subject and B
as the subsidiary subject:
(i) He should get 55 percent or more in A and 45 percent or more in B.
(ii) If he gets less than 55 percent in A he should get 55 percent or more in B. However, he should get at least
45 percent in A.
(iii) If he gets less than 45 percent in B and 65 percent or more in A he is allowed to
reappear in an examination in B to qualify.
(iv) In all other cases he is declared to have failed. Write a
program to receive marks in A and B and Output whether the student has passed, failed or is allowed to reappear in B */
#include<stdio.h>
void main()
{
clrscr();
printf("Enter percentage marks obtained in Sub A: ");
scanf("%f",&A);
printf("Enter percentage marks obtained in Sub B: ");
scanf("%f",&B);
if((A>=55 && B>=45) || (A>45 && A<55 && B>=55))
printf("\nQualified for the degree");
else if(A>=65 && B<45)
printf("\nReappear in subject B to qualify for degree");
else
printf("\nFailed");
}
(i) If a customer order is less than or equal to that in stock and has credit is OK, supply has requirement.
(ii) If has credit is not OK do not supply. Send him intimation.
(iii) If has credit is Ok but the item in stock is less than has order, supply what is in stock. Intimate to him data the balance will be shipped.
Write a C program to implement the company policy.
// Let Us C (Chapter 2 : The Decision control Structure) : Program-22
/* The policy followed by a company to process customer orders is given by the following rules:
(i) If a customer order is less than or equal to that in stock and has credit is OK, supply has requirement.
(ii) If has credit is not OK do not supply. Send him intimation.
(iii) If has credit is Ok but the item in stock is less than has order, supply what is in stock.
Intimate to him data the balance will be shipped.
Write a C program to implement the company policy */
#include<stdio.h>
#define STOCK 200
float Order;
char Credit;
void main()
{
clrscr();
printf("Enter order qty: ");
scanf("%f",&Order);
printf("Is credit OK(Y/N): ");
scanf("%c",&Credit);
if(Order<=STOCK && (Credit=='y'||Credit=='Y'))
printf("Supply %f qty",Order);
else if(Order<=STOCK && (Credit=='n'||Credit=='N'))
printf("Credit not sufficient, please clear previous balance");
else if(Order>STOCK && (Credit=='Y'||Credit=='y'))
printf("Supply %f qty; %f will be shipped in next week",STOCK,(Order-STOCK));
// else if(Order>STOCK && (Credit=='N'||Credit=='n'))
// printf("Credit not sufficient, please clear previous balance");
}
good work
ReplyDeletever nice
ReplyDelete