Accenture Coding Question 13
Coding Question 13
Instructions: You are required to write the code. You can click on compile and run anytime to check compilation/execution status. The code should be logically/syntactically correct.
Question: Write a program in C such that it takes a lower limit and upper limit as inputs and print all the intermediate pallindrome numbers.
Test Cases:
TestCase 1:
Input :
10 , 80
Expected Result:
11 , 22 , 33 , 44 , 55 , 66 , 77.
Test Case 2:
Input:
100,200
Expected Result:
101 , 111 , 121 , 131 , 141 , 151 , 161 , 171 , 181 , 191.
C
C++
Java
Python
C
#include<stdio.h>
int main()
{
int i, n, reverse, d,f,l;
printf("enter the starting \n",f);
scanf("%d",&f);
printf("enter the ending\n",l);
scanf("%d",&l);
for (i = f; i <= l; i++)
{
reverse = 0;
n = num;
while (n != 0)
{
d = n % 10;
reverse = reverse * 10 + d;
n = n / 10;
}
if (i == reverse)
printf("%d ",i);
}
return 0;
}
C++
#include<iostream>
using namespace std;
int reverse(int);
int main()
{
int i,f,l;
cout<<"enter the starting \n",f;
cin>>f;
cout<<"enter the ending\n",l;
cin>>l;
for (i = f; i <= l; i++)
{
if(i==reverse(i))
cout<<" "<<i;
}
return 0;
}
int reverse(int a)
{
int n=0,d=0,rev=0;
n = a;
while (n != 0)
{
d = n % 10;
rev = rev * 10 + d;
n = n / 10;
}
return rev;
}
Java
import java.util.Scanner;
import java.util.ArrayList;
import java.util.Collections;
public class Main {
static int pallindrome(int no1) {
int rem=0;
int div = no1;
while (div != 0)
{
int r = div % 10;
rem = (rem * 10) + r;
div = div / 10;
}
return rem;
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter Upper and Lower Limit");
int ul = sc.nextInt();
int ll = sc.nextInt();
for (int i = ul; i <= ll; i++) {
if(i==pallindrome(i))
System.out.println(i);
}
}
}
Python
# Palindrome Number Checking
first_number = int(input())
second_number = int(input())
for i in range(first_number, second_number+1):
reverse = 0
temp = i
while temp != 0:
remainder = temp % 10
reverse = (reverse * 10)+remainder
temp = temp // 10
if i == reverse:
print(reverse, end=" ")