Simple C++ Program
Posted: Thu Jan 15, 2015 9:18 pm
Hello World, here is a simple C++ program, compile and execute it to see what it does!
- #include<iostream>
- #include<string>
- using namespace std;
- int main ()
- {
- /* cout<< "Hello world"<<endl; // Prints Hello world
- cout<< "I am a C++ Program"<<endl;
- for (int i = 1; i<= 100; i++) if (i%5==0) cout<<"i = "<<i<<endl;
- return 0; //Terminate the program
- */
- /* cout <<"What the Hell!"<<endl;
- const int rows = 3;
- const int cols = 6;
- int numbers[rows][cols];
- int Table[rows][cols] = {{1,2,3,4,5,6},{5,4,3,6,7,8}, {9,6,7,5,4,3}};
- for (int r = 0; r<rows; ++r)
- for (int c = 0; c<cols; ++c)
- numbers[r][c] = 0;
- for(int r = 0; r<rows; ++r) {
- for (int c = 0; c<cols; ++c)
- cout<<" "<<numbers[r][c]<<" ";
- cout<<endl;
- }
- return 0;
- */
- const int rows = 6;
- const int cols = 6;
- int Total = 0;
- double average = 0.0;
- int grades[rows][cols] = {{89, 98, 78, 79, 100, 96}, //initialization of 6 by 6 array
- {97, 87, 77, 80,90, 95},
- {86, 88, 99, 94, 92, 84},
- {75, 85, 81, 83, 98, 90},
- {80, 76, 77, 89, 96, 77},
- {90,80,78,91, 93, 100}};
- for (int r = 0; r < rows; ++r) {cout<<"Students"<<r+1<<"Marks"<<" :";
- for (int c = 0; c < cols; ++c){
- cout<<grades[r][c]<<" ";
- Total + = grades[r][c];
- }
- average = Total/cols;
- cout<<"Average is"<<average<<endl;
- Total = 0;
- average = 0.0;
- }
- return 0;
- }