第一题
1. #include<iostream> 2. using namespace std; 3. int main() 4. { 5. cout<<"Hello, world!"<<endl; 6. return 0; 7. }
第二题
1. #include<iostream> 2. using namespace std; 3. int main() 4. { 5. string a; 6. cin>>a; 7. cout<<a<<",欢迎您加入C++课程学习编程,祝您收获满满!"<<endl; 8. return 0; 9. }
第三题
1. #include<iostream> 2. using namespace std; 3. int main() 4. { 5. int A,B,sum; 6. cin>>A>>B; 7. sum=A+B; 8. cout<<sum<<endl; 9. return 0; 10. }
第四题
1. #include<iostream> 2. using namespace std; 3. int main() 4. { 5. int sum; 6. for(int i=1;i<=100;i++) 7. { 8. sum = sum+i; 9. } 10. cout<<sum<<endl; 11. return 0; 12. }
第五题
1. #include<iostream> 2. using namespace std; 3. int main() 4. { 5. int a,b,sum; 6. cin>>a>>b; 7. for(int i=a;i<=b;i++) 8. { 9. sum=sum+i; 10. } 11. cout<<sum<<endl; 12. return 0; 13. }
第六题
1. #include<iostream> 2. using namespace std; 3. int main() 4. { 5. int a; 6. cin>>a; 7. if(a==0) 8. { 9. cout<<"天纵奇才,吾辈楷模"<<endl; 10. } 11. else if(a==1) 12. { 13. cout<<"疯...凡是伟大的天才都带有疯狂的特征"<<endl; 14. } 15. else 16. { 17. cout<<"不是天才也不是疯子?呜呜呜,不要为难人家好不啦!"<<endl; 18. } 19. return 0; 20. }
第七题
1. #include <bits/stdc++.h> 2. using namespace std; 3. int main () { 4. int n,ans=0,a[26]; 5. cin>>n; 6. for(int i=0;i<n;i++) 7. { 8. cin>>a[i]; 9. ans+=a[i]; 10. } 11. sort(a,a+n); 12. for(int i=n-1;i>=0;i--) 13. { 14. cout<<a[i]; 15. if(i) cout<<" "; 16. } 17. printf("\n%d %.2f",ans,ans*1.0/n); 18. }
第八题
1. #include<iostream> 2. using namespace std; 3. int sum(int x,int y) 4. { 5. int sum=0; 6. sum=x+y; 7. return sum; 8. } 9. int sumab(int x,int y) 10. { 11. int sum=0; 12. if(x>y)swap(x,y); 13. for(int i=x;i<=y;i++) 14. { 15. sum=sum+i; 16. } 17. return sum; 18. } 19. int main() 20. { 21. int n,a,b; 22. cin>>n; 23. for(int i=0;i<=n-1;i++) 24. { 25. cin>>a>>b; 26. cout<<sum(a,b)<<" "<<sumab(a,b)<<endl; 27. } 28. return 0; 29. }
第九题
1. #include <iostream> 2. using namespace std; 3. 4. int main() 5. { 6. cout<<"Data type Number of bytes"<<endl; 7. cout<<"------------- --------------------"<<endl; 8. cout<<"char "<<sizeof(char)<<endl; 9. cout<<"short int "<<sizeof(short int)<<endl; 10. cout<<"int "<<sizeof(int)<<endl; 11. cout<<"long int "<<sizeof(long int)<<endl; 12. cout<<"long long "<<sizeof(long long)<<endl; 13. cout<<"float "<<sizeof(float)<<endl; 14. cout<<"double "<<sizeof(double)<<endl; 15. cout<<"long double "<<sizeof(long double); 16. 17. return 0; 18. }