Problem sheet - 1
1 . /*finding area and perimeter of rectangle*/
#include <stdio.h>
int main() {
//input
int height = 7, width = 5;
int perimeter = 2 * (height + width);
int area = height * width;
//output
printf("Perimeter of the rectangle = %d inches\n", perimeter);
printf("Area of the rectangle = %d square inches\n", area);
return 0;
}
2 . //converting feets and inches into centimeters
#include <stdio.h>
int main() {
int feet, inches;
float cm;
printf("Enter length (feet and inches): ");
scanf("%d %d", &feet, &inches);
//formula
cm = (feet * 30.48) + (inches * 2.54);
printf("Length in centimeters: %.2f cm\n", cm);
return 0;
}
3 . //different types of data types
#include <stdio.h>
int main() {
//input
int a = 125, b = 12345;
long ax = 1234567890;
short s = 4043;
float x = 2.13459;
double dx = 1.1415927;
char c = 'W';
unsigned long ux = 2541567890;
//output
printf("a + c = %d\n", a + c);
printf("x + c = %f\n", x + c);
printf("dx + x = %f\n", dx + x);
printf("((int) dx) + ax = %ld\n", ((int) dx) + ax);
printf("a + x = %f\n", a + x);
printf("s + b = %d\n", s + b);
printf("ax + b = %ld\n", ax + b);
printf("s + c = %d\n", s + c);
printf("ax + c = %ld\n", ax + c);
printf("ax + ux = %lu\n", ax + ux);
return 0;
}
4 . //finding profits,loses and commisions
#include<stdio.h>
int main(){
int shares,cost,sp,commision,amount;
printf("enter number of shares \n");
scanf("%d",&shares);
printf("enter the cost \n");
scanf("%d",&cost);
sp=(shares)*(cost);
printf("give the value of sp=%d",sp);
commision=(sp)*(2/100);
printf("give the value of commision=%d",commision);
amount=(sp)*(commision);
printf("give the value of amount=%d",amount);
return 0;
}
5 . //converting days into years
#include<stdio.h>
int main(){
int years,weeks,days;
//input
printf("enter days\n");
scanf("%d",&days);
//output
printf("%d is years\n",days/365);
printf("%d is weeks\n",(days%365)/7);
printf("%d is days",(((days%365)/7)/7));
return 0;
}
6 . //finding average
#include<stdio.h>
int main(){
float iw1,iw2,nop1,nop2,average;
//input
printf("enter iw1");
scanf("%f",&iw1);
printf("enter iw2");
scanf("%f",&iw2);
printf("enter nop1");
scanf("%f",&nop1);
printf("enter nop2");
scanf("%f",&nop2);
//output
average=((iw1*nop1)+(iw2*nop2))/(nop1+nop2);
printf("%f = average");
return 0;
}
7 . //finding car fare per kilometer
#include<stdio.h>
int main()
{
float distance,fare;
//input
printf("enter distance\n");
scanf("%f",&distance);
//output
fare=distance*30;
printf("%f=fare",fare);
return 0;
}
8 . //finding total amount and broker commision
#include<stdio.h>
int main()
{
int sp,commision,amount;
//input
printf("enter the value sp \n");
scanf("%d",&sp);
//output
commision=(sp)*(0.08);
printf("%d=commision",commision);
amount=(sp)-(commision);
printf("%d=amount",amount);
return 0;
}
9 . //finding batting average in cricket
#include<stdio.h>
#include<math.h>
int main()
{
float b,w,h,avg;
//input
printf("enter value b"); // no . of times of batting
scanf("%f",&b);
printf("enter value w"); // no . of runs
scanf("%f",&w);
printf("enter value h"); // no . of hitts
scanf("%f",&h);
//output
avg=(w-b)/h;
printf("value of avg=%f",avg);
return 0;
}
10 .