0% found this document useful (0 votes)
961 views7 pages

C Program To Find Area and Circumference of Circle

The document contains code snippets for C programs to calculate the area and circumference of a circle, area of a rectangle, check if a number is prime, print array elements, and search an element in an array. The programs take user input, perform the relevant calculations, and output the results.

Uploaded by

NEERAJ
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)
961 views7 pages

C Program To Find Area and Circumference of Circle

The document contains code snippets for C programs to calculate the area and circumference of a circle, area of a rectangle, check if a number is prime, print array elements, and search an element in an array. The programs take user input, perform the relevant calculations, and output the results.

Uploaded by

NEERAJ
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

C Program to find area and circumference of circle

#include<stdio.h>

int 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);

return(0);
}

Output :
Enter radius of a circle : 1
Area of circle : 3.14
Circumference : 6.28
C Program to Calculate Area of Circle

#include<stdio.h>

int main() {
float radius, area;

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


scanf("%d", &radius);

area = 3.14 * radius * radius;


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

return (0);
}

Output :

1 Enter the radius of Circle : 2.0


2 Area of Circle : 6.14
C Program to Calculate Area of Rectangle

#include<stdio.h>
#include<conio.h>

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

printf("\nEnter the Length of Rectangle : ");


scanf("%d", &length);

printf("\nEnter the Breadth of Rectangle : ");


scanf("%d", &breadth);

area = length * breadth;


printf("\nArea of Rectangle : %d", area);

return (0);
}

Output :

Enter the Length of Rectangle : 5


Enter the Breadth of Rectangle : 4
Area of Rectangle : 20
C Program to Calculate Area and Circumference of circle
#include<stdio.h>

int 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);

return (0);
}

Output :

Enter radius of a circle : 1


Area of circle : 3.14
Circumference : 6.28
Check Whether Number is Prime or not
#include<stdio.h>

int main() {
int num, i, count = 0;

printf("Enter a number:");
scanf("%d", &num);
if(num==0||num==1)
{

printf("%d is not a prime number", num);


}

for (i = 2; i <= num / 2; i++) {


if (num % i == 0) {
count++;
break;
}
}

if (count == 0)
printf("%d is a prime number", num);
else
printf("%d is not a prime number", num);

return 0;
}
C Program to Print Array Elements

#include<stdio.h>

int main() {
int i, arr[50], num;

printf("\nEnter no of elements :");


scanf("%d", &num);

//Reading values into Array


printf("\nEnter the values :");
for (i = 0; i < num; i++) {
scanf("%d", &arr[i]);
}

//Printing of all elements of array


for (i = 0; i < num; i++) {
printf("\narr[%d] = %d", i, arr[i]);
}

return (0);
}
C Program to Search an element in Array

#include<stdio.h>

int main() {
int a[30], ele, num, i;

printf("\nEnter no of elements :");


scanf("%d", &num);

printf("\nEnter the values :");


for (i = 0; i < num; i++) {
scanf("%d", &a[i]);
}

//Read the element to be searched


printf("\nEnter the elements to be searched :");
scanf("%d", &ele);

//Search starts from the zeroth location


i = 0;
while (i < num && ele != a[i]) {
i++;
}

//If i < num then Match found


if (i < num) {
printf("Number found at the location = %d", i + 1);
} else {
printf("Number not found");
}

return (0);
}

Output :
Enter no of elements : 5
11 22 33 44 55
Enter the elements to be searched : 44
Number found at the location = 4

You might also like