#include<stdio.h>
int main()
{ float r,pi=3.14,s,v;
printf("enter the radius of sphere :");
scanf("%f",&r);
s=4*pi*(r*r);
v=(4/3)*pi*(r*r*r);
printf("\nsurface area = %f",s);
printf("\nvolume = %f",v);
return 0;
}
Output -
2) C program to take 5- digit number as input and find the sum of digit.
#include<stdio.h>
int main()
{ int n,r,s=0;
printf("enter 5 digit no: ");
scanf("%d",&n);
while(n!= 0)
{
r=n%10;
s+= r ;
n= n/10;
}
printf("sum is = %d",s);
}
Output -
3) write a C program to take three sides of a triangle as input and verify whether the triangle is isosceles, equilateral or scalene.
#include<stdio.h>
int main()
{ int s1,s2,s3;
printf("enter sides of triangle : ");
scanf("%d%d%d",&s1,&s2,&s3);
if(s1==s2 && s2==s3 && s3==s1)
printf("\nit is an equilateral triangle");
else if(s1==s2 || s2==s3 || s3==s1)
printf("\nit is an isosceles triangle");
else
printf("\nscalene triangle 😉");
return 0;
}
Output-
4) write a C program that takes 3 integer as input and verify whether they for Pythagorean tripet or not.
Code-
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
int a,b,c,gre,num,num1,num2,sum,sqr;
clrscr();
printf("\nEnter three +ve numbers:");
printf("\nEnter first number:");
scanf("%d",&a);
printf("\nEnter second number:");
scanf("%d",&b);
printf("\nEnter third number:");
scanf("%d",&c);
num=a*a;
num1=b*b;
num2=c*c;
if(a>b && a>c)
{
sqr=sqrt(num1+num2);
gre=a;
}
else
if(b>c)
{
sqr=sqrt(num2+num);
gre=b;
}
else
{
sqr=sqrt(num+num1);
gre=c;
}
if(sqr==gre)
{
printf("\nPythagorean Triangle possible ");
}
else
{
printf("\nTriangle not possible");
}
getch();
}
Output - comming soon...
5) write a C program to print prime number between given range of number.
Code-
#include<stdio.h>
int main()
{ int a,b,i,flag;
printf("enter start and end value");
scanf("%d%d",&a,&b);
printf("prime no. between %d and %d are :",a,b);
while(a<b)
{ flag=0;
for(i=2; i<=a/2; a++)
{ if(a%i==0)
{
flag = 1;
break;
}
}
if(flag==0)
{ printf("%d",a);
++a;
}
}
printf("\n");
}
Output- thoda wait karo..
6) write a program to define a function that take integer as argument and return sum of digit of that integer.
Code-
#include<stdio.h>
int main()
{ int n,m;
printf("enter the integer");
scanf("%d",&n);
int sum(int);
m=sum(n);
printf("the sum of digit is %d",m);
return 0;
}
int sum(x)
{ int s=0,r;
while(x!=0)
{
r=x%10;
s=s+r;
x=x/10;
}
return s;
}
Output - comming soon..
7) write a C program to define a macro that can calculate the greater of two argument use this macro to calculate the greatest of 4 numbers.
For 2 numbers:-
#include<stdio.h>
#define MAX(x,y)((x>y)?x:y)
int main()
{ int a,b,max;
printf("enter the first no.: ");
scanf("%d",&a);
printf("enter the second no.: ");
scanf("%d",&b);
max=MAX(a,b);
printf("greatest no. is %d",max);
return 0;
}
For 4 numbers:-
#include<stdio.h>
#define MAX(x,y,u,w)((x>y)&&(x>u)&&(u>w)? x:(y>u)&&(y>w)? y:(u>w)?u:w)
int main()
{ int a,b,c,d,max;
printf("enter the first no.: ");
scanf("%d",&a);
printf("\nenter the second no.: ");
scanf("%d",&b);
printf("\nenter the third no.: ");
scanf("%d",&c);
printf("\nenter the fourth no.: ");
scanf("%d",&d);
max=MAX(a,b,c,d);
printf("\ngreatest no. is %d",max);
return 0;
}
8) Objective - write a C program to define recursive function that will print the reverse of its integer argument.
Code-
include<stdio.h>
int main()
{ int num,rev_no;
printf("Enter the no");
scanf("%d",&num);
rev_no= rev_fun(num);
printf("\nthe reverse of no. is %d",rev_no);
}
int sum = 0,rem;
rev_fun(int num)
{
if(num)
{
rem=num%10;
sum=sum*10+rem;
rev_fun(num/10);
}
else return sum;
return sum;
}
Output-