#include<iostream> using namespace std; int gcd(int,int); int main() { int i,n,a,b,c; cin>>i; for(n=1; n<=i; n++) { cin>>a>>b; c=gcd(a,b); cout<<c<<endl; } return 0; } int gcd(int m,int n) { int t,r; if(m<n) { t=m; m=n; n=t; } while(n!=0) { r=m%n; m=n; n=r; } return m; }
#include<iostream> using namespace std; int main() { int n,a; while(cin>>n) { a=n; while(a>0) { cout<<a%10<<' '; a=a/10; } cout<<"\n"; } return 0; }
参考解答:
#include<iostream> using namespace std; int main() { int x,A=0,B=0,C=0,D=0; while((cin>>x)&&!(x>10||x<0)) { switch(x) { case 0: case 1: case 2: case 3: case 4: D++; break; case 5: case 6: C++; break; case 7: case 8: B++; break; case 9: case 10: A++; } } cout<<"A:"<<A<<endl; cout<<"B:"<<B<<endl; cout<<"C:"<<C<<endl; cout<<"D:"<<D<<endl; return 0; }
================ 迂者 贺利坚 CSDN博客专栏=============== |== IT学子成长指导专栏 专栏文章的分类目录(不定期更新) ==| |== C++ 课堂在线专栏 贺利坚课程教学链接(分课程年级) ==| |== 我写的书——《逆袭大学——传给IT学子的正能量》 ==| ===== 为IT菜鸟起飞铺跑道,和学生一起享受快乐和激情的大学 =====
|