Sie sind auf Seite 1von 23

MACHINE PROBLEMS

3.1 Make a C program that will accept any integer from 1-12 and displays equivalent month,
example if 3, “March”.

3.2 Create a program in C that input hours and display if the employee has overtime hours if it
exceeds 40 hours.

3.3 Construct a C program that will enter three integers and display the highest value,
assuming all inputs are different.

3.4 Any customer whose total PURCHASE is at least P1000 will be given a 10% discount.
Make a C program that would input the customer’s purchase and output his net BILL.

3.5 A driver will be fined P500 if his SPEED goes beyond 80 kph, and P800 if it goes beyond
100 kph. Design a program that will input the car’s speed and output the fine.

3.6 Every leap year is divisible by 4. Write a program that will input YEAR and display whether
the year is “LEAP YEAR” or “ORDINARY YEAR”.

3.7 A student GRADE may be calculated based on his SCORE. Construct a program that
will input score and display its equivalent grade.

Score Grade

Below 60: F

At least 60 but below 70: D

At least 70 but below 80: C

At least 80 but below 90: B

At least 90: A

3.8 Design a C program that will input two integers and a code [A, B, C, D]. Display the sum if
the code entered is “A”, difference if “B”, product if “C” and quotient if “D”.

3.9 Create a program in C language that will input any integer from 1 to 100 and display the
equivalent value in words. Use a shortcut way to minimize the code for this problem.

3.10 Design a program that will accept three positive values that will represent angles of a
triangle and print the classification of the triangle. If one angle measures exactly 90 degrees you
have right triangle; if the two angles are equal the triangle is classified as isosceles triangle; if all
angles are equal the triangle is known as equilateral/equiangular triangle; otherwise the
triangle is a scalene triangle. Assume that the following angles must be positive and the total
angles must be 180 degrees.
3.11 Design a program that will enter any Hindu Arabic numbers from 1 to 1000 and display the
equivalent value in Roman Numerals.

3.12 Ding Dong is a computer programmer for the state transportation department. His first
assignment is to computerize the process of automobile drive licensing. He decides that the first
thing the computer should do is to look at the applicant’s age determine what of license can be
possibly issued.

Here is what Ding Dong is thinking:

a. If the applicant’s age is less than 18, then the computer should print: “UNDERAGE”
b. If the applicant is 18, then the computer should print: “STUDENT LICENSE POSSIBLE”
c. If the applicant is older than 18, then the computer should print: “PROFESSIONAL
LICENSE POSSIBLE”

Before the license is released the applicant need to pass the drug test examination. If the
drug test result is positive, display “HOLD LICENSE” otherwise display “RELEASE
LICENSE”.

3.13 The 1988 United States Federal Estimated Tax Schedule is the simplest in recent
times. It has 4 categories, single, head of the family, married (joint) & married (separated).
Create a C program that will input the category code, number of dependents and the taxable
income and then calculate the tax.

Category Category Code Tax


Single W 12.5% of first $17,850 plus
10% of excess
Head of the Family X 12.5% of first $23,900 plus
10% of excess
Married (Joint) Y 12.5% of first $29,750 plus
10% of excess
Married (Separated) Z 12.5% of first $14,875 plus
10% of excess

Number of dependent Additional Exemption


1 $1,500
2 $2,300
3 $3,100
SOLUTIONS

3.1 CODE

#include <stdio.h> printf("June");


#include <conio.h> break;
case 7:
int x; printf("July");
break;
main() case 8:
{ printf("August");
printf("[1-12]\nInput integer: "); break;
scanf("%d", &x); case 9:
printf("September");
switch (x) break;
{ case 10:
case 1: printf("October");
printf("January"); break;
break; case 11:
case 2: printf("November");
printf("Febuary"); break;
break; case 12:
case 3: printf("December");
printf("March"); break;
break; default:
case 4: printf("Invalid input. [1-
printf("April"); 12]");
break; }
case 5:
printf("May"); getch();
break; }
case 6:

