标签:
1、首先练习鸡兔同笼问题:
1 #include <iostream> 2 using namespace std; 3 int main() 4 { 5 int a,b,x,y; 6 cout << "请输入鸡和兔的总数:"; 7 cin >> a; 8 cout << "请输入鸡和兔的总脚数:"; 9 cin >> b; 10 x = (4 * a - b) / 2; 11 y = (b - 2 * a) / 2; 12 cout << "鸡的总数为:" << x << endl; 13 cout << "鸭的总数为:" << y << endl; 14 return 0; 15 }
说实话,cnbolog的代码字体看起来不是很满意。
2、输出成绩求平均值问题
1 #include <iostream> 2 #include <iomanip> 3 using namespace std; 4 int main() 5 { 6 // 输入考试成绩求平均值问题 7 // include<iomanip> 8 float score1,score2,score3,average; 9 cout << "请输入三门课程的考试成绩:" << endl; 10 cin >> score1 >> score2 >> score3; 11 average = (score1 + score2 + score3) / 3; 12 cout << setw(10) << "科目" << setw(12) << "成绩" << endl; 13 cout << setw(10) << "英语" << setw(12) << score1 << endl; 14 cout << setw(10) << "程序设计" << setw(12) << score2 << endl; 15 cout << setw(10) << "大学物理" << setw(12) << score3 << endl; 16 cout << fixed; 17 cout.precision(2); 18 cout << "该生的平均成绩为:" << average << endl; 19 return 0; 20 }
3、leap year or not
1 int year; 2 cout << "Enter the year:" << endl; 3 cin >> year; 4 if (year%4==0 && year%100!=0 || year%400==0) 5 { 6 cout << year << " is a leap year. " << endl; 7 } 8 else 9 { 10 cout << year << " is not a leap year. " << endl; 11 } 12 return 0;
标签:
原文地址:http://www.cnblogs.com/Cyrus-Drew/p/4307677.html