0% found this document useful (0 votes)
3 views

c lang

The document contains a series of C programming exercises that demonstrate various calculations and conversions, including area and perimeter of a rectangle, area and circumference of a circle, average of three numbers, and swapping numbers. It also includes programs for adding digits of a four-digit number, calculating cost price from selling price and profit, converting temperatures between Celsius and Fahrenheit, and converting centimeters to meters. Each program is presented with code snippets and prompts for user input.

Uploaded by

mnahm8096
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

c lang

The document contains a series of C programming exercises that demonstrate various calculations and conversions, including area and perimeter of a rectangle, area and circumference of a circle, average of three numbers, and swapping numbers. It also includes programs for adding digits of a four-digit number, calculating cost price from selling price and profit, converting temperatures between Celsius and Fahrenheit, and converting centimeters to meters. Each program is presented with code snippets and prompts for user input.

Uploaded by

mnahm8096
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 9

RAAM RAAM BHAI SARYA N 🚩🚩

1. Write a program to calculate area and perimeter of rectangle.

#include <stdio.h>

#include<conio.h>

void main()

float l, w, a, p;

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

scanf("%f", &l);

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

scanf("%f", &w);

a = l*w;

p = 2 * (l + w);

printf("Area of the rectangle: %.2f\n", a);

printf("Perimeter of the rectangle: %.2f\n", p);

getch ();

2. Write a program to calculate area and circumference of circle.

#include <stdio.h>

#include<conio.h>

#include <math.h>

void main()
{

float r, a, c;

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

scanf("%f", &r);

area = M_PI * r * r; // M_PI is the value of pi from math.h

c = 2 * M_PI * r;

printf("Area of the circle: %.2f\n", a);

printf("Circumference of the circle: %.2f\n", c);

getch ();

3. Write a program to calculate average of three numbers.

#include <stdio.h>

#include<conio.h>

void main()

float num1, num2, num3, average;

printf("Enter the first number: ");

scanf("%f", &num1);

printf("Enter the second number: ");

scanf("%f", &num2);

printf("Enter the third number: ");

scanf("%f", &num3);

average = (num1 + num2 + num3) / 3;

printf("The average of the three numbers is: %.2f\n", average);

getch();

}
4. Write a program to swap two numbers with the help of third variable.

#include <stdio.h>

#include<conio.h>

void main()

int num1, num2, temp;

printf("Enter the first number: ");

scanf("%d", &num1);

printf("Enter the second number: ");

scanf("%d", &num2);

printf("Before swapping: \n");

printf("First number: %d\n", num1);

printf("Second number: %d\n", num2);

temp = num1;

num1 = num2;

num2 = temp;

printf("After swapping: \n");

printf("First number: %d\n", num1);

printf("Second number: %d\n", num2);

getch();

5. Write a program to swap two numbers without using third variable.

#include <stdio.h>

#include<conio.h>
void main()

int num1, num2;

printf("Enter the first number: ");

scanf("%d", &num1);

printf("Enter the second number: ");

scanf("%d", &num2);

printf("Before swapping: \n");

printf("First number: %d\n", num1);

printf("Second number: %d\n", num2);

num1 = num1 + num2;

num2 = num1 - num2;

num1 = num1 - num2;

printf("After swapping: \n");

printf("First number: %d\n", num1);

printf("Second number: %d\n", num2);

getch();

6. Write a program to add first and last digit of four digit number.

#include <stdio.h>

#include<conio.h>
void main()

int number, firstDigit, lastDigit, sum;

printf("Enter a four-digit number: ");

scanf("%d", &number);

if (number < 1000 || number > 9999)

printf("Please enter a valid four-digit number.\n");

lastDigit = number % 10;

firstDigit = number / 1000;

sum = firstDigit + lastDigit;

printf("The sum of the first and last digits is: %d\n", sum);

getch();

7. Write a program to calculate cost price of one item after taking selling price and profit for 15 items.

#include <stdio.h>

#include<conio.h>

void main()
{

float sellingPricePerItem, profitPerItem, totalSellingPrice, totalProfit, totalCostPrice, costPricePerItem;

printf("Enter the selling price of one item: ");

scanf("%f", &sellingPricePerItem);

printf("Enter the profit per item: ");

scanf("%f", &profitPerItem);

totalSellingPrice = sellingPricePerItem * 15;

totalProfit = profitPerItem * 15;

totalCostPrice = totalSellingPrice - totalProfit;

costPricePerItem = totalCostPrice / 15;

printf("The cost price of one item is: %.2f\n", costPricePerItem);

getch();

8. Write a program to convert temperature Celsius into Fahrenheit.

#include <stdio.h>

#include<conio.h>

float celsius_to_fahrenheit(float celsius)

return (celsius * 9 / 5) + 32;

}
int main()

float celsius, fahrenheit;

printf("Enter temperature in Celsius: ");

scanf("%f", &celsius);

fahrenheit = celsius_to_fahrenheit(celsius);

printf("%.2f°C is equal to %.2f°F\n", celsius, fahrenheit);

return 0;

9. Write a program to convert temperature Fahrenteit into Celsius.

#include <stdio.h>

#include<conio.h>

float fahrenheit_to_celsius(float fahrenheit)

return (5.0 / 9.0) * (fahrenheit - 32);

int main()

float fahrenheit, celsius;

printf("Enter temperature in Fahrenheit: ");


scanf("%f", &fahrenheit);

celsius = fahrenheit_to_celsius(fahrenheit);

printf("%.2f°F is equal to %.2f°C\n", fahrenheit, celsius);

return 0;

10. Write a program to convert centimetre into metre.

#include <stdio.h>

#include<conio.h>

float centimeters_to_meters(float centimeters)

return centimeters / 100.0;

int main()

float centimeters, meters;

printf("Enter length in centimeters: ");

scanf("%f", &centimeters);

meters = centimeters_to_meters(centimeters);

printf("%.2f cm is equal to %.2f meters\n", centimeters, meters);


return 0;

Dhanaywaad

You might also like