Solved Assignment Problems in C – Part2

Q1. Design a program to find the circumference of a circle. Use the formula: C=2πr, where π is approximately equivalent 3.1416.

Sol:

#include<stdio.h>
#define pi 3.1416
void main()
{
//we need to give only one input to program i.e., radius of circle r
int r;
float Circum;
printf(“Enter radius of circle r:\n”);
scanf(“%d”, &r);
Circum = 2pir;
printf(“circumference of circle is: %f”, Circum);
}

Q2. Write a program that takes as input the purchase price of an item (P), its expected number of years of service (Y) and its expected salvage value (S). Then outputs the yearly depreciation for the item (D). Use the formula: D = (P – S) Y

Sol:

//P = purchase price of an item
//S = expected salvage value
//Y = expected number of years of service
//D = yearly depreciation for the item

#include<stdio.h>
void main()
{
//we need to give 3 inputs to the program i.e., P, S, Y
float P, S, Y;
float D;
printf(“Enter purchase price of an item P:\n”);
scanf(“%f”, &P);printf(“Enter expected salvage value S:\n”);
scanf(“%f”, &S);
printf(“Enter expected number of years of service Y:\n”);
scanf(“%f”, &Y);
D = (P-S)*Y;
printf(“Product depreciation is: %f”, D);
}

Q3. Swapping of 2 variables without using temporary (or 3rd variable)

Sol:

include<stdio.h>
void main()
{
//we need to give 2 inputs: x and y
int x, y;
printf(“Enter values of x and y:\n”);
scanf(“%d %d”, &x, &y);
printf(“Before swapping, values of x and y are: %d %d”, x, y);
printf(“\n”);
x = x+y; //suppose x = 10, y = 20, then x = 10+20 = 30
y = x-y; //y = x-y = 30 – 20 = 10
x = x-y; //x = x – y = 30 – 10 = 20
printf(“After swapping, values of x and y are: %d %d”, x, y);
}

Q4. Determine the most economical quantity to be stocked for each product that a manufacturing company has in its inventory: This quantity, called economic order quantity (EOQ) is calculated as follows: EOQ=2rs/1 where: R= total yearly production requirement S=set up cost per order I=inventory carrying cost per unit.

Sol:

//EOQ = economic order quantity
//R= total yearly production requirement
//S=set up cost per order
//I=inventory carrying cost per unit

#include<stdio.h>
void main()
{
//we need to give 3 inputs to the program i.e., P, S, Y
float R, S, I;
float EOQ;
printf(“Enter total yearly production R:\n”);
scanf(“%f”, &R);
printf(“Enter set up cost S:\n”);
scanf(“%f”, &S);
printf(“Enter inventory cost I:\n”);
scanf(“%f”, &I);
EOQ = (2RS)/I;
printf(“economic order quantity EOQ is: %f”, EOQ);
}

Q5. Write a program to compute the radius of a circle. Derive your formula from the given equation: A=πr², then display the output.

Sol:

//r² = A/pi and r = sqrt(A/pi)

#include<stdio.h>
#include<math.h>
#define pi 3.1416
void main()
{
//we need to give only one input to program i.e., area of circle A
int A;
float r;
printf(“Enter area of circle A:\n”);
scanf(“%d”, &A);r = sqrt(A/pi);
printf(“Radius of circle is: %f”, r);
}

Gopal Krishna

Hey Engineers, welcome to the award-winning blog,Engineers Tutor. I'm Gopal Krishna. a professional engineer & blogger from Andhra Pradesh, India. Notes and Video Materials for Engineering in Electronics, Communications and Computer Science subjects are added. "A blog to support Electronics, Electrical communication and computer students".

Leave a Reply

Your email address will not be published. Required fields are marked *

Translate »