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

1. #include <stdio.

h>

int main()
{
int a;
float b;
char c;
double d;

printf("Enter an integer value: ");


scanf("%d", &a);

printf("Enter a float value: ");


scanf("%f", &b);

printf("Enter a character: ");


char c = getchar();
getchar();

printf("Enter a double value: ");


scanf("%lf", &d);

printf("\nOutput integer value:%d \n", a);


printf("Output float value: %f \n", f);
printf("Output entered character: '%c' \n", c);
printf("Output entered double: %lf \n", d);

return 0;
}

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

int main()
{
int a;
int b;
int sum;

printf("\nEnter two numbers: ");


scanf("%d %d", &a, &b);

sum = a + b;
printf("Sum : %d", sum);

return 0;
}

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

int main()
{
int number1;
int number2;
int add;
int sub;
int mul;
float div;

printf("\nEnter two numbers: ");


scanf("%d %d", &number1, &number2);

add = number1 + number2;


sub = number1 - number2;
mul = number1 * number2;
div = number1 / number2;

printf("Result of Addition: %d\n", add);


printf("Result of Subtraction: %d\n", sub);
printf("Result of Multiplication: %d\n", mul);
printf("Result of Division: %f\n", div);

return 0;
}

4.

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

int main()
{
float length;
float breadth;
float perimeter;

printf("Enter the length of the rectangle: ");


scanf("%f", &length);
printf("Enter the breadth of the rectangle: ");
scanf("%f", &breadth);

perimeter = 2 * (length + breadth);

printf("The Perimeter of rectangle = %f units ", perimeter);

return 0;
}

5.

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

int main()
{
float length;
float breadth;
float area;

printf("Enter the length of the rectangle: ");


scanf("%f", &length);
printf("Enter the breadth of the rectangle: ");
scanf("%f", &breadth);

area = (length * breadth);

printf("The Area of rectangle = %f square units ", area);

return 0;
}

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

int main()
{
float radius;
float diameter;
float circumference;
float area;

printf("Enter the radius of the circle: ");


scanf("%f", &radius);

diameter = 2 * radius;
circumference = 2 * 3.14 * radius;
area = 3.14 * (radius * radius);

printf("The Diameter of circle = %.2f units \n", diameter);


printf("The Circumference of circle = %.2f units \n", circumference);
printf("The Area of circle = %.2f square units ", area);

return 0;
}

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

int main()
{
float centimeter = 1000.0;
float meter;
float kilometer;

printf("Enter length in centimeter:\n ");


scanf("%f", &centimeter);

meter = (centimeter / 100.0);


km = (centimeter / 100000.0);

printf("The Length in Meter = %.2f m \n", meter);


printf("The Length in Kilometer = %.2f km\n", Kilometer);
return 0;
}

8. #include <stdio.h>
#include <math.h>
int main()
{
float celsius;
float fahrenheit;

printf("Enter temperature in Celsius: ");


scanf("%f", &celsius);

fahrenheit = (celsius * 9 / 5) + 32;

printf("The conversion of %.2f Celsius = %.2f Fahrenheit", celsius, fahrenheit);

return 0;
}

9.

#include <stdio.h>
#include <math.h>
int main()
{
float celsius;
float fahrenheit;

printf("Enter temperature in Fahrenheit: ");


scanf("%f", &fahrenheit);

celsius = (fahrenheit - 32) * 5 / 9;

printf("The conversion of %.2f Fahrenheit = %.2f Celsius", fahrenheit, celsius);


return 0;
}

10. #include <stdio.h>


#include <math.h>
int main()
{
float base;
float height;
float area;

printf("Enter base of the triangle: ");


scanf("%f", &base);
printf("Enter height of the triangle: ");
scanf("%f", &height);

area = (base * height) / 2;

printf("Area of the triangle = %.2f square units", area);

return 0;
}

11. #include <stdio.h>


#include <math.h>
int main()
{
float phy;
float che;
float bio;
float math;
float hmth;

float total;
float average;
float percentage;

printf("Enter marks of five subjects: \n");


scanf("%f%f%f%f%f", &phy, &che, &bio, &math, &hmath);
total = phy + che + bio + math + hmath;
average = total / 5.0;
percentage = (total / 500.0) * 100;

printf("Total marks = %.2f\n", total);


printf("Average marks = %.2f\n", average);
printf("Percentage = %.2f", percentage);

return 0;
}

12. #include <stdio.h>


#include <math.h>
int main()
{
float p; //principle
float t; //time
float r; //rate
float interest;

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


scanf("%f", &p);

printf("Enter time: ");


scanf("%f", &t);

printf("Enter rate: ");


scanf("%f", &r);

interest = (p * t * r) / 100;

printf("Simple Interest = %f", interest);

return 0;
}

You might also like