Created
February 4, 2025 08:02
-
-
Save Fatima-progmmer/15eeb6fe0a588271aa1c94b637d155dc to your computer and use it in GitHub Desktop.
How to use array to add number of days that you spend using for loop
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
int main() | |
{ | |
int day, month, total_day; | |
int days_per_month[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; | |
cout << "Enter month(1 to 12) :"; | |
cin >> month; | |
cout << "Enter day (1 to 30) :"; | |
cin >> day; | |
total_day = day; | |
for (int j = 0; j < month - 1; j++) | |
total_day += days_per_month[j]; | |
cout << "Total days from start of the year is :" << total_day << endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment