Question #16935

Write an algorithm that determines the day number ( 1 to 366) in a year for a date that is provided as input data. For example, 1/1/1994 is the day number 1, while, 31/12/1994 is the day number 366 because 1994 is a leap year.
Hint: A year is a leap year if it is devisable by 4 except any year that is divisible by 100 is a leap year if it is divisible by 400.
( sorry i want it in flowchart and pseudo-code)

Expert's answer

#include<iostream>

using namespace std;

char msg[200], inv[200];

int y, m, d, n=0, i;

void main(){

cout<<"enter the year: ";

cin>>y;

cout<<"enter the month: ";

cin>>m;

cout<<"enter the day: ";

cin>>d;

n += d;

for (i=1; i<m; i++){

& if (i==1) n+=31;

& if ((y%4==0)&&(i==2)) n+=29;

& else if (i==2) n+=28;

& if (i==3) n+=31;

& if (i==4) n+=30;

& if (i==5) n+=31;

& if (i==6) n+=30;

& if (i==7) n+=31;

& if (i==8) n+=31;

& if (i==9) n+=30;

& if (i==10) n+=31;

& if (i==11) n+=30;

}

cout<<"the day number is "<<n<<".\n";

}

using namespace std;

char msg[200], inv[200];

int y, m, d, n=0, i;

void main(){

cout<<"enter the year: ";

cin>>y;

cout<<"enter the month: ";

cin>>m;

cout<<"enter the day: ";

cin>>d;

n += d;

for (i=1; i<m; i++){

& if (i==1) n+=31;

& if ((y%4==0)&&(i==2)) n+=29;

& else if (i==2) n+=28;

& if (i==3) n+=31;

& if (i==4) n+=30;

& if (i==5) n+=31;

& if (i==6) n+=30;

& if (i==7) n+=31;

& if (i==8) n+=31;

& if (i==9) n+=30;

& if (i==10) n+=31;

& if (i==11) n+=30;

}

cout<<"the day number is "<<n<<".\n";

}

## Comments

## Leave a comment