1.
#include<iostream> using namespace std; int main() { int n,m; n = m = 0; int total = 0; cin >> n >> m ; for(int i = n; i <= m; i++) total += i; cout << n <<endl; cout << m << endl; cout << total <<endl; return 0; }
3.
#include<iostream> using namespace std; int main() { int n; n = 0; int total = 0; cin >> n; while(n != 0) { total += n; cout << total <<endl; cin >> n; } return 0; }
5.
#include<iostream> #include<string> using namespace std; int main() { char* month[12]; int num[12]; for(int i = 0; i < 12; i++) { cin >> month[i]; cin >> num[i]; } for( i = 0; i < 12; i++) { cout << month[i] << ": " << num[i]<<endl; } return 0; }
6.
#include<iostream> using namespace std; int main() { int num[3][12]; int year = 0; int year3 = 0; for(int i = 0; i < 3; i++) for(int j = 0; j < 12; j++) cin >> num[i][j]; for(i = 0; i < 3; i++) { for(int j = 0; j < 12; j++) { year += num[i][j]; } cout << year <<endl; year3 += year; } cout << year3 <<endl; return 0; }
7.
#include <iostream> #include <string> using namespace std; struct car{ string name; int year; }; void get(car *); void show(const car const *); void main57() { cout<<"How many cars do your wish to catalog?"; int num; cin>>num; car *c=new car[num]; for(int i=0;i<num;i++,c++) { cout<<"Car #"<<i+1<<":"<<endl; get(c); show(c); } cin.get(); } void get(car *c) { cin.get(); cout<<"Please enter the make:"; string name; getline(cin,name); cout<<"\nplease enter the years of make:"; int y; cin>>y; c->name=name; c->year=y; } void show(const car const *c) { cout<<"/nHere is your collection: "; cout<<c->year<<" "<<c->name<<endl; }