1, first practice chicken and rabbit cage problem:
1#include <iostream>2 using namespacestd;3 intMain ()4 {5 inta,b,x,y;6cout <<"Please enter the total number of chickens and rabbits:";7CIN >>A;8cout <<"Please enter the total number of feet for chickens and rabbits:";9CIN >>b;Tenx = (4* A-B)/2; Oney = (b-2* a)/2; Acout <<"The total number of chickens is:"<< x <<Endl; -cout <<"The total number of ducks is:"<< y <<Endl; - return 0; the}
To be honest, Cnbolog's code fonts don't look very satisfying.
2, the output results to find the average problem
1#include <iostream>2#include <iomanip>3 using namespacestd;4 intMain ()5 {6 //Enter the test results to find the average problem7 //include<iomanip>8 floatScore1,score2,score3,average;9cout <<"Please enter the exam results for each of the courses:"<<Endl;TenCIN >> Score1 >> score2 >>Score3; OneAverage = (Score1 + score2 + score3)/3; Acout << SETW (Ten) <<"Subjects"<< SETW ( A) <<"Achievements"<<Endl; -cout << SETW (Ten) <<"English"<< SETW ( A) << Score1 <<Endl; -cout << SETW (Ten) <<"Programming"<< SETW ( A) << Score2 <<Endl; thecout << SETW (Ten) <<"University Physics"<< SETW ( A) << Score3 <<Endl; -cout <<fixed; -Cout.precision (2); -cout <<"The average result of the student is:"<< Average <<Endl; + return 0; -}View Code
3, leap year, or not
1 intYear ;2cout <<"Enter the year:"<<Endl;3CIN >>Year ;4 if(year%4==0&& year% -!=0|| year% -==0)5 {6cout << Year <<"Is a leap year."<<Endl;7 }8 Else9 {Tencout << Year <<"Is isn't a leap year."<<Endl; One } A return 0;
C + + Learning (i)--Basic program design