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

Problem Solving 4

This document contains 19 coding problems involving calculations in C programming language. The problems cover a range of topics including unit conversions, calculations involving geometry, time conversions, financial calculations, and electrical circuit calculations. Each problem includes the code to compile and run a C program to perform the specified calculation and output the result.

Uploaded by

Anantha Vijay
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)
30 views

Problem Solving 4

This document contains 19 coding problems involving calculations in C programming language. The problems cover a range of topics including unit conversions, calculations involving geometry, time conversions, financial calculations, and electrical circuit calculations. Each problem includes the code to compile and run a C program to perform the specified calculation and output the result.

Uploaded by

Anantha Vijay
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/ 19

C PROBLEM SOLVING ASSIGNMENT 4

Problem 1:

#include <stdio.h>

int main()
{
float pounds,ounces,kg,g;
printf("Enter Weight in Pounds : ");
scanf("%f",&pounds);
printf("Enter Weight in Ounces : ");
scanf("%f",&ounces);
g=pounds*453.592+ounces*28.349527;
kg=g/1000;
printf("\nThe weight is %.2f kilograms(kg) or %.2f grams(g)\n",kg,g);
}

Output:
Problem 2:

#include <stdio.h>
int main()
{
float days,m;
days=78*365.35;
m=days*60;
printf("Number of times the heart beat in a lifetime of 78 years is %.2f \n",m);
}

Output:

Problem 3:

#include <stdio.h>
int main()
{
float d,v,volume,area,r;
printf("Enter the diameter of the pipe: ");
scanf("%f",&d);
printf("Enter the velocity of water : ");
scanf("%f",&v);
r=d/2;
area=3.14*r*r;
volume=area*v;
printf("Diameter : %.2f ft \n",d);
printf("Velocity : %.2f ft/s \n",v);
printf("Volume : %.2f ft^3\n",volume);
return 0;
}

Output:

Problem 4:
#include <stdio.h>
#include <math.h>

int main()
{
float x1,y1,x2,y2,d;
printf("Enter the coordinates of point P : ");
scanf("%f %f",&x1,&y1);
printf("Enter the coordinates of point Q : ");
scanf("%f %f",&x2,&y2);
d=sqrt(pow((x2-x1),2)+pow((y2-y1),2));
printf("The length of the line PQ is : %.2f",d);
return 0;
}

Output:

Problem 5:
#include <stdio.h>

int main()
{
float d,r,volume;
printf("Enter the diameter of the sphere (in inches ) : ");
scanf("%f",&d);
r=d/2;
volume=(4/3)*3.14*r*r;
printf("The diameter of the sphere is : %.2f inches \n",d);
printf("The volume of the sphere is : %.2f inches^3\n",volume);
return 0;
}

Output:

Problem 6:

#include <stdio.h>

int main()
{
int id;
float quantity,cost,commission,total;
printf("COOL YOUR HOME\n\n");
printf("Enter Your ID : ");
scanf("%f",&id);
printf("Enter Number of items sold : ");
scanf("%f",&quantity);
printf("Enter Cost per item : ");
scanf("%f",&cost);
total=cost*quantity;
commission=total*0.12;
printf("Total Sales : Rs %.2f\n",total);
printf("Commission : Rs %.2f",commission);
return 0;
}

Output:
Problem 7:

#include <stdio.h>

int main()
{
int cm,cm2,km,m,n;
printf("Enter the length in cm : ");
scanf("%d",&cm);
km=cm/100000;
n=cm%100000;
m=n/100;
cm2=n%100;
printf("%d km %d m %d cm",km,m,cm2);
return 0;
}

Output:

Problem 8:

#include <stdio.h>
int main()
{
float stress,d,pound,area,r;
printf("Enter Diameter (in inches): ");
scanf("%f",&d);
r=d/2;
area=3.14*r*r;
printf("Enter Compression Load (in pounds) : ");
scanf("%f",&pound);
stress=pound/area;
printf("The diameter is : %.2f inches \n",d);
printf("Compressed Stress : %f pounds/inches^2",stress);
return 0;
}

Output:

Problem 9:

