0% found this document useful (0 votes)
66 views5 pages

Abhishek Kumar Assignment

The document contains 8 coding assignments involving prime numbers, factorials, Armstrong numbers, square sums, Fibonacci series, number reversal, palindrome checks, and prime counting. The first assignment prints all prime numbers between 1-25. The second finds the factorial of a given number. The third identifies Armstrong numbers between 0-999.

Uploaded by

mack
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
66 views5 pages

Abhishek Kumar Assignment

The document contains 8 coding assignments involving prime numbers, factorials, Armstrong numbers, square sums, Fibonacci series, number reversal, palindrome checks, and prime counting. The first assignment prints all prime numbers between 1-25. The second finds the factorial of a given number. The third identifies Armstrong numbers between 0-999.

Uploaded by

mack
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 5

ASSIGNMENT

1)Prime number b/w 1 to 25

#incIude<stdio.h>
int main()

int num ,i;


for(num=1;num<=25;num++)
{
for(i=2; i<num; i++)
{
if (num % i==0)
break;
}
if (num==i)
printf("%d\t" ,num);
}
}
//2,3,5,7,11,13,17,19,23//

2)Finding Factorial of any number

#incIude<stdio.h>
int main()
{
int num ,i, fact=1;
printf("enter the number to find factorial\n");
scanf("%d", &num);

for(i=1; i<=num; i++)


{
fact=fact*i;
}
printf("the factorial of %d is %d:", num, fact);

//the factorial of 5 is 120//

3) Find Armstrong no b/w 0 to 999

#incIude<stdio.h>
int main()
{
int num, rem, sum, temp=0, count=0;
for(num=0;num<=999;num++)
{
sum=0;
temp=num;
for(;temp!=0;)
{
rem=temp%10;
temp=temp/10;
sum=sum+(rem*rem*rem);
}
if(num==sum)
{
printf("%d\t" ,num);
count++;
}
printf("\n the number of Armstrong number between 0-999 is %d",count);

//
0,1,153,370,371,407
the number of Armstrong number between 0-999 is 6 //

4)Find nth term square of natural no. and display their summation

#incIude<stdio.h>
int main()
{
int i, num, sum=0;
printf("enter the value to get square up to that number\n");
scanf("%d", &num);
for(i=1; i<=num; i++)
{
printf("square of %d is: %d\n",i,i”i);
sum=sum+(i*i);
}
printf("the sum of all square value is %d", sum);

}
//
enter the value to get square up to that number 5
square of 1 is: 1
square of 2 is: 4
square of 3 is: 9
square of 4 is: 16
square of 5 is: 25
the sum of all square value is 55
//
5)Nth terms of Fibonacci series

#incIude<stdio.h>
int main()
{
int i,num,n1=0,n2=1,n3;
printf("enter the number to get Fibonacci series\n");
scanf("%d", &num);
printf("%d,%d,",n1,n2);
for(i=2; i<num; i++)
{
n3=n1+n2;
printf("%d,",n3);
n1=n2;
n2=n3;
}
}
//enter the number to get Fibonacci series 10
0,1,1,2,3,5,8,13,21,34//

6)displaying the no. in reverse order

#incIude<stdio.h>
int main()
{
int num, reverse=0,rem;
printf("enter the number to get reversed of it\n");
scanf("%d", &num);
for (;num!=0;)
{
rem=num%10;
reverse=reverse”10+rem;
num=num/10;
}
printf("the reverse is %d", reverse);

//
enter the number to get reversed of it 12345
the reverse is 54321
//
7)To find whether the no. is palindrome or not

#incIude<stdio.h>
int main()

{
int num, reverse=0,rem,temp;
printf("enter the number to check whether it is palindrome or not \n");
scanf("%d", &num);
temp=num;
for(;num!=0;)
{
rem=num%10;
reverse=reverse*10+rem;
num=num/10;
}
if(reverse==temp)
printf("it is palindrome");
else
printf("it is not palindrome");

//enter the number to check whether it is palindrome or not 123321


it is palindrome

enter the number to check whether it is palindrome or not 12332


it is not palindrome//

8)Program for counting first 25 prime number?

#incIude<stdio.h>
int main()
{
int num ,i, count=0;
for(num=1;num<=25;num++)
{
for(i=2; i<num; i++)
{
if (num % i==0)
break;
}
if (num==i)
count++;
}
printf("total prime number between 1-25 is %d", count);
}

//total prime number between 1-25 is 9//

You might also like