Q. Write a program to determine whether a given number is palindrome or not, using function and demonstrating with argument and with return value.
#BIT- 2018-Group A- Qno.1 b. 8 Marks - Solution, #BIT_FirstSem_2017_7N0_8 Marks_Solution #Assignment3bSolution
==>Code goes like this
#include<stdio.h>
int palindrome(int );
int main()
{
int num,original,rev;
printf("Enter a number:");
scanf("%d",&num);
original=num;
rev=palindrome(num); // calling function by passing values to function
if (original==rev) //Comparing original & reverse number
printf("\n Palindrome Number");
else
printf("\n Not Palindrome");
return 0;
}
int palindrome(int num) //receiving number passed by main function
{
int rev=0,rem;
while(num!=0) //reverse number checking starts
{
rem=num%10;
rev=rev*10+rem;
num=num/10;
} //reverse number checking ends
return rev; // returning values to main function
}
Output:
Output1:
I have used Dev CPP to compile this program.
If you are using Turbo C++ IDE, then use conio.h in link section after stdio.h
and use getch(); to hold the output screen, just before the end of main function.
If you have any confusion regarding the program, please, comment below.
Happy Coding !
Thank you
WAP to determine weather a given number is palindrome or not - C
9:14 PM
argument and function in C
,
AssignmentSolutionC
,
determine the given number is palindrome or not using function in C
,
OldQuestionSolution2017C
,
OldQuestionSoluton2018C
,
Palindrome checking in C
Edit
0 comments:
Post a Comment