Program to store temperature different cities for a week and display it using Two Dimensional Array.
To understand this Program to store temperature different cities, you can learn C++ programming.
- Two Dimensional Array
- C++ for loop
Program to store temperature of two different cities for a week and display it.
#include <iostream> using namespace std; const int CITY = 2; const int WEEK = 7; int main() { int temperature[CITY][WEEK]; cout << "Enter all temperature for a week of first city and then second city. \n"; // Inserting the values into the temperature array for (int i = 0; i < CITY; ++i) { for(int j = 0; j < WEEK; ++j) { cout << "City " << i + 1 << ", Day " << j + 1 << " : "; cin >> temperature[i][j]; } } cout << "\n\nDisplaying Values:\n"; // Accessing the values from the temperature array for (int i = 0; i < CITY; ++i) { for(int j = 0; j < WEEK; ++j) { cout << "City " << i + 1 << ", Day " << j + 1 << " = " << temperature[i][j] << endl; } } return 0; }
Output
Enter all temperature for a week of first city and then second city. City 1, Day 1 : 32 City 1, Day 2 : 33 City 1, Day 3 : 32 City 1, Day 4 : 34 City 1, Day 5 : 35 City 1, Day 6 : 36 City 1, Day 7 : 38 City 2, Day 1 : 23 City 2, Day 2 : 24 City 2, Day 3 : 26 City 2, Day 4 : 22 City 2, Day 5 : 29 City 2, Day 6 : 27 City 2, Day 7 : 23 Displaying Values: City 1, Day 1 = 32 City 1, Day 2 = 33 City 1, Day 3 = 32 City 1, Day 4 = 34 City 1, Day 5 = 35 City 1, Day 6 = 36 City 1, Day 7 = 38 City 2, Day 1 = 23 City 2, Day 2 = 24 City 2, Day 3 = 26 City 2, Day 4 = 22 City 2, Day 5 = 29 City 2, Day 6 = 27 City 2, Day 7 = 23
Ask your questions and clarify your/others doubts on how to store the temperature of different cities by commenting. Documentation
Related Program
- C++ Program for selection Sort.
- C++ Program to store the value in Three Dimensional Array
- C++ Program to Find Transpose of a Matrix
- C++ Program to implement binary search
- C++ Program to create a Pyramid and Pattern.
- C++ Program to make a simple calculator using switch…case.
- C++ Program to Calculate Power of a Number
Please write to us at [email protected] to report any issue with the above content or for feedback.