0% found this document useful (0 votes)
16 views7 pages

Lab Task01

The document contains 7 coding problems and their solutions in C programming language. The problems include: 1) Calculating VAT on an amount, 2) Converting Fahrenheit to Celsius, 3) Finding ASCII code of a character, 4) Calculating circumference of a circle, 5) Determining profit or loss, 6) Calculating total bill for a car rental, 7) Calculating number of cubic marbles that can fit in a cubic box. For each problem, the code takes inputs, performs calculations, and prints the output.

Uploaded by

2023-3-60-047
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views7 pages

Lab Task01

The document contains 7 coding problems and their solutions in C programming language. The problems include: 1) Calculating VAT on an amount, 2) Converting Fahrenheit to Celsius, 3) Finding ASCII code of a character, 4) Calculating circumference of a circle, 5) Determining profit or loss, 6) Calculating total bill for a car rental, 7) Calculating number of cubic marbles that can fit in a cubic box. For each problem, the code takes inputs, performs calculations, and prints the output.

Uploaded by

2023-3-60-047
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

Lab Task

1. Write a C program which takes an amount as input and calculates the VAT (5% of the
amount) and outputs the total amount including VAT.

Solution:

#include <stdio.h>
#include <stdlib.h>

int main()
{
float amnt;
printf("Please Enter the Amount Your Majesty:");
scanf("%f", &amnt);
float res;
res = amnt+amnt*.05;

printf("Your Total amount is: %.4f", res);


return 0;
}

Output:
2. Write a C program which takes temperature as input in the fahrenheit unit and converts it
to a celsius unit. The formula is:
C = (5/9) * (F-32)

Solution:

#include <stdio.h>
#include <stdlib.h>

int main()
{
float frnht;
printf("Enter the desired temperature:");
scanf("%f", &frnht);
float cels;
cels= (5.0/9.0) * (frnht-32.0);
printf("Your Celsius temperature is:%.2f\n", cels);
return 0;
}

Output:
3. Write a C program which takes a character as input and shows its ASCII code.

Solution:

#include <stdio.h>
#include <stdlib.h>

int main()
{
char s;
printf("Enter the beloved character:");
scanf("%c", &s);
printf("The ASCII code of %c is %d", s,s);
return 0;
}

Output:
4. Write a program which takes radius as input and, finds out the circumference of a circle.

Solution:

#include <stdio.h>
#define PI 3.1416

int main()
{
double rad,crcmfrnc;
printf("Will you please enter the radius of the circle:");
scanf("%lf", &rad);
crcmfrnc= (2 * PI * rad);
printf("The circumference of the circle is:%.3lf\n", crcmfrnc);
return 0;
}

Output:
5. Write a program to input the selling price and cost price from the user and determine whether
the seller has made profit or incurred loss. Also display the value of profit or loss in percentage.
formatted I/O functions

Solution:

#include <stdio.h>
#include <stdlib.h>

int main()
{
double s, c, t, p, l;
printf("Enter the selling price:");
scanf("%lf", &s);
printf("Enter cost price:");
scanf("%lf", &c);
t= s - c;
if(t>0){
p= (t/c)*100;
printf("Your profit is : %.3lf (Profit percentage: %.2lf)\n", t,p);
}
else if (t<0){
l= (-t/c)*100;
printf("Your loss is : %.3lf (Profit percentage: %.2lf)\n", t,l);
}
else {
printf("Zero Profit, Zero Loss\n");
}
return 0;
}

Output:
6. A car rental company charges 20 BDT for every kilometer of travel. (It charges a full 20 BDT
for any fractional km). It also charges 2 BDT for every minute of waiting. Write a C program
which can input a fractional number indicating distance travel and an integer number indicating
waiting time in minutes. Display the total bill for that ride.

Solution:

#include <stdio.h>

int main() {
double dist;
int wait;

printf("Enter the distance traveled (in kilometers): ");


scanf("%lf", &dist);
printf("Enter the waiting time (in minutes): ");
scanf("%d", &wait);

double distanceCost = dist * 20;


double waitingCost = wait * 2;
double total= distanceCost + waitingCost;

printf("Total Bill: %.2lf BDT\n", total);


return 0;
}

Output:
7. You have bought many cubic shaped marbles and want to store them in a cube shape box.
Write a C program which can input the length of marbles and length of the box and display
how many marbles can be stored in that box.

Solution:
#include <stdio.h>

int main() {
float marble_length, box_length, number_of_marbles;

printf("Enter the length of the marble in cm: ");


scanf("%f", &marble_length);

printf("Enter the length of the box in cm: ");


scanf("%f", &box_length);

number_of_marbles = (box_length * box_length * box_length) / (marble_length *


marble_length * marble_length);

printf("The number of marbles that can be stored in the box is: %.0f\n", number_of_marbles);

return 0;
}

Output:

You might also like