close
#include <iostream>
#include <conio.h>
using namespace std;
int main()
{
cout<<"=歡迎光臨=\n";
cout<<"第一個C++程式\n";
/*輸入一個三位數的數字ex:123取其個十百位數做相加*/
cout<<"輸入三位數,取百十個位數加總";
int num1,get1,get2,get3,get4,get5,get6;
cin >> num1; //輸入一個三位數
get1 = num1/100;
get2 = num1%100/10;
get3 = num1%10; //or num1%100%10;
cout<<"總合"<<get1+get2+get3;
/*輸入一個六位數字ex:123456取其個十百千萬十萬位數做相加*/
cout<<"輸入六位數,取每位數做加總";
cin >> num1; //輸入一個六位數
get1=num1/100000;
get2=num1%100000/10000;
get3=num1%100000%10000/1000;
get4=num1%100000%10000%1000/100;
get5=num1%100000%10000%1000%100/10;
get6=num1%10;
cout <<"加總為"<<get1+get2+get3+get4+get5+get6;
getch();
return 0;
}
全站熱搜
留言列表