把一个整数转换成字符串,并倒序保存在字符数组s中--简单算法


源程序:

#include <stdio.h>

#include <stdlib.h>

#define N 80

char s[N];

void fun(long int n) 

{

  int i = 0;

  while (n > 0)

  {

    s[i] = n % 10 + '0';

    n = n / 10;

    i++;

  }

  s[i] = '\0';

}

void main()

{

  long int n = 12345;

  printf("***the origial data***\n");

  printf("n=%ld",n);

  fun(n);

  printf("\n%s",s);

  system("pause");

}

 

  


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM