473,398 Members | 2,120 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

Number of palindromes between a and b

28
Expand|Select|Wrap|Line Numbers
  1. #include <stdio.h>
  2.  
  3. int main(void) {
  4.     int t,i,a,b,temp,rem,count,reverse;
  5.     scanf("%d",&t);
  6.     while(t--)
  7.     {
  8.         count=0;
  9.         scanf("%d",&a);
  10.         scanf("%d",&b);
  11.         for(i=a;i<=b;i++)
  12.         {
  13.             reverse=0;
  14.             temp=a;
  15.             while(temp!=0)
  16.             {
  17.                 rem=temp%10;
  18.                 reverse=reverse*10+rem;
  19.                 temp/=10;
  20.             }
  21.              printf("%d\t%d\n",i,reverse);
  22.             if(reverse==i) 
  23.             count++;
  24.         }
  25.         printf("%d\n",count);
  26.     }
  27.     return 0;
  28. }
on debugging found i am not able to reverse the string properly
Input:
1
10 15
output:
10 1
11 1
12 1
13 1
14 1
15 1
0
Apr 22 '14 #1

✓ answered by techboy

Solved temp=i;
silly me

3 1163
techboy
28
Solved temp=i;
silly me
Apr 22 '14 #2
weaknessforcats
9,208 Expert Mod 8TB
I'm not sure what you are trying to do. There's no string but only some ints.

A palindrome is not a reversal. It is a string that reads the same forwards and backwards: madam im adam.
Apr 22 '14 #3
techboy
28
I was programming for integer values that numbers as palindrome
Apr 22 '14 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: EAS | last post by:
Hey, I'm new to python (and programming in general) so I'll prolly be around here a lot... Anyways, I've found out how to make a "guess my number game" where the player guesses a number between...
11
by: don | last post by:
Ok, this is a homework assignment, but can you help me out anyway...... I need a routine for figuring out if a number inputted by the user is a prime number or not...... all I'm asking for is Not...
19
by: gk245 | last post by:
Trying to write a program that will figure out if a number is perfect or not. Here is my logic: 1) Read in the number 2) Split it up (number - 1) 3) Put all the split up numbers into an...
2
by: Gayani | last post by:
I want to know how to write a program to check wether the given string is a palindromes? create a program using C++.
6
by: Tmoney | last post by:
hello any guidance on this would be greatly appreciated( im very new to programming the more comments the better) the objective is to create a class that defines a single String data member. The...
19
Frinavale
by: Frinavale | last post by:
Filtering user input is extremely important for web programming. If input is left unfiltered users can input malicious code that can cripple your website. This article will explain how to make...
4
by: kryptor | last post by:
Hi there, Just need some help with this small program. Using recursion I'm trying to find out if a word (in this case a test word) is a palindrome or not. If it is it should return a 1 to...
0
by: 249740 | last post by:
A palindrome is a number/string that reads the same backwards and forward. For example: BOB, 3113 etc. Write a program that reads in an input value or string and outputs the number of possible...
4
by: JanineXD | last post by:
Hello, I already have the program ( convert number to words but only 0-999 ). I need it to be ( 0-9999 ). can you help me? package num2word; import java.util.Scanner;
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.