OUTPUT
3.2 CODE

#include <stdio.h>
#include <conio.h>

int h;

main()
{
printf("Input hours: ");
scanf("%d", &h);

if (h>40)
printf("\nEmployee has worked overtime hours.");

else
printf("\nEmployee did not work overtime hours.");

getch();
}

OUTPUT
3.3 CODE

#include <stdio.h>
#include <conio.h>

int x,y,z;

main()
{
printf("Input three different integers: \n");
scanf("%d%d%d", &x,&y,&z);

if (x>y & x>z)


printf("\n%d is highest among %d,%d and %d.", x,x,y,z);

else if (y>x & y>z)


printf("\n%d is highest among %d,%d and %d.", y,x,y,z);

else if (z>x & z>y)


printf("\n%d is highest among %d,%d and %d.", z,x,y,z);

else if (x==y || x==z || y==z)


printf("\nINVALID INPUT.");

getch();
}

OUTPUT
3,4 CODE

#include <stdio.h>
#include <conio.h>

int p;
float t;

main()
{
printf("Input purchase: ");
scanf("%d", &p);

t=p-(p*.10);

if (p>=1000)
printf("\nCustomer is entitled to a 10 percent discount.\nNet bill is %.2f.",t);

else
printf("\nNet bill is %d.",p);

getch();
}

OUTPUT
3.5 CODE
#include <stdio.h>
#include <conio.h>

int s;
main()
{
printf("Input speed: ");
scanf("%d", &s);

if (s>100)
printf("\nCar speed is beyond 100 kph.\nFine will be P800.");

else if (s>80)
printf("\nCar speed is beyond 80 kph.\nFine will be P500.");

else
printf("\nCar speed did not go beyond limit.\nNo fine to be issued.");

getch();
}
OUTPUT
3.6 CODE
#include <stdio.h>
#include <conio.h>

int yr;
float x;

main()
{
printf("Input year: ");
scanf("%d",&yr);

x=yr%4;

if (x==0)
printf("\nThis year is a leap year.");

else
printf("\nThis year is an ordinary year.");

getch();
}

OUTPUT
3.7 CODE
#include <stdio.h>
#include <conio.h>

int s;

main()
{
printf("Input student's score: ");
scanf("%d", &s);

if (s<60)
printf("\nStudent's grade is F.");

else if (s>=60 && s<70)


printf("\nStudent's grade is D.");

else if (s>=70 && s<80)


printf("\nStudent's grade is C.");

else if (s>=80 && s<90)


printf("\nStudent's grade is B.");

else if (s>=90 && s<=100)


printf("\nStudent's grade is A.");

else
printf("\nInvalid score.");

getch();
}

OUTPUT
3.8 CODE
#include<stdio.h>
#include<conio.h>

float x,y,z;
char c;

main()
{

printf("CODES: *CASE SENSITIVE*\n\nA for Addition\nB for Subtraction\nC for


Multiplication\nD for Division\n\nEnter Code: ");
scanf("%c", &c);
printf("\nEnter first number: ");
scanf("%f", &x);
printf("Enter second number: ");
scanf("%f", &y);

switch (c)
{

case 'A':
z=x+y;
printf("\nThe sum is %.2f ",z);
break;
case 'B':
z=x-y;
printf("\nThe difference is %.2f ",z);
break;
case 'C':
z=x*y;
printf("\nThe product is %.2f ",z);
break;
case 'D':
z=x/y;
printf("\nThe quotient is %.2f ",z);
break;
default:
printf("\nINVALID CODE.");
}

getch();
}
OUTPUT

3.9 CODE
#include <stdio.h>
#include <conio.h>

int x,a,b;

main()
{
printf("Enter number: ");
scanf("%d", &x);

a=x%10;
b=x/10;

if (b>=2 && b<=9)


switch (b)
{
case 2:
printf("Twenty");
break;
case 3:
printf("Thirty");
break;
case 4:
printf("Forty");
break;
case 5:
printf("Fifty");
break;
case 6:
printf("Sixty");
break;
case 7:
printf("Seventy");
break;
case 8:
printf("Eighty");
break;
case 9:
printf("Ninety");
break;
}

if (b!=1 && a>=1 && x<=100)


switch (a)
{
case 1:
printf(" One");
break;
case 2:
printf(" Two");
break;
case 3:
printf(" Three");
break;
case 4:
printf(" Four");
break;
case 5:
printf(" Five");
break;
case 6:
printf(" Six");
break;
case 7:
printf(" Seven");
break;
case 8:
printf(" Eight");
break;
case 9:
printf(" Nine");
break;
}
if (b==1)
switch (a)
{
case 0:
printf("Ten");
break;
case 1:
printf("Eleven");
break;
case 2:
printf("Twelve");
break;
case 3:
printf("Thirteen");
break;
case 4:
printf("Fourteen");
break;
case 5:
printf("Fifteen");
break;
case 6:
printf("Sixteen");
break;
case 7:
printf("Seventeen");
break;
case 8:
printf("Eighteen");
break;
case 9:
printf("Nineteen");
break;
}

else if (x==100)
printf("One Hundred");

else if (x>100 || x<1)


printf("INVALID INPUT. [1-100]");

getch();
}
OUTPUT

3.10 CODE
#include<stdio.h>
#include<conio.h>

int a,b,c;

main()
{
printf("Enter three angles of a triangle: \n");
scanf("%d%d%d", &a,&b,&c);

if (a+b+c!=180)
printf("\nNot a triangle. Angles must add up to 180 degrees.");

else if (a==90 || b==90 || c==90)


printf("\nRight Triangle");

else if (a==b && a!=c || b==c && b!=a || c==a && c!=b)
printf("\nIsosceles Triangle");

else if (a==b && b==c && c==a)


printf("\nEquilateral/Equiangular Triangle");

else
printf("\nScalene Triangle");

getch();
}
OUTPUT
3.11 CODE
#include <stdio.h>
#include <conio.h>

int x,a,b1,b2,c;

main()
{
printf("Enter number: ");
scanf("%d", &x);

a=x%10;
b1=x/10;
b2=b1%10;
c=x/100;

if (c>=1 && c<=9)


switch (c)
{
case 1:
printf("C");
break;
case 2:
printf("CC");
break;
case 3:
printf("CCC");
break;
case 4:
printf("CD");
break;
case 5:
printf("D");
break;
case 6:
printf("DC");
break;
case 7:
printf("DCC");
break;
case 8:
printf("DCCC");
break;
case 9:
printf("CM");
break;
}

if (b2>=2 && b2<=9)


switch (b2)
{
case 2:
printf("XX");
break;
case 3:
printf("XXX");
break;
case 4:
printf("XL");
break;
case 5:
printf("L");
break;
case 6:
printf("LX");
break;
case 7:
printf("LXX");
break;
case 8:
printf("LXXX");
break;
case 9:
printf("XC");
break;
}

if (b2!=1 && a>=1 && x<1000)


switch (a)
{
case 1:
printf("I");
break;
case 2:
printf("II");
break;
case 3:
printf("III");
break;
case 4:
printf("IV");
break;
case 5:
printf("V");
break;
case 6:
printf("VI");
break;
case 7:
printf("VII");
break;
case 8:
printf("VIII");
break;
case 9:
printf("IX");
break;
}

else if (b2==1)
switch (a)
{
case 0:
printf("X");
break;
case 1:
printf("XI");
break;
case 2:
printf("XII");
break;
case 3:
printf("XIII");
break;
case 4:
printf("XIV");
break;
case 5:
printf("XV");
break;
case 6:
printf("XVI");
break;
case 7:
printf("XVII");
break;
case 8:
printf("XVIII");
break;
case 9:
printf("XIX");
break;
}

else if (x==1000)
printf("M");

else if (x>1000 || x<1)


printf("INVALID INPUT. [1-1000]");

getch();
}
OUTPUT
3.12 CODE
#include <stdio.h>
#include <conio.h>

int age,test;

main()
{
printf("Age of the Applicant: ");
scanf("%d", &age);

if (age<18)
printf("\nUNDERAGE");

else if (age==18)
{
printf("\nSTUDENT LICENSE POSSIBLE\n");
printf("\nDrug Test Result\n Enter 1 if Positive\n Enter 2 if Negative\n\n ");
scanf("%d", &test);

if (test==1)
printf("\nHOLD LICENSE");

else if (test==2)
printf("\nRELEASE LICENSE");

else
printf("\nINVALID INPUT");
}

else if (age>18)
{
printf("PROFESSIONAL LICENSE POSSIBLE\n");
printf("\nDrug Test Result\n Enter 1 if Positive\n Enter 2 if Negative\n\n ");
scanf("%d", &test);

if (test==1)
printf("\nHOLD LICENSE");

else if (test==2)
printf("\nRELEASE LICENSE");

else
printf("\nINVALID INPUT");
}

getch();
}

OUTPUT

3.13 CODE
#include<stdio.h>
#include<conio.h>

float tax, tax1, tax2;


int num;
char code;

main()
{
printf("CODES: *CASE SENSITIVE*\n\nW for SINGLE\nX for HEAD OF THE
FAMILY\nY for MARRIED (JOINT)\nZ for MARRIED (SEPARATED)\n\nEnter Code: ");
scanf("%c", &code);
printf("Enter Taxable Income: ");
scanf("%f", &tax2);

switch (code)
{
case 'W':
tax=(17850*0.125)+((tax2-17850)*0.10);
printf("Enter Number of Independent/s <1,2,3>: ");
scanf("%d", &num);
if (num==1)
{
tax1=tax-1500;
printf("\nCalculated Tax is %.2f", tax1);
}
else if (num==2)
{
tax1=tax-2300;
printf("\nCalculated Tax is %.2f", tax1);
}
else if (num==3)
{
tax1=tax-3100;
printf("\nCalculated Tax is %.2f", tax1);
}
else
{
printf("\nINVALID INPUT");
}
break;

case 'X':
tax=(23900*0.125)+((tax2-23900)*0.10);
printf("Enter Number of Independent/s: ");
scanf("%d", &num);
if (num==1)
{
tax1=tax-1500;
printf("\nCalculated Tax is %.2f", tax1);
}
else if (num==2)
{
tax1=tax-2300;
printf("\nCalculated Tax is %.2f", tax1);
}
else if (num==3)
{
tax1=tax-3100;
printf("\nCalculated Tax is %.2f", tax1);
}
else
{
printf("\nINVALID INPUT");
}
break;
case 'Y':
tax=(29750*0.125)+((tax2-29750)*0.10);
printf("Enter Number of Independent/s: ");
scanf("%d", &num);
if (num==1)
{
tax1=tax-1500;
printf("\nCalculated Tax is %.2f", tax1);
}
else if (num==2)
{
tax1=tax-2300;
printf("\nCalculated Tax is %.2f", tax1);
}
else if (num==3)
{
tax1=tax-3100;
printf("\nCalculated Tax is %.2f", tax1);
}
else
{
printf("\nINVALID INPUT");
}
break;

case 'Z':
tax=(14875*0.125)+((tax2-14875)*0.10);
printf("Enter Number of Independent/s: ");
scanf("%d", &num);
if (num==1)
{
tax1=tax-1500;
printf("\nCalculated Tax is %.2f", tax1);
}
else if (num==2)
{
tax1=tax-2300;
printf("\nCalculated Tax is %.2f", tax1);
}
else if (num==3)
{
tax1=tax-3100;
printf("\nCalculated Tax is %.2f", tax1);
}
else
{
printf("\nINVALID INPUT");
}
break;
default:
printf("\nINVALID INPUT");
}
getch();
}
OUTPUT

Das könnte Ihnen auch gefallen