how can I output 123454321, if i input 5. and 1234321 if i input 4?

10
Contributors
12
Replies
15
Views
8 Years
Discussion Span
Last Post by Nick Evan
Featured Replies
• 1

Ok here we go: - you're missing the semi-colon after your declaration of the variable [B]n[/B]. - you haven't declared the variables [B]i[/B] and [B]count[/B]. And you don't need the [B]count [/B]variable. Just print the value of [B]i[/B]. - remove the semi-colons from the end of your for statements - …

• 2
Salem 5,138   8 Years Ago

> in a single loop without any conditional statement. But a loop without any conditional statement either runs zero times, or forever. Anyway, here's one answer - have fun explaining it ;) Or learn something, by trying to unravel it :) [code] #include <stdio.h> int main ( ) { int …

• 1

Good job man! After only 10 months you came up with an answer in the wrong language. :icon_wink: Closed.

use a loop that counts from 1 to the number you enter, then another loop that counts backwards back down to 1. Print the loop counter.

how can I output 123454321, if i input 5. and 1234321 if i input 4?

you could do that by following below

``````for(start = 1; start <= conut; start++)
putchar( start + '0' );
for(start = start -2; start > 0; start--)
putchar( start + '0' );``````

Haven't tested it yet, but it could be similar to this :

``````int M = 5;
int i = 1;
while(i <= M) cout << i++ <<" ";  //print from 1 to 5
while(--i > 0) cout << i << " "; //print from 4 to 1``````

Edited by firstPerson: n/a

you could do that by following below

``````for(start = 1; start <= conut; start++)
putchar( start + '0' );
for(start = start -2; start > 0; start--)
putchar( start + '0' );``````

this is what I have so far, but does not work:
#include <stdio.h>
int main()
{
int n
printf ("Enter digit: ");
scanf ("%d",&n);

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

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

return 0;
}

Ok here we go:

- you're missing the semi-colon after your declaration of the variable n.

- you haven't declared the variables i and count. And you don't need the count variable. Just print the value of i.

- remove the semi-colons from the end of your for statements - you have empty for statements here and that is why you are not getting the desired output.

- when counting back, initialize i to n-1.

- the code to print the required output should be part of an else clause - that way, if invalid data is entered, you don't end up printing erroneous values after printing your error message.

- in the future, use code tags when posting code - read the information at this link to learn how to do this:

How can i print 123454321 (on input 5) in a single loop without any conditional statement...???

How can i print 123454321 (on input 5) in a single loop without any conditional statement...???

Is this a joke?

no... m serious...!!!

> in a single loop without any conditional statement.
But a loop without any conditional statement either runs zero times, or forever.

Anyway, here's one answer - have fun explaining it ;)
Or learn something, by trying to unravel it :)

``````#include <stdio.h>
int main ( ) {
int num = 5;
int i = 1, j = 1;
while ( i > 0 ) {
putchar(i|(0x60>>(i/i)));
i+=i/i-((i<<(i/i))/i)*(j++-num>=0);
}
return 0;
}``````

I know I did, obfuscating it :twisted:

thanks dude... :)
this is really great...

No problem - you didn't learn anything
``````public static void main(String a[]) {
int num = 20;
int sequence;
for (int i = 1; i < 2*num; i++) {
sequence = i>num ? 2*num - i : i;
System.out.print(sequence);
}
}``````

Edited by Nick Evan: n/a

Good job man! After only 10 months you came up with an answer in the wrong language. :icon_wink: Closed.