数组方法
#include <bits/stdc++.h>
using namespace std;
int main()
{
long long int n, a[10], sum = 0, x;
cin >> n;
long long int b = n;
long long int i = 1;
if (b < 0)
{
cout << "-";
b = -b;
}
if (b == 0)
{
cout << 0 << endl;
return 0;
}
while (b != 0)
{
int c = b % 10;
b = b / 10;
a[i] = c;
i++;
sum++;
}
if (a[1] == 0)
x = 1;
for (int j = 1; j <= sum; ++j)
{
if (x == j && a[j] == 0)
{
x++;
continue;
}
else
cout << a[j];
}
return 0;
}
数字取余数
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n, m = 0;
cin >> n;
while (n != 0)
{
m = m * 10 + n % 10;
n = n / 10;
}
cout << m << endl;
return 0;
}