Attachment 'indent.c'

Download

   1 #include <stdio.h> 
   2 
   3 int indent; /* отступ */ 
   4 
   5 int sumn( int n ) /* 25.1 */
   6 {
   7     int res; int i;
   8     indent += 2; /* indent = indent + 2, also -=, *=, /=, %/  */ 
   9 
  10     for (i = 0; i<indent; i++) printf( " " );
  11     printf( "sumn: start: n = %d, n%%10 = %d, n/10 = %d\n", n, n%10, n/10 );
  12 
  13     if (n == 0)
  14       res = 0;
  15     else
  16       res = n%10 + sumn( n / 10 );
  17 
  18     for (i = 0; i<indent; i++) printf( " " );
  19     printf( "sumn: will return %d\n", res );
  20     indent -= 2;
  21     return res;
  22 }
  23 
  24 int main (int argc, char **argv)
  25 {
  26   int n;
  27   indent = 0;
  28   scanf("%d", &n);
  29   printf( "sumn = %d\n", sumn( n ));
  30   return 0;
  31 }

Attached Files

To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.

You are not allowed to attach a file to this page.