Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 13

Name-Ritul Ranjan

Section-S4

Rollno-201cv144

Cs110 ASSIGNMENT-1

Basic input output functions


QUESTION 1- To find Simple and Compound Interest

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

int main()
{
float amt, time, rate, si ,ci;

printf("Enter principle amount: ");//input amount


scanf("%f", &amt);

printf("Enter time: ");//input time


scanf("%f", &time);

printf("Enter rate: ");//input rate


scanf("%f", &rate);

si = (amt * time * rate) / 100;//calculate simple interest

printf("Simple Interest = %f", si);//print simple interest


printf("\n");

ci=amt*(pow(1+rate/100,time));//calculate compound interest

printf("Compound interest=%f",ci);//print compound interest

return 0;
}

QUESTION 2-To read the radius of a circle and find its Area and Perimeter

#include <stdio.h>

int main()
{
float rad,area, perm;

printf("Enter radius of circle: ");//enter radius


scanf("%f",&rad);

area=3.14*rad*rad;//calculate area of circle

printf("Area of the circle=%f",area);//print area of circle

printf("\n");

perm=2*3.14*rad;//calculate perimeter of circle

printf("Perimeter of the circle=%f",perm);//print Perimeter of circle

return 0;
}

QUESTION 3-To read the temperature in Fahrenheit and convert it to degree centigrade.

#include <stdio.h>

int main()
{
float fah,cen;

printf("Enter temperature in fahrenhite: ");//enter temperature in fahrenhite


scanf("%f",&fah);

cen=5*(fah-32)/9;//convert temperature in centigrade

printf("Temperature in centigrade=%f",cen);//print temperature in centigrade

return 0;
}

QUESTION 4-Program to accept student roll no, marks in 3 subjects and calculate total, average
of marks and print them with appropriate messages.

#include <stdio.h>

int main()
{

float rollno,s1,s2,s3,total,average;

printf("Enter roll number : ");//enter rollno of student


scanf("%f",&rollno);

printf("Enter marks of subject1 : "); //enter marks of subject 1


scanf("%f",&s1);

printf("Enter marks of subject2 : "); //enter marks of subject 2


scanf("%f",&s2);

printf("Enter marks of subaject 3 : "); //enter marks of subaject 3


scanf("%f",&s3);

total=s1+s2+s3;//calculate total marks


printf("Total marks of student=%f",total);//print total marks

printf("\n");

average=total/3;//calculate average of marks


printf("Average of marks =%f",average);//print average of marks

return 0;
}

QUESTION 5-An Employee's Basic Pay (BP) is to be read through a keyboard. DA is 40% of BP,
HRA is 20% of BP, calculate the Gross Pay (GP) GP is computed as BP+DA+HRA

#include <stdio.h>

int main()
{

float bp,da,hra,gp;
printf("ENTER BASIC PAY:");//enter basic pay
scanf("%f",&bp);

da=0.4*bp;//calculate da
printf("DA =%f",da);//print da

printf("\n");

hra=0.2*bp;//calculate hra
printf("HRA=%f",hra);//print hra

printf("\n");

gp=da+bp+hra;//calculate gross pay


printf("GROSS PAY=%f",gp);//print gross PAY

return 0;
}

QUESTION 6-Program to find the distance between two points (x1, y1) and (x2, y2) in a
Cartesian plane.

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

int main()
{
float x1,x2,y1,y2,dis;

printf("Enter x-coordinate of point1 (x1,y1):");//enter x1


scanf("%f",&x1);
printf("Enter y-coordinate of point1 (x1,y1):");//enter y1
scanf("%f",&y1);

printf("Enter x-coordinate of point2 (x2,y2):");//enter x2


scanf("%f",&x2);

printf("Enter y-coordinate of point2 (x2,y2):");//enter y2


scanf("%f",&y2);

dis=sqrt(pow((x2-x1),2)+pow((y2-y1),2)*1.0);//calculate distance between the points


printf("Distance between the points=%f",dis);//print distance between the points

return 0;
}

QUESTION 7-Program to swap two numbers using a temporary variable. Also print the original
and exchanged values

#include <stdio.h>

int main()
{
float n1,n2,var;

printf("ENTER FIRST NUMBER:");//enter first number


scanf("%f",&n1);

printf("ENTER SECOND NUMBER:");//enter second number


scanf("%f",&n2);

var=n1;//value of first number assigned to var

n1=n2;//value of second number assigned to first number

n2=var;//value of var assigned to second number

printf("FIRST NUMBER AFTER SWAPPING=%F",n1);//print swapped first number

printf("\n");

printf("SECOND NUMBER AFTER SWAPPING=%f",n2);//print swapped second number

return 0;
}

Operators and Expressions


QUESTION1- The distance between two cities (in km.) is input through the keyboard. Write a
program to convert and print this distance in meters, feet, inches and centimeters.

#include <stdio.h>

int main()
{
float meters,km,cm,ft,inch;
printf("Enter distance in kilometer:");//enter distance in km
scanf("%f",&km);

meters=km*1000;//convert km to meters

cm=meters*100;//convert km to centimeter

ft=3.28084*meters;//convert km to feet

inch=12*ft;//convert km to inches

printf("Distance in meteres=%f",meters);//print distance in meters

printf("\n");

printf("Distance in cenitmeters=%f",cm);//print distance in centimeters

printf("\n");

printf("Distance in feets=%f",ft);//print distance in feets

printf("\n");

printf("Distance in inches=%f",inch);//print distance in inches

return 0;
}
QUESTION 2-The length & breadth of a rectangle and radius of a circle are input through the
keyboard. Write a program to calculate the area & perimeter of the rectangle, and the area &
circumference of the circle.

#include <stdio.h>

int main()
{
float len,bre,rad,a1,a2,p1,p2;

printf("ENTER LENGTH OF RECTANGLE:");//enter length of rectangle

scanf("%f",&len);

printf("ENTER BREADTH OF RECTANGLE:");//enter breadth of rectangle

scanf("%f",&bre);

printf("ENTER RADIUS OF CIRCLE:");//enter radius of circle

scanf("%f",&rad);

a1=len*bre;//calculate area of rectangle

p1=2*len*bre;//calculate perimeter of rectangle

a2=3.14*rad*rad;//calculate area of circle

p2=2*3.14*rad;//calculate circumference of circle

printf("AREA OF REACTANGLE=%f",a1);//print area of rectangle


printf("\n");

printf("PERIMETER OF RECTANGLE=%f",p1);//print perimeter of rectangle

printf("\n");

printf("AREA OF CIRCLE=%f",a2);//print area of circle

printf("\n");

printf("CIRCUMFERENCE OF CIRCLE=%f",p2);//print circumference of circle


return 0;
}

QUESTION 3-. If a five-digit number is input through the keyboard, write a program to calculate
the sum of its digits

#include <stdio.h>

int main()
{

int num,sum,u,t,h,th,tth;

printf("ENTER A FIVE DIGIT NUMBER:");//enter a five digit number


scanf("%d",&num);

u=num%10;//digit at units place

t=(num/10)%10;//digit at tens place


h=(num/100)%10;//digit at hundreds place

th=(num/1000)%10;//digit at thousands place

tth=(num/10000)%10; //digit at ten thousands place

sum=u+t+h+th+tth;//calculate sum of the digits of the five digit number

printf("sum of the digits of the number is=%d",sum);//print the sum of the digits of the five
digit number

return 0;
}

QUESTION 4-If a five-digit number is input through the keyboard, write a program to reverse the
number.

#include <stdio.h>

int main()
{

int num,rev,u,t,h,th,tth;

printf("ENTER A FIVE DIGIT NUMBER:");//enter a five digit number


scanf("%d",&num);

u=num%10;//digit at units place

t=(num/10)%10;//digit at tens place


h=(num/100)%10;//digit at hundreds place

th=(num/1000)%10;//digit at thousands place

tth=(num/10000)%10;//digit at ten thousands place

rev=u*10000+t*1000+h*100+th*10+tth;//reverse of the number

printf("REVERSE NUMBER =%d",rev);//print the reverse of the number

return 0;
}

QUESTION 5-If the total selling price of 15 items and the total profit earned on them is input
through the keyboard, write a program to find the cost price of one item.

#include <stdio.h>

int main()

float tp,prof,cp;

printf(" Enter the total selling price Of 15 items:");//total selling price of 15 items

scanf("%f",&tp);

printf("Enter the total profit earned:");//total profit earned

scanf("%f",&prof);

cp=(tp-prof)/15;//calculate cost price of one item

printf("The Cost Price of one item is : %f",cp);//print cost price of one item
return 0;

QUESTION 6-Write a program to compute the values of square-roots and squares of the numbers 0
to 100 in steps 10

You might also like