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

C Program To Find Area and Circumference of Circle

The document contains 6 C programming code examples that demonstrate calculating the area and circumference of a circle, swapping two numbers without a third variable, calculating the sum and percentage of 5 subjects, checking if a number is odd or even using modulus, and finding the largest of three numbers using if/else statements. Each example includes the code, input/output, and is focused on demonstrating a different basic programming concept.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
62 views

C Program To Find Area and Circumference of Circle

The document contains 6 C programming code examples that demonstrate calculating the area and circumference of a circle, swapping two numbers without a third variable, calculating the sum and percentage of 5 subjects, checking if a number is odd or even using modulus, and finding the largest of three numbers using if/else statements. Each example includes the code, input/output, and is focused on demonstrating a different basic programming concept.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

1.

C Program to find area and circumference of circle


#include<stdio.h>
#include<conio.h>
void main() {

int rad;
float PI = 3.14, area, ci;

printf("\nEnter radius of circle: ");


scanf("%d", &rad);

area = PI * rad * rad;


printf("\nArea of circle : %f ", area);

ci = 2 * PI * rad;
printf("\nCircumference : %f ", ci);

getch();
}
output
Enter radius of a circle : 1
Area of circle : 3.14
Circumference : 6.28

2. Area of Circle
#include<stdio.h>
#include<conio.h>

void main() {
float radius, area;

printf("\nEnter the radius of Circle : ");


scanf("%d", &radius);

area = 3.14 * radius * radius;


printf("\nArea of Circle : %f", area);

getch();
}

output
Enter the radius of Circle : 2.0
Area of Circle : 6.14

3. Program to show swap of two nos without using third


variable
#include<stdio.h>

int main() {
int a, b;

printf("\nEnter value for num1 & num2 : ");


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

a = a + b;
b = a - b;
a = a - b;

printf("\nAfter swapping value of a : %d", a);


printf("\nAfter swapping value of b : %d", b);

return (0);
}
Output :
Enter value for num1 & num2 : 10 20

After swapping value of a : 20


After swapping value of b : 10

4. Program to calculate sum of 5 subjects and find


percentage
#include<stdio.h>
int main() {
int s1, s2, s3, s4, s5, sum, total = 500;
float per;

printf("\nEnter marks of 5 subjects : ");


scanf("%d %d %d %d %d", &s1, &s2, &s3, &s4, &s5);

sum = s1 + s2 + s3 + s4 + s5;
printf("\nSum : %d", sum);

per = (sum * 100) / total;


printf("\nPercentage : %f", per);

return (0);
}
Output :
Enter marks of 5 subjects : 80 70 90 80 80
Sum : 400
Percentage : 80.00

5. program to check odd or even using modulus operator

#include <stdio.h>

int main()
{
int n;

printf("Enter an integer\n");
scanf("%d", &n);

if (n%2 == 0)
printf("Even\n");
else
printf("Odd\n");

return 0;

}
output
Enter an integer
5
Odd

6. program to find largest number using if...else statement

#include <stdio.h>
int main(){

float a, b, c;
printf("Enter three numbers: ");
scanf("%f %f %f", &a, &b, &c);
if (a>=b)
{
if(a>=c)
printf("Largest number = %.2f",a);
else
printf("Largest number = %.2f",c);
}
else
{
if(b>=c)
printf("Largest number = %.2f",b);
else
printf("Largest number = %.2f",c);
}
return 0;
}

output

Enter three numbers: 12.2


13.452
10.193

Largest number = 13.45

You might also like