Sei sulla pagina 1di 3

C Programs

1a) write a C program to calculate the area of circle


#include<stdio.h>
#include<conio.h>
#define pi 3.14285
void main()
{
float radius,area;
printf("Enter the circle radius value: ");
scanf("%f",&radius);
area=pi*radius*radius;
printf("Area of Circle: %f",area);
}

1b) write a C program to convert C to F.


#include<stdio.h>
#include<conio.h>
void main()
{
float f_val,c_val;
printf("Enter the celcius value: ");
scanf("%f",&c_val);
f_val=(c_val*1.8)+32;
printf("Farenheit: %f",f_val);
}

1c) write a C program to convert F to C.


#include<stdio.h>
#include<conio.h>
void main()
{
float f_val,c_val;
printf("Enter the farenheit value: ");
scanf("%f",&f_val);
c_val=(f_val-32)/1.8;
printf("Celcius Value: %f",c_val);
}

2a) write a C program to find the biggest of given three numbers.


#include<stdio.h>
void main()
{
int a,b,c;
printf("Biggest of 3 Numbers\n Enter three values: ");
scanf("%d",&a);
scanf("%d",&b);
scanf("%d",&c);
if(a>b&&a>>c)

printf("%d is the greatest number",a);


else if(b>a&&b>c)
printf("%d is the greatest number",b);
else
printf("%d is the greatest number",c);
}

2b) write a C program to check whether the given year is leap year or
not.
#include<stdio.h>
#include<conio.h>
void main()
{
int year;
clrscr();
printf("Enter the year value: ");
scanf("%d",&year);
if(year%4==0)
printf("%d is a leap year",year);
else
printf("%d is not leap year",year);
getch();
}

4a) write a C program to check whether the given number is even or


odd.
#include<stdio.h>
#include<conio.h>
void main()
{
int num;
clrscr();
printf("Enter a value: ");
scanf("%d",&num);
if(num%2==0)
printf("%d is an even number",num);
else
printf("%d is an odd number",num);
getch();
}

4b) write a C program to calculate the square root of given number.


#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
float n,result;
clrscr();

printf("Enter the value: ");


scanf("%f",&n);
result=sqrt(n);
printf("Square Root value: %5.0f",result);
getch();
}

5b) write a C program to reverse the digits of a given number.


#include<stdio.h>
#include<conio.h>
void main()
{
int j,n,temp,result=0;
clrscr();
printf("Enter a value: ");
scanf("%d",&n);
temp=n;
while(n>0)
{
j=n%10;
result=(result*10)+j;
n=n/10;
}
printf("Reverse of %d is %d",temp,result);
getch();
}

6a) write a C program to check whether the given number is a


palindrome or not.
#include<stdio.h>
#include<conio.h>
void main()
{
int j,n1,n2=0,temp;
printf("Enter a value: ");
scanf("%d",&n1);
temp=n1;
while(n1>0) {
j=n1%10;
n2=n2*10+j;
n1/=10;
}
if(temp==n2)
printf("\n%d is a palindrome",temp);
else
printf("\n%d is not a palindrome",temp);
}

Potrebbero piacerti anche