diff --git a/Armstrong_num.c b/Armstrong_num.c new file mode 100644 index 0000000..3677d23 --- /dev/null +++ b/Armstrong_num.c @@ -0,0 +1,35 @@ +#include +int main() +{ + int number,count=0,result=0,mul=1,cnt,rem; + printf("Enter any number:"); + scanf("%d", &number); + + int q=number; + while (q!=0){ + q=q/10; + count++; + } + cnt=count; + q=number; + while(q!=0){ + rem=q%10; + while(cnt!=0){ + mul=mul*rem; + cnt--; + } + result=result+mul; + cnt=count; + q=q/10; + mul=1; +} + if(result==number) + { + printf("%d is a Armstrong number",number); + } + else + { + printf("%d is nnot a Armstrong number",number); + } +return 0; +} diff --git a/Factorial.c b/Factorial.c new file mode 100644 index 0000000..dd726a6 --- /dev/null +++ b/Factorial.c @@ -0,0 +1,14 @@ +#include +int main() +{ + int number,result=0,rem,fact=1; + printf("Enter any number:"); + scanf("%d",&number); + + int q=number; + while(q!=0){ + fact=fact*q; + q--; + } + printf("%d ",fact); +} \ No newline at end of file diff --git a/Fibonacci_series.c b/Fibonacci_series.c new file mode 100644 index 0000000..8ce3fb0 --- /dev/null +++ b/Fibonacci_series.c @@ -0,0 +1,21 @@ +#include +int main() +{ + int a,b,i,n,result,res=0; + printf("Enter the number till which you want to find fibonacci series:"); + scanf("%d",&n); + + a=0; + b=1; + + for(i=1;i<=n;i++) + { + printf(" %d ",a); + result=a+b; + a=b; + b=result; + } + res=a+res; + +} + diff --git a/Floyds_triangle.c b/Floyds_triangle.c new file mode 100644 index 0000000..190acac --- /dev/null +++ b/Floyds_triangle.c @@ -0,0 +1,19 @@ +#include +int main() +{ + int row,i,j,n; + printf("Enter the number of rows:"); + scanf("%d",&row); + + n=1; + for(i=1;i<=row;i++) + { + for(j=1;j<=i;j++) + { + printf(" %d ", n); + n++; + } + printf("\n"); + } + return 0; +} \ No newline at end of file diff --git a/Leap_year_or_not.c b/Leap_year_or_not.c new file mode 100644 index 0000000..1e0db53 --- /dev/null +++ b/Leap_year_or_not.c @@ -0,0 +1,25 @@ +#include +int main() +{ + int year; + printf("Enter any year:"); + scanf("%d", &year); + + if(year%400==0) + { + printf("%d is a leap year",year); + } + else if(year%100==0) + { + printf("%d is not a leap year",year); + } + else if (year%4==0) + { + printf("%d is a leap year",year); + } + else + { + printf("%d is not a leap year",year); + } + return 0; +} \ No newline at end of file diff --git a/Palindrome_num.c b/Palindrome_num.c new file mode 100644 index 0000000..0fc9750 --- /dev/null +++ b/Palindrome_num.c @@ -0,0 +1,25 @@ +#include +int main() +{ + int number,q,rem,result=0; + + printf("enter the number:"); + scanf("%d",&number); + + q=number; + while(q!=0) + { + rem=q%10; + result=result*10+rem; + q=q/10; + } + if(result==number) + { + printf("%d is a palindrome number", number); + } + else + { + printf("%d is not a palindrome number",number); + } + return 0; +} \ No newline at end of file diff --git a/Perfect_num.c b/Perfect_num.c new file mode 100644 index 0000000..bda162f --- /dev/null +++ b/Perfect_num.c @@ -0,0 +1,24 @@ +#include +int main() +{ + int number; + printf("Enter number:"); + scanf("%d",&number); + int i,rem,sum=0; + for(i=1;i +int main() +{ + int a,i; + printf("Enter any +ve number:"); + scanf("%d",&a); + + i=2; + while (i<=a/2) + { + if(a%i==0) + break; + i++; + } + if(i>a/2) + printf("%d is a prime number", a); + else + { + printf("%d is not a prime number.", a); + } +} \ No newline at end of file diff --git a/Strong_num.c b/Strong_num.c new file mode 100644 index 0000000..0135b20 --- /dev/null +++ b/Strong_num.c @@ -0,0 +1,39 @@ +#include +int main() +{ + int rem,result=0,number,count=0,cnt,fact=1; + printf("Enter any number:"); + scanf("%d",&number); + + int q=number; + while(q!=0) + { + q=q/10; + count++; + } + q=number; + cnt=count; + while(q!=0) + { + rem=q%10; + while(rem!=1) + { + fact=fact*rem; + rem--; + } + result=result+fact; + q=q/10; + cnt=count; + fact=1; + + } + printf("%d ",result); + if(result==number) + { + printf("YES"); + } + else + { + printf("NO"); + } +} \ No newline at end of file diff --git a/tower_of_hanoi.c b/tower_of_hanoi.c new file mode 100644 index 0000000..67851d4 --- /dev/null +++ b/tower_of_hanoi.c @@ -0,0 +1,22 @@ +#include + +void tower(int num, char frompeg, char topeg, char auxpeg) +{ + if(num==1) + { + printf("Move disk 1 from peg %c to pec %c", frompeg, topeg); + return; + } + tower(num-1,frompeg,auxpeg,topeg); + printf("\nMove disk %d from peg %c to pec %c\n",num,frompeg,topeg); + tower(num-1,auxpeg,topeg,frompeg); +} + +int main() +{ + int num; + printf("Enter the number of disk: "); + scanf("%d",&num); + tower(num, 'A', 'C', 'B'); + return 0; +}