Professional Documents
Culture Documents
#include<stdio.h>
int main()
int x=1,y,z=1;
scanf("%d",&y); input:- 4
while(z<=y). Output:- 24
x=x*z;
z++;
printf("%d",x);
#include<stdio.h>
int main()
int x,y;
scanf("%d%d",&x,&y);. Input:- 3 4
x=x+y;. output:- 4 3
y=x-y;
x=x-y;
printf("%d %d",x,y);
}
/* To find prime or not*/
#include<stdio.h>
int main()
int a,i,b,c=0;
scanf("%d",&a);
if(a%I==0) input:-23
c++;
if(c==2)
else
}
/* Palindrome */
#include<stdio.h>
int main()
int a,b,c=0,d,e,f,I;
scanf("%d",&a);
e=a;
while(a!=0)
b=a%10;
c=b+c*10;
a=a/10;
//printf("%d",c);
if(e==c)
printf("palindrome");
else
printf("not palindrome");
}
/* To print prime number between 1 to n*/
#include<stdio.h>
int main()
int n,m,num;
scanf("%d",&num);
for(int i=1;i<=num;i++)
n=i,m=0;
for(int j=2;j<=n-1;j++)
if(n%j==0)
m=1;
break;
if(m==0)
printf("%d ",n);
}.
Output
20
1 2 3 5 7 11 13 17 19
/* Leap year or not */
#include <stdio.h>
int main()
scanf("%d", &year);
if (year % 4 == 0) {
if (year % 100 == 0) {
if (year % 400 == 0)
printf("leap yr\n");
else
} else
printf("leap yr\n");
} else
Output
2020
leap yr
/* Ascending order */
#include<stdio.h>
int main()
int a[10],I,j,c,d,e;
scanf("%d",&d);
for(I=0;I<d;I++)
scanf("%d",&a[I]);
for(I=0;I<d;I++)
for(j=I+1;j<d;j++)
if(a[I]>a[j])
c=a[I];
a[I]=a[j];
a[j]=c;
for(I=0;I<d;I++)
printf("%d\t",a[I]);
} Output. :- 5
} 24371
1 2 3 4 7
/* Descending order */
#include<stdio.h>
int main()
int a[10],I,j,c,d,e;
scanf("%d",&d);
for(I=0;I<d;I++)
scanf("%d",&a[I]);
for(I=0;I<d;I++)
for(j=I+1;j<d;j++)
if(a[I]<a[j])
c=a[I];
a[I]=a[j];
a[j]=c;
printf("%d\t",a[I]);
} output
83926
9 8 6 3 2
/* Program of printing number 1 to 10 using while loop*/
#include<stdio.h>
int main()
int i=1;
while(i<=10)
printf("%d\n",i);
i++;
Output
10
/* Finding even numbers between 1 to 100 */
#include<stdio.h>
int main()
int i=1;
while(i<=100)
if(i%2==0)
printf("%d\t",i);
i++;
Output
2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38
40 42 44 46 48 50 52 54 56 58 60 62 64 66 68 70 72 74 76
78 80 82 84 86 88 90 92 94 96 98 100
/* Printing sum of digits */
#include<stdio.h>
int main()
int m,n=0,p;
scanf("%d",&m);
while(m!=0)
p=m%10;
n=n+p;
m=m/10;
printf("%d\t",n);
Output
172
10
/* Printing perfect square number */
#include<stdio.h>
int main()
int m,p;
scanf("%d",&m);
p=m*m;
printf("%d\t",p);
Output
81
/* Printing sum of square number digIts */
#include<stdio.h>
int main()
int m,p,n,b=0;
scanf("%d",&m);
p=m*m;
while(p!=0)
n=p%10;
b=b+n;
p=p/10;
Output
square number is 81
#include<stdio.h>
int main()
int x=1,y,z=1,m=0,a=0,b;
scanf("%d",&y);
while(z<=y)
x=x*z;
z++;
while(x!=0)
b=x%10;
a=a+b;
x=x/10;
Output
#include<stdio.h>
int main()
int no,a,b=1,c=0;
scanf("%d",&no);
for(int i=1;i<=no;i++)
printf("%d ",c);
a=b;
b=c;
c=a+b;
Output
011235
/* Armstrong number program */
#include<stdio.h>
int main()
int a,b,c=0,t;
scanf("%d",&a);
t=a;
while(a!=0)
b=a%10;
c=c+b*b*b;
a=a/10;
if(t==c)
else
Output
153
its Armstrong no