2407:c language exercise integer conversion to string

Source: Internet
Author: User

2407:c language exercise integer conversion to string time limit:1 Sec Memory limit:128 MB
submit:917 solved:416
[Submit] [Status] [Web Board] Description

Converts an integer n to a string using recursion. For example, enter 483 and the string "483" should be output. The number of bits of n is indeterminate and can be an integer of any number of digits.

Input

N

Output

The corresponding string

Sample Input
483
Sample Output
4 8 3
HINT

The main function is given below, and it is not required to include the following main function when committing

/* C code */

int main ()

{

int number;

scanf ("%d", &number);

if (number<0)

{

printf ("-");

Number=-number;

}

convert (number);

printf ("\ n");

return 0;

}




/* C + + code */

int main ()

{

int number;

cin>>number;

if (number<0)

{

cout<< "-";

Number=-number;

}

convert (number);

cout<<endl;

return 0;

}

#include <stdio.h>int convert (int n) {    int a[20],j;    int i=0;    while (n!=0)    {        a[i++]=n%10;        N=N/10;    }    for (j=i-1;j>=0;j--)        printf ("%d", A[j]);} int main () {    int number;    scanf ("%d", &number);    if (number<0)    {        printf ("-");        Number=-number;    }    convert (number);    printf ("\ n");    

  

2407:c language exercise integer conversion to string

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.