#include <stdio.h>
int main()
{
int sec,sec2,hour,day,min,n;
printf("Enter time in seconds : ");
scanf("%d",&sec);
day=sec/(24*3600);
sec=sec%(24*3600);
hour=sec/3600;
sec=sec%3600;
min=sec/60;
sec2=sec%60;
printf("%d seconds is %d days %d hours %d minutes and %d
seconds",sec,day,hour,min,sec2);
}

Output:

Problem 10:

#include <stdio.h>
int main()
{
int sec,sec2,hour,day,min,n;
printf("Enter time in seconds : ");
scanf("%d",&sec);
day=sec/(24*3600);
sec=sec%(24*3600);
hour=sec/3600;
sec=sec%3600;
min=sec/60;
sec2=sec%60;
printf("%d seconds is %d days %d hours %d minutes and %d
seconds",sec,day,hour,min,sec2);
}

Output:

Problem 11:

#include <stdio.h>
#include <math.h>
int main()
{
float f,v,n,a;
f=120;
n=4;
a=sqrt(23*23+0.5*(f*f));
v=pow(275/a,n);
printf("The voltage gain is : %.2f V ",v);
return 0;
}

Output:

Problem 12:

#include <stdio.h>
#include <math.h>

int main()
{
float year,pop,a;
year=2012;
a=0.02*(year-2000);
pop=6.0*(pow(2.718281828,a));
printf("The worldwide population in the year 2012 : %.2f billion ",pop);
return 0;
}

Output:

Problem 13:

#include <stdio.h>

int main()
{
int x,y;
printf("Enter the value of x and y : ");
scanf("%d %d",&x,&y);
if ((x-y)>0)
printf("The absolute value of x-y is : %d",x-y);
else
printf("The absolute value of x-y is : %d",y-x);
reutrn 0;
}
Output:

Problem 14:

#include <stdio.h>

int main()
{
float startm,endm,startg,endg,totm,totg,km,fuel;
float cf1=1.609,cf2=3.785;
printf("Enter Milage at the start : ");
scanf("%f",&startm);
printf("Enter Milage at the end : ");
scanf("%f",&endm);
printf("Enter fuel at the start in galleons: ");
scanf("%f",&startg);
printf("Enter fuel at the end in galleons : ");
scanf("%f",&endg);
totm=startm-endm;
totg=startg-endg;
printf("\nTotal miles traveled = %.2f miles \n",totm);
printf("Total fuel consumed = %.2f galleons \n",totg);
printf("Miles per Galleons : %f\n\n",totm/totg);
km=totm*cf1;
fuel=totg*cf2;
printf("Total Kilometer traveled = %.2f\n km",km);
printf("Total fuel consumed in liters = %.2f liters \n",fuel);
printf("Liters of fuel per 100 km : %.2f\n\n",(fuel/km)*100);
return 0;
}

Output:

Problem 15:
#include <stdio.h>

int main()
{
int a,b,s1,s2,hyp;
printf("Enter 2 positive integers : ");
scanf("%d %d",&a,&b);
s1=(m*m)-(n*n);
s2=2*m*n;
hyp=(m*m)+(n*n);
printf("The Pythagorean triplet : (%d , %d, %d)",s1,s2,hyp);
return 0;
}

Output:

Problem 17:

#include <stdio.h>
#include <math.h>
int main()
{
float a,b,c,d,x1,x2;
printf("Enter a,b,c of a quadratic equation : ");
scanf("%f %f %f",&a,&b,&c);
d=sqrt(b*b-(4*a*c));
x1=((-b)+d)/2*a;
x2=((-b)-d)/2*a;
printf("The roots of the quadratic equation are : %.2f,%.2f \n",x1,x2);
return 0;
}

Output:

Problem 18:

#include <stdio.h>

int main ()
{
float initbal,r,bal;
printf("Enter Initial Balance : ");
scanf("%f",&initbal);
printf("Enter Annual Interest rate in percentage : ");
scanf("%f",&r);
r=r/100;
int i;
for (i=1;i<4;i++){
bal=initbal*pow(1+(r/12),i);
printf("\nThe Balance at the end of Month %d : %.2f\n",i,bal);
}
return 0;
}

Output:

Problem 19:
#include <stdio.h>

int main()
{
float r1,r2,r3,parallel,series;
printf("Enter Resistance of 3 Resistors : ");
scanf("%f %f %f",&r1,&r2,&r3);
parallel=(r2*r3)/(r2+r3);
series=r1+parallel;
printf("The total resistance : %.2f ohms",series);
return 0;
}

Output:

You might also like