0% found this document useful (0 votes)
6 views10 pages

Lecture 4-Merged

The document contains multiple C programming examples that demonstrate how to calculate areas, perimeters, volumes, and other mathematical operations based on user inputs. It includes programs for rectangles, triangles, circles, washers, character conversion, finding the greatest and smallest of three integers, determining student grades, calculating tax based on salary, checking leap years, and solving quadratic equations. Each program is self-contained with input prompts and output statements.

Uploaded by

aryankhanx595
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)
6 views10 pages

Lecture 4-Merged

The document contains multiple C programming examples that demonstrate how to calculate areas, perimeters, volumes, and other mathematical operations based on user inputs. It includes programs for rectangles, triangles, circles, washers, character conversion, finding the greatest and smallest of three integers, determining student grades, calculating tax based on salary, checking leap years, and solving quadratic equations. Each program is self-contained with input prompts and output statements.

Uploaded by

aryankhanx595
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/ 10

LECTURE - 04

Write a program that calculates the area and the perimeter of a rectangle
where the length and the width of the rectangle are provided by the user as
inputs.

#include<stdio.h>
int main()
{
float length,width,area,perimeter;
printf("Input length of the Rectangle:");
scanf("%f",&length);
printf("Input width of the Rectangle:");
scanf("%f",&width);
area=length*width;
perimeter=2*(length+width);

printf("The Area of Rectangle:%f",area);


printf("\nThe Perimeter of Rectangle:%f",perimeter);
return 0;

}
Write a program that calculates the area of a triangle where the base and
height of the triangle are provided by the user as inputs.

#include<stdio.h>
int main()
{
float base,height,area,perimeter;
printf("Input base of the Triangle:");
scanf("%f",&base);
printf("Input height of the Triangle:");
scanf("%f",&height);
area=0.5*(base*height);

printf("The Area of Triangle:%f",area);


return 0;

}
Write a program that calculates the area of a circle and the perimeter of a
circle where the radius of the circle is provided by the user as input.

#include<stdio.h>
int main()
{
float radius,area,perimeter;
float const PI=3.1416;
printf("Input radius of the Circle:");
scanf("%f",&radius);

area=PI*radius*radius;
perimeter=2*PI*radius;

printf("The Area of Circle:%f",area);


printf("\nThe Perimeter of Circle:%f",perimeter);
return 0;

}
Write a program that calculates the volume and surface area of a flat washer
where the height, outer diameter (d1) and the inner diameter (d2) are
provided by the user as inputs.

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

int main()
{
float d1, d2, height, radius1, radius2, volume, surface_area;
float const PI = 3.1416;

printf("Enter the outer diameter: ");


scanf("%f", &d1);
printf("Enter the inner diameter: ");
scanf("%f", &d2);
printf("Enter the height: ");
scanf("%f", &height);

radius1 = d1 / 2;
radius2 = d2 / 2;

volume = PI * height * (radius1 * radius1 - radius2 * radius2);


surface_area = 2 * PI * (radius1 + radius2) * height + PI * (radius1 * radius1 -
radius2 * radius2);
printf("\nVolume: %.2f", volume);
printf("\nSurface Area: %.2f", surface_area);

return 0;
}
Write a program that accepts a character(small letter) as input from the user
and (a) converts it into uppercase letter and (b) shows it’s binary equivalent.

#include<stdio.h>
#include<math.h>
int main()
{
char ch,large;
printf("Input a Lowercase Character:");
scanf("%c",&ch);
large=ch-32;
printf("Uppercase Character:%c",large);

printf("\nBinary Equivalent of %d: ", ch);


int value = ch;
int divisor = 128;

while (divisor > 0)


{
printf("%d", (value / divisor) % 2);
divisor /= 2;
}
printf("\n");

return 0;
}
LECTURE-5

Write a C program that prompts the user to input three integer values and
find the greatest and smallest of those three values.

#include <stdio.h>
int main()
{
int a,b,c;
printf("Input a:");
scanf("%d",&a);
printf("Input b:");
scanf("%d",&b);
printf("Input c:");
scanf("%d",&c);
if(a>b && a>c)
printf("%d is Greatest",a);
else if(b>c && b>a)
printf("%d is Greatest",b);
else if(c>a && c>b)
printf("%d is Greatest",c);
if(a<b && a<c)
printf("\n%d is Smallest",a);
else if(b<c && b<a)
printf("\n%d is Smallest",b);
else if(c<a && c<b)
printf("\n%d is Smallest",c);
return 0;
}
Write a program that determines a student’s grade. The program
will read three scores and determine the grade.

#include <stdio.h>
int main()
{
float num1,num2,num3;
printf("Input three marks:");
scanf("%f%f%f",&num1,&num2,&num3);
float avg=(num1+num2+num3)/3;
printf("The Average:%f\n",avg);
if(avg>=90 && avg<=100)
printf("Grade = A");
else if(avg>=70 && avg<90)
printf("Grade = B");
else if(avg>=50 && avg<70)
printf("Grade = C");
else if(avg<50 && avg <=0)
printf("Grade = F");
return 0;
}
Calculate Tax

#include <stdio.h>
int main()
{
float salary;
printf("Enter your Salary:");
scanf("%f",&salary);
if(salary>=0 && salary<15000)
printf("Your Tax amount is:%.2f\n",salary*0.15);
else if(salary>=15000 && salary<30000)
printf("Your Tax amount is:%.2f\n",2250+(salary-15000)*0.18);
else if(salary>=30000 && salary<50000)
printf("Your Tax amount is:%.2f\n",5400+(salary-30000)*0.22);
else if(salary>=50000 && salary<80000)
printf("Your Tax amount is:%.2f\n",11000+(salary-50000)*0.27);
else if(salary>=80000 && salary<=150000)
printf("Your Tax amount is:%.2f\n",21600+(salary-80000)*0.33);
else
printf("Your Input is Invalid");
return 0;
}
Determine if a year (provided as input) is a Leap-year or not.

#include <stdio.h>
int main()
{
int year;
printf("Enter Year:");
scanf("%d",&year);
if((year%400==0)||(year%4==0 && year %100!=0))
{
printf("%d is a Leap Year",year);
}
else
{
printf("%d is Not a Leap Year",year);
}

return 0;
}
Write a program to compute the real roots of a quadratic equation of the
form ax2+bx+c=0, a≠0.

#include <stdio.h>
#include<math.h>
int main()
{
float a,b,c,dis,root1,root2;
printf("Input three numbers a,b,c:");
scanf("%f%f%f",&a,&b,&c);
dis=pow(b,2)-4*a*c;
root1=(-b+sqrt(dis))/2*a;
root2=(-b-sqrt(dis))/2*a;
if(dis>0)
{
printf("The two real roots are:%.3f and %.3f",root1,root2);
}
else if(dis==0)
{
printf("There is only one root and the root is:%.3f",root1);
}
else
{
printf("No real roots exist");
}

return 0;
}

You might also like