#include <stdlib.h>
#include <iostream>
using namespace std;
int a, b;
int main()
{
int x, y, z;
z = 10;
cout << "Please input a Digit:" << "\n";
while (1)
{
cin >> x;
if (x == 0)break;
while (1)
{
y = x % z;
a = a + y;
x = x / 10;
if (x == 0)
{
if (a < 10) break;
x = a;
a = 0;
}
}
cout << a << "\n";
x =a = b = y = 0;
}
system("pause");
return 0;
}
#include <iostream>
using namespace std;
int a, b;
int main()
{
int x, y, z;
z = 10;
cout << "Please input a Digit:" << "\n";
while (1)
{
cin >> x;
if (x == 0)break;
while (1)
{
y = x % z;
a = a + y;
x = x / 10;
if (x == 0)
{
if (a < 10) break;
x = a;
a = 0;
}
}
cout << a << "\n";
x =a = b = y = 0;
}
system("pause");
return 0;
}
沒有留言:
張貼留言
歡迎指教或發問