static void Main(string[] args) { int m = 1236578; int[] ms = new int[m.ToString().Length]; Rev(m.ToString().Length, m, ref ms); for (int i = 0; i < m.ToString().Length; i++) Console.Write("{0}", ms[i]); Console.ReadLine(); } private static void Rev(int len, int m, ref int[] ms) { if (m / 10 > 0) { ms[len - m.ToString().Length] = m % 10; Rev(len, m / 10, ref ms); return; } ms[len - m.ToString().Length] = m % 10; }
#include <stdio.h>
#include <string.h>
void fun(int n, char a[])
{
static int i = 0;
if(n < 10) a[i++] = n + '0';
else
{ a[i++] = n % 10 + '0';
fun(n / 10, a);
}
}
void main()
{
int x;
char a[10];
memset(a, 0, 10);
scanf("%d", &x);
fun(x, a);
for(int i = 0; i <10; ++i)
printf("%c", a[i]);
}
先寫第一個
#include "stdio.h"
main()
{
int n,m;
int sum=0;
printf("input a number:\n");
scanf("%d",&n);
while(n/10!=0)
{
m=n%10;
sum=sum+m;
n=n/10;
}
sum=sum+n;
printf("sum is:%d",sum);
getch();
}