You are on page 1of 15

/*Factorial Number*/

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

/*swapping of numbers without using 3rd variable*/

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

for( int I=1;I<=a;I++)

if(a%I==0) input:-23

{. Output:- it is a prime number

c++;

if(c==2)

printf("its prime no");

else

printf("not prime no");

}
/* 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;

printf("Enter any number upto you want to print prime number\n");

scanf("%d",&num);

printf("Prime number between 1 and %d is given below\n",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

Enter any number upto you want to print prime number

20

Prime number between 1 and 20 is given below

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) {

// the year is a leap year if it is divisible by 400.

if (year % 400 == 0)

printf("leap yr\n");

else

printf("Not leap yr\n");

} else

printf("leap yr\n");

} else

printf("Not leap yr\n");

// write your code here

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;

printf(" square number is %d\n",p);

while(p!=0)

n=p%10;

b=b+n;

p=p/10;

printf("sum of digit of number is %d\n",b);

Output

square number is 81

sum of digit of number is 9


/* Printing sum of factorial of each digit*/

#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++;

printf("factorial of given digit %d\n",x);

while(x!=0)

b=x%10;

a=a+b;

x=x/10;

printf("sum of that factorial %d",a);

Output

factorial of given digit 24

sum of that factorial 6


/* Fibonacci series */

#include<stdio.h>

int main()

int no,a,b=1,c=0;

printf("Enter any number upto you want to print fabonacci series\n");

scanf("%d",&no);

for(int i=1;i<=no;i++)

printf("%d ",c);

a=b;

b=c;

c=a+b;

Output

Enter any number upto you want to print fabonacci series

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)

printf("its Armstrong no");

else

printf("its not Armstrong no");

Output

153

its Armstrong no

You might also like