1. Write a program to perform factorial.
#include<stdio.h>
#include<conio.h>
void main()
{
int a,fact=1;
clrscr();
printf("enter no");
scanf("%d",&a);
while(a>=1)
{
fact=fact*a;
a--;
}
printf("==%d",fact);
getch();
}
2. Write a program to arrange the elements in ascending and descending order.
#include<stdio.h>
#include<conio.h>
void main()
{
int no[10],x,y,temp;
clrscr();
for(x=0;x<5;x++)
{
printf("enter the %d value",x);
scanf("%d",&no[x]);
}
for(x=0;x<5;x++)
{
for(y=0;y<5;y++)
{
if(no[x]>no[y])
{
temp=no[x];
no[x]=no[y];
no[y]=temp;
}
}
}
printf("\n descending order");
for(x=0;x<5;x++)
{
printf("%d",no[x]);
}
printf("ascending order");
for(x=4;x>=0;x--)
{
printf("%d",no[x]);
}
getch();
}
3. Write a program to check whether the number is heterogeneous or not.
#include<stdio.h>
#include<conio.h>
void main()
{
int no,y,sum=0,mul=1;
clrscr();
printf("enter the no==");
scanf("%d",&no);
while(no>0)
{
y=no%10;
sum=sum+y;
mul=mul*y;
no=no/10;
}
if(sum==mul)
printf("hetrogeneous");
else
printf("not");
getch();
}
4. Write a program to swap two numbers.
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b;
clrscr();
printf("enter a and b=");
scanf("%d%d",&a,&b);
printf("a is %d and b is %d",a,b);
hello(&a,&b);
printf("a is %d and b is %d",a,b);
}
hello(int *p1,int *p2)
{
int temp;
temp=*p1;
*p1=*p2;
*p2=temp;
return(0);
}
5. Write a program to find the biggest number from the given number.
#include<stdio.h>
#include<conio.h>
void main()
{
long int no,y,max;
clrscr();
printf("enter any long no");
scanf("%ld",&no);
while(no>0)
{
y=no%10;
if(y>max)
{
max=y;
}
no=no/10;
}
printf("the biggest is %ld",max);
getch();
}
Made By: Chaudhary Amit V.
Comments
Post a Comment