[go: up one dir, main page]

0% found this document useful (0 votes)
15 views3 pages

unit-II Programs

The document contains three C programs: one to check if a number is a palindrome, another to determine if a number is prime, and a third to verify if a number is an Armstrong number. Each program prompts the user for input and outputs the result based on the respective mathematical properties. The code snippets include necessary logic and loops to perform the calculations.

Uploaded by

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

unit-II Programs

The document contains three C programs: one to check if a number is a palindrome, another to determine if a number is prime, and a third to verify if a number is an Armstrong number. Each program prompts the user for input and outputs the result based on the respective mathematical properties. The code snippets include necessary logic and loops to perform the calculations.

Uploaded by

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

Palindrome

#include <stdio.h>

int main()

int n, rev= 0, rem,original;

printf("Enter an integer: ");

scanf("%d", &n);

original=n;

// reversed integer is stored in reversed variable

while (n != 0)

rem=n%10;

rev=rev* 10+rem;

n=n/10;

// palindrome if orignal and reversed are equal

if (original==rev)

printf("%d is a palindrome.", original);

else

printf("%d is not a palindrome.", original);

return 0;

}
PRIME NUMBERS

#include <stdio.h>

int main()

int i,n;

int prime=1;

printf("enter n value");

scanf("%d",&n);

for(i=2;i<n;i++)

if((n%i)== 0)

prime=0;

if(prime==1)

printf("%d is prime number", n);

else

printf("%d is not a prime number",n);

return 0;

Armstrong number :A number is called as an Armstrong number if the sum of the cubes
of its digits is equal to the number itself.

#include <stdio.h>
void main()
{

int num,x;
int sum = 0;
printf("Enter a number:");
scanf("%d",&num);
int i = num;
while(i!=0)
{
x = i%10;
sum= sum + x*x*x;
i = i/10;
}

if(num==sum)
{
printf ("%d is an Armstrong Number.", num);
}

else
{
printf ("%d is not an Armstrong Number.", num);
}
}

You might also like