0% found this document useful (0 votes)
58 views

Code

The fourth document poses an international racing broadcast problem, where the program must take a speed in km/h and output equivalent speeds in mph, m/s, and y/s. The fifth document provides a problem to write a function that calculates the volume of a sphere given

Uploaded by

Miss RealCyCy
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
58 views

Code

The fourth document poses an international racing broadcast problem, where the program must take a speed in km/h and output equivalent speeds in mph, m/s, and y/s. The fifth document provides a problem to write a function that calculates the volume of a sphere given

Uploaded by

Miss RealCyCy
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

1. Hide and Seek #include <stdio.

h>
by CodeChum Admin #include <math.h>

Gone are the days where we search for criminal numbers int main()
in an array or even in the numbers themselves because {
you see, numbers have evolved, they knew that the best float num;
hiding spot is in the place where normal programmers float integer = (int)num;
would never look, and that place is BEHIND the decimal float decpos;
point. That’s right, for the past few months, these
numbers have tricked the Number Police Department printf("Enter the number: ");
Programmers by doing shady business behind these scanf("%f", &num);
decimal points because they knew that only rare and
legendary programmers can catch them. That’s why we printf("Enter the decimal
came to you, Coding Hero, we want you to rid the streets position: ");
of these hooligans by showing them that we’re smarter scanf("%f", &decpos);
than them. We will provide you the number and the
decimal position and it’s up to you how you’ll capture float decnum = num - integer;
these criminals. The whole country is depending on you.
for(int x = 1; x <= decpos; x++,
Input decnum *= 10)
{
1. The number
}
2. The decimal position int dec = decnum;
dec = dec % 10;
Output

The first line will contain a message prompt to input the printf("Decimal value at
number. decimal position = %d", dec);
The second line will contain a message prompt to input
the decimal position. return 0;
The last line contains the decimal value at the inputted
decimal position. }

Enter·the·number:·5.234
Enter·the·decimal·position:·3
Decimal·value·at·decimal·position·=·4
2. Ice Cream Cones #include <stdio.h>
by CodeChum Admin
int main()
I have always loved ice cream, I mean, who doesn't? But {
to me, the worst part of eating ice cream is the cone. I float r, v, h;
feel like no one has figured out the perfect volume yet. const float PI = 3.14;
That's why I'm going to be testing out a bunch of
different ice cream cones to test which one is the best. I'm printf("Enter the radius of the
going to give you the radius and the height of the cone cone: ");
and you have to give me the volume. Sound good? scanf("%f", &r);
printf("Enter the height of the
cone: ");
scanf("%f", &h);
Volume = (1/3) * pi * radius2 * height
v = (1.0 / 3.0) * PI * r * r * h ;
Assume that pi = 3.14
printf("Volume of the cone =
Input %.2f", v);
1. Radius of the cone return 0;
}
2. Height of the cone

Output

The first line will contain a message prompt to input the


radius of the cone.
The second line will contain a message prompt to input
the height of the cone.
The last line contains the volume of the cone rounded off
and displayed with 2 decimal places.

Enter·the·radius·of·the·cone:·1.5
Enter·the·height·of·the·cone:·6
Volume·of·the·cone·=·14.13
3. Taxi Meter #include <stdio.h>
by CodeChum Admin int main()
{
It’s the middle of the night, you just finished your shift, int met, b;
and the rain is pouring. Luckily, you find a vacant taxi. int c1, d1;
As you attempt to go in, the driver stops you and tells you int c, d;
that he can’t take you anywhere because his taxi meter is float cost, cost1;
broken. Since you desperately want to go home, you
make a deal with the taxi driver. You propose to printf("Enter the distance
manually calculate the total fare of your ride, luckily travelled (meters): ");
enough the driver trusts you and explains to you how the scanf("%d", &met);
fare is calculated.
if (met <= 450){
c1 = (met - 250)/200;
d1 = c1;
The taxi has a base fee of P40.00 for the first 250 meters. cost1 = d1 * 2.5 + 40;
An additional P2.50 is added for every succeeding 200 printf("Total cost = P%.2f",
meters. Compute and print the total fare that you would cost1);
need to pay. }
else {
Input c = (met - 250)/200;
d = c + 1;
1. Total distance travelled in meters
cost = d * 2.5 + 40;
Output printf("Total cost = P%.2f",
cost);
The first line will contain a message prompt to input the }
total distance travelled in meters. return 0;
The second line contains the total cost of the ride. }

Enter·the·distance·travelled·(meters):·250
Total·cost·=·P40.00
4. International Speeds #include<stdio.h>
by CodeChum Admin int main()
{
Ever since we started broadcasting professional races
internationally, we've been getting complaints about how float num1, smph, smps, syps;
we only display speeds in kilometers per hour. In order to
accomodate our international audiences, we're going to printf("Enter the speed (km/h):
start adding more speed units to our broadcast! Namely: ");
miles per hour, meters per second and yards per second. scanf("%f", &num1);
You're in charge of that by the way, off to the races you
go! smph = num1 / 1.60934;

printf("Speed in miles per hour


= %.2f\n", smph);
Conversion:
smps = num1 * 1000 / 60 / 60;
1 mile = 1.60934 kilometers
printf("Speed in meters per
1 km = 1093.61 yards
second = %.2f\n", smps);
1 km = 1000 meters
syps = num1 * 1093.61 / 60 /
Input 60;

1. Speed in kilometers per hour printf("Speed in yards per


second = %.2f\n", syps);
Output
return 0;
The first line will contain a message prompt to input the
speed in kilometers per hour. }
The second line contains the speed in miles per hour.
The third line contains the speed in meters per second.
The fourth line contains the speed in yards per second.

Enter·the·speed·(km/h):·20.53
Speed·in·miles·per·hour·=·12.76
Speed·in·meters·per·second·=·5.70
Speed·in·yards·per·second·=·6.24
5. Volume of a Sphere #include <stdio.h>
by Bea May Belarmino int main()
{
Write a function that computes the volume of a sphere const float pi = 3.14159;
given its radius. float vol, rad;

The volume of a sphere is given as: printf("Enter radius: ");


scanf("%f", &rad);
Accept a radius as an integer input and use the function to
calculate the radius given input radius. vol = (4.0 * pi * rad * rad * rad)
/ 3.0;
Input
printf("Volume: %0.2f", vol);
1. Radius return 0;
}
Output

Output·Sample:

Enter·radius:·5
Volume:·523.60
6. Baby's Age #include<stdio.h>
by CodeChum Admin int main(){

Walking home, Cody was amazed that people could grow int prog, teacher, peter, baby;
so old and wondered if he, a robot, would also be able to
grow like that. Suddenly, he heard a sharp cry nearby, printf("Enter The Programmer's
and as he turned the corner, he saw a baby. Cody never age: ");
saw a baby before, plus, he was never a baby himself so scanf("%d", &prog);
he was really surprised that something could be that
young. Cody asked the baby his age and the baby replied printf("Enter the teacher's age:
through crying, “My age is the product of The ");
Programmer’s age and your teacher’s age all of which is scanf("%d", &teacher);
divided by Peter’s age then added by 1.” Cody quickly
inputted all the ages. printf("Enter Peter's age: ");
scanf("%d", &peter);
Input
baby = ((prog * teacher) / peter)
1. The Programmer's age + 1;

2. Teacher's age printf("Baby's age = %d", baby);

3. Peter's age return 0;


}
Output

The first line will contain a message prompt to input The


Programmer's age.
The second line will contain a message prompt to input
the teacher's age.
The third line will contain a message prompt to input
Peter's age.
The fourth line will contain the age of the baby.

Enter·The·Programmer's·age:·10
Enter·the·teacher's·age:·10
Enter·Peter's·age:·20
Baby's·age·=·6
7. The looks matters #include<stdio.h>
by Gran Sabandal
int main()
Can't you just follow and get this thing done. I need to get {
this report to my boss. All you need to do is follow the int part_number1,
format. part_number2, part_number3,
part_number4;
Input int qty_hand1, qty_hand2,
qty_hand3, qty_hand4;
1. Part Details 1 int qty_order1, qty_order2,
qty_order3, qty_order4;
Description float price1, price2, price3,
price4;
A series of part details that contains the part number,
quantity on hand, quantity on order, and price. In a single printf("Enter part 1 details
line separated with space in order. (separated with space): ");
scanf("%d %d %d %f",
Sample &part_number1, &qty_hand1,
&qty_order1, &price1);
31235·22·86·45.62
2. Part Details 2
printf("Enter part 2 details
Description (separated with space): ");
scanf("%d %d %d %f",
A series of part details that contains the part number, &part_number2, &qty_hand2,
quantity on hand, quantity on order, and price. In a single &qty_order2, &price2);
line separated with space in order.
printf("Enter part 3 details
Sample (separated with space): ");
scanf("%d %d %d %f",
321·55·21·122 &part_number3, &qty_hand3,
3. Part Detail 3 &qty_order3, &price3);

Description printf("Enter part 4 details


(separated with space): ");
A series of part details that contains the part number, scanf("%d %d %d %f",
quantity on hand, quantity on order, and price. In a single &part_number4, &qty_hand4,
line separated with space in order. &qty_order4, &price4);
Sample printf("\nReport\n");

28764·0·24·0.75
4. Part Detail 4 printf("--------------------------------
------------------------------\n");
Description
printf("Part Number | Qty On
A series of part details that contains the part number, Hand | Qty On Order | Price\
quantity on hand, quantity on order, and price. In a single n");
line separated with space in order.

Sample printf("--------------------------------
------------------------------\n");
3232·12·0·10.91
Output printf(" %06d |%13d |
%14d | Php %9.2f\n",
Use the formatted table.
part_number1, qty_hand1,
Part Number must have leading zeros.
qty_order1, price1);
Qty On Hand, Qty On Order and Price have leading zeros
printf(" %06d |%13d |
suppressed.
%14d | Php %9.2f\n",
Price must be decimal points has been aligned.
part_number2, qty_hand2,
Report qty_order2, price2);
-------------------------------------------------------------- printf(" %06d |%13d |
Part·Number··|··Qty·On·Hand··|··Qty·On·Order··|··Price %14d | Php %9.2f\n",
-------------------------------------------------------------- part_number3, qty_hand3,
·031235······|···········22··|············86··|··Php·····45.62 qty_order3, price3);
·000321······|···········55··|············21··| printf(" %06d |%13d |
··Php····122.00 %14d | Php %9.2f\n",
·028764······|············0··|············24··|··Php······0.75 part_number4, qty_hand4,
·003232······|···········12··|·············0··|··Php·····10.91 qty_order4, price4);
--------------------------------------------------------------
End·of·Report
printf("--------------------------------
------------------------------\n");

printf("End of Report");

return 0;
}
8. Slippery Slope #include<stdio.h>
by CodeChum Admin int main(){
float y2, y1, x2, x1, slope;
We have an upcoming math competition and one of the
questions involve calculating the slope of a line. In order printf("Enter y2: ");
to verify their answers efficiently, we would need you to scanf("%d", &y2);
create a simple program that could solve for the slope.
Thanks in advance! printf("Enter y1: ");
scanf("%d", &y1);

printf("Enter x2: ");


Formula: scanf("%d", &x2);
m = (y2 - y1) / (x2 - x1) printf("Enter x1: ");
scanf("%d", &x1);
Input
slope = (y2 - y1) / (x2 - x1);
1. Value of y2

2. Value of y1 printf("Slope = %.2f", slope);

3. Value of x2 return 0;
}
4. Value of x1

Output

The first line will contain a message prompt to input the


value of y2.
The second line will contain a message prompt to input
the value of y1.
The third line will contain a message prompt to input the
value of x2.
The fourth line will contain a message prompt to input
the value of x1.
The last line contains the slope of the line based on the
given values rounded off and displayed with 2 decimal
places.

Enter·y2:·4
Enter·y1:·3
Enter·x2:·2
Enter·x1:·1
Slope·=·1.00

You might also like