0% found this document useful (0 votes)
97 views4 pages

Factorial Number: AIM:-To Write A Program To Calculate The Factorial of The Given Number Using Functions. Algorithm

The document describes a C program to calculate the factorial of a given number and check if a number is a palindrome. It provides the aim, algorithm, program code, and output for both problems. The algorithm for factorial uses a for loop to multiply the input number by all integers from 1 to the given number. The palindrome algorithm uses a while loop to extract digits of a number into a reverse variable until the number is 0, then compares the reverse to the original to check for palindromic properties. The provided code implements these algorithms and outputs the correct results.

Uploaded by

Kr Ranjith
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)
97 views4 pages

Factorial Number: AIM:-To Write A Program To Calculate The Factorial of The Given Number Using Functions. Algorithm

The document describes a C program to calculate the factorial of a given number and check if a number is a palindrome. It provides the aim, algorithm, program code, and output for both problems. The algorithm for factorial uses a for loop to multiply the input number by all integers from 1 to the given number. The palindrome algorithm uses a while loop to extract digits of a number into a reverse variable until the number is 0, then compares the reverse to the original to check for palindromic properties. The provided code implements these algorithms and outputs the correct results.

Uploaded by

Kr Ranjith
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/ 4

Ex.

No:5a

FACTORIAL NUMBER

AIM:To write a program to calculate the factorial of the given number using functions.
ALGORITHM:
STEP 1: Start the program.
STEP 2: Enter a number.
STEP 3: Set a loop to find the factorial of the given no using Fact=fact*i
STEP 4: Print the factorial of the given number.
STEP 5: Stop the program.
Start

Read n

i1

Is i<=n

No
Yes
Fact=fact*i
I=i+1

PROGRAM:

Print fact
Stop

// FACTORIAL OF THE GIVEN NUMBER


#include<stdio.h>
main()
{
int fact=1,i,num;
printf("Enter the number");
scanf("%d",&num);
for(i=1;i<=num;i++)
{
fact=fact*i;
}
printf("the factorial of %dis %d",num,fact);
getch();
}
OUTPUT:
Enter the Number 5
The factorial of 5 is 120
RESULT:-

Thus the C program to calculate factorial of the given number using function is
Calculated successfully and verified.

Ex. No: 5b

REVERSE , PALINDROME OF A NUMBER

AIM:To write a C program to find the reverse of digits and Check whether the number is
Palindrome or not
ALGORITHM:STEP 1: Start the program.
STEP 2: Enter the number.
STEP 3: Set a loop upto the number is not equal to zero .
Remnum%10

Rnum rnum *10 +rem Num num/10

STEP 4: After the end of the loop print the reverse of the number.
STEP 5: Find whether the reverse no is equal to the actual given number to
check if it is a palindrome.
STEP 6: Stop the Program.
Start

Read num
A=num; rnum=0

No

Is i<num

Yes
fib=fib+a; Remnum%10
+rem Nu

Rnum rnum *10

Print rnum
Is a==r num

m num/10

Yes
Print Palindrome

Stop

No
Print it is not
Palindrome

PROGRAM:
// REVERSE, PALINDROME
#include<stdio.h>
#include<conio.h>
void main()
{
int a,num,sum=0,rnum=0,rem;
clrscr();
printf("\n Enter the No:");
scanf("%d",&num);
a=num;
while(num!=0)
{
rem=num%10;
rnum=rnum*10+rem;
num=num/10;
}
printf("\n The Reverse %ld is=%ld\n",a,rnum);
if(a==rnum)
printf("\n The Given number is a Palindrome");
else
printf("\n The Given number is not a Palindrome");
getch();
}
OUTPUT:Enter the No:12345
The Reverse 12345 is=54321
The Given number is not a Palindrome
RESULT:Thus the C program to find the reverse of digits and Check whether it is
a Palindrome or not is verified successfully.

You might also like