C program "palindrome"

Reply

Join Date: Oct 2009
Posts: 21
Reputation: needhelpe is an unknown quantity at this point 
Solved Threads: 0
needhelpe needhelpe is offline Offline
Newbie Poster

C program "palindrome"

 
-2
  #1
Oct 14th, 2009
hello! I am having problems with a palindrome program. I have to input an integer between 1 and 9. and then the output has to be:

for example if I input 4:
output: 1234321

if I input 5:
output: 123454321

if 1
output: 1
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 1,859
Reputation: twomers has a spectacular aura about twomers has a spectacular aura about twomers has a spectacular aura about 
Solved Threads: 55
twomers's Avatar
twomers twomers is offline Offline
Posting Virtuoso
 
0
  #2
Oct 14th, 2009
ANd the problem is?
I blag!?
"Mr Kitty, you have to live in the attic now. Here, write a diary."
I am the Walrus!
Reply With Quote Quick reply to this message  
Join Date: Oct 2009
Posts: 21
Reputation: needhelpe is an unknown quantity at this point 
Solved Threads: 0
needhelpe needhelpe is offline Offline
Newbie Poster
 
0
  #3
Oct 14th, 2009
Originally Posted by needhelpe View Post
hello! I am having problems with a palindrome program. I have to input an integer between 1 and 9. and then the output has to be:

for example if I input 4:
output: 1234321

if I input 5:
output: 123454321

if 1
output: 1
the problem is that I don't know how to do it. I tried but I don't get it. can somebody help me, my mind is going to blow!!!
Reply With Quote Quick reply to this message  
Join Date: Oct 2009
Posts: 21
Reputation: needhelpe is an unknown quantity at this point 
Solved Threads: 0
needhelpe needhelpe is offline Offline
Newbie Poster
 
0
  #4
Oct 14th, 2009
Originally Posted by twomers View Post
ANd the problem is?
that I have been trying but I don't get it. my mind is going to explode!!!
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 1,859
Reputation: twomers has a spectacular aura about twomers has a spectacular aura about twomers has a spectacular aura about 
Solved Threads: 55
twomers's Avatar
twomers twomers is offline Offline
Posting Virtuoso
 
0
  #5
Oct 14th, 2009
Well, what to you have so far? Code wise?
I blag!?
"Mr Kitty, you have to live in the attic now. Here, write a diary."
I am the Walrus!
Reply With Quote Quick reply to this message  
Join Date: Oct 2009
Posts: 21
Reputation: needhelpe is an unknown quantity at this point 
Solved Threads: 0
needhelpe needhelpe is offline Offline
Newbie Poster
 
0
  #6
Oct 14th, 2009
Originally Posted by twomers View Post
Well, what to you have so far? Code wise?
#include <stdio.h>
int main()
{
int n
printf ("Enter digit: ");
scanf ("%d",&n);

if ((n < 0) || (n > 9))
{
printf("number not in range\n");
}
else
printf("n-1...n...n-1")
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 1,859
Reputation: twomers has a spectacular aura about twomers has a spectacular aura about twomers has a spectacular aura about 
Solved Threads: 55
twomers's Avatar
twomers twomers is offline Offline
Posting Virtuoso
 
0
  #7
Oct 14th, 2009
Ok. Consider using two for loops. One to count up to a number and one to count down. Print the looping variable.
I blag!?
"Mr Kitty, you have to live in the attic now. Here, write a diary."
I am the Walrus!
Reply With Quote Quick reply to this message  
Join Date: Oct 2009
Posts: 21
Reputation: needhelpe is an unknown quantity at this point 
Solved Threads: 0
needhelpe needhelpe is offline Offline
Newbie Poster
 
0
  #8
Oct 14th, 2009
Originally Posted by twomers View Post
Ok. Consider using two for loops. One to count up to a number and one to count down. Print the looping variable.
something like:
for (count = 1; count <=n; count = count + 1)
for(count=1; count>=n; count = count - 1)
printf(ā€œ%dā€, count);

?
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 1,859
Reputation: twomers has a spectacular aura about twomers has a spectacular aura about twomers has a spectacular aura about 
Solved Threads: 55
twomers's Avatar
twomers twomers is offline Offline
Posting Virtuoso
 
0
  #9
Oct 14th, 2009
Sorta. But you don't want to nest the loops. printf() after each for loop.
for ( counting up )
printf();

for ( counting down )
printf()
The second loop will be going from the upper limit to 1, remember. So limits of count=n; count>=1; count-- would make more sense.
I blag!?
"Mr Kitty, you have to live in the attic now. Here, write a diary."
I am the Walrus!
Reply With Quote Quick reply to this message  
Join Date: Oct 2009
Posts: 21
Reputation: needhelpe is an unknown quantity at this point 
Solved Threads: 0
needhelpe needhelpe is offline Offline
Newbie Poster
 
0
  #10
Oct 14th, 2009
Originally Posted by twomers View Post
Sorta. But you don't want to nest the loops. printf() after each for loop.
for ( counting up )
printf();

for ( counting down )
printf()
The second loop will be going from the upper limit to 1, remember. So limits of count=n; count>=1; count-- would make more sense.
like:
#include <stdio.h>
int main()
{
int n
printf ("Enter digit: ");
scanf ("%d",&n);

if ((n < 0) || (n > 9))
{
printf("number not in range\n");
}
else


for (count = 1; count <=n; count = count + 1);
pintf("%d",count);
for(count=n; count>=1; count = count - 1)
printf(ā€œ%dā€, count);

return 0;
}

?
Reply With Quote Quick reply to this message  
Reply

Message:



Similar Threads
Other Threads in the C Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC