The user enters a number. Print the entire number of this number, each with a new line. Example

432567
four
3
2
five
6

#include "stdafx.h" int _tmain(int argc, _TCHAR* argv[]) { int A,i; printf("Vvod chisla A\n"); scanf("\n%d",&A); printf("%d\n",A); return 0; } 

Closed due to the fact that the issue is too general for the participants Dmitriy Simushev , Vladimir Martyanov , dirkgntly , user207618, Grundy Aug 29 '16 at 19:16 .

Please correct the question so that it describes the specific problem with sufficient detail to determine the appropriate answer. Do not ask a few questions at once. See “How to ask a good question?” For clarification. If the question can be reformulated according to the rules set out in the certificate , edit it .

  • one
    And what exactly did you fail? - pavel
  • #include "stdafx.h" int _tmain (int argc, _TCHAR * argv []) {int A, i; printf ("Vvod chisla A \ n"); scanf ("\ n% d", & A); return 0; - Stepan Kotov
  • Immediately visible to those who use ms vc ++ :) - pavel
  • How can I display each number from the new line? - Stepan Kotov
  • one
    You have the same code, which would have something to do, not in the program. What do you expect from it? - Pavel Gurkov

2 answers 2

The following code section displays the digits of the integer in reverse order, starting with the last digit:

 int digit = 0; while (number >= 1) { // записываем в переменную последнюю цифру числа (остаток от деления на 10) digit = number % 10; // выводим цифру на экран printf("%d\t", digit); // делим число на 10, чтобы избавиться от последней цифры number = number / 10; } 

You have to figure out how to bring them in the order you need.

    Well, for example,

     printf("%d\n",A); 

    replaced by

     char buf[40], *с; sprintf(buf,"%d",A); for(с = buf; *c; ++c) printf("%c\n",*c); 

    About safety, efficiency, etc. I can not tell :)

    Update Since I was told that this is too difficult - here’s another option:

     int main() { int c; printf("Vvedite chislo A: "); for(c = getchar(); c != EOF && c != '\n'; c = getchar()) { putchar(c); putchar('\n'); } } 

    :)

    • Difficult for a beginner who barely brought the number, do not you think? :) - Sleepy Panda
    • @SleepyPanda No, I do not find. Suggest it easier - using the stack, for example :) Or with recursion. As for me - I gave the simplest method. Even easier - just enter the number not as a number, but as a string and work directly with the entered characters. - Harry