87 lines
1.4 KiB
C++
87 lines
1.4 KiB
C++
|
//do...while
|
||
|
//计算各个数位之和
|
||
|
|
||
|
#include<iostream>
|
||
|
using namespace std;
|
||
|
|
||
|
void while_1();
|
||
|
void do_while();
|
||
|
void huiwenshu();
|
||
|
|
||
|
int main(){
|
||
|
|
||
|
int choose;
|
||
|
cout <<"选择"<<endl;
|
||
|
cout <<"1.do...while"<<endl;
|
||
|
cout <<"2.while"<<endl;
|
||
|
cout <<"3.回文数"<<endl;
|
||
|
cin >>choose;
|
||
|
|
||
|
if (choose == 2)
|
||
|
{
|
||
|
while_1();
|
||
|
}else if (choose == 1)
|
||
|
{
|
||
|
do_while();
|
||
|
}else if (choose == 3)
|
||
|
{
|
||
|
huiwenshu();
|
||
|
}else{
|
||
|
cout <<"输入错误!"<<endl;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void do_while(){
|
||
|
cout <<"已进入do..while"<<endl;
|
||
|
int CIN,andy;
|
||
|
int a,b,c;
|
||
|
|
||
|
do
|
||
|
{
|
||
|
cin >>CIN;
|
||
|
a = CIN / 100;
|
||
|
b= CIN / 10 % 10;
|
||
|
c = CIN % 10;
|
||
|
|
||
|
andy = a+b+c;
|
||
|
cout <<andy<<endl;
|
||
|
} while (CIN > 0);
|
||
|
}
|
||
|
|
||
|
void while_1(){
|
||
|
cout <<"已进入while"<<endl;
|
||
|
int CIN2,andy,a,b,c;
|
||
|
|
||
|
while (CIN2 > 0)
|
||
|
{
|
||
|
cin >>CIN2;
|
||
|
a = CIN2 / 100;
|
||
|
b = CIN2 / 10 % 10;
|
||
|
b = CIN2 % 10;
|
||
|
andy = a+b+c;
|
||
|
cout <<andy<<endl;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void huiwenshu(){
|
||
|
while (true)
|
||
|
{
|
||
|
int n,ge,number = 0,number2;
|
||
|
cin >>n;
|
||
|
number2 = n;
|
||
|
do
|
||
|
{
|
||
|
ge = n%10;
|
||
|
number = number * 10 + ge;
|
||
|
n = n / 10;
|
||
|
} while (n > 0);
|
||
|
|
||
|
if (number != number2)
|
||
|
{
|
||
|
cout <<"NO!"<<endl;
|
||
|
}else
|
||
|
{
|
||
|
cout <<"YES!"<<endl;
|
||
|
}
|
||
|
}
|
||
|
}
|