Answered! Write an ANSI-C pragram that reads input from the standard input about date, and then calculate the number days…

Write a C program

Write an ANSI-C pragram that reads input from the standard input about date, and then calculate the number days that has elapsed in the year. The program runs a loop for pre-defined N times. In each interaction, the user is prompted to enter Month-Day Year (three words separated by a dash and a space). For each input your program displays the approximate days that have elapsed from the start of the year.Answered! Write an ANSI-C pragram that reads input from the standard input about date, and then calculate the number days... 1

Don't use plagiarized sources. Get Your Custom Essay on
Answered! Write an ANSI-C pragram that reads input from the standard input about date, and then calculate the number days…
GET AN ESSAY WRITTEN FOR YOU FROM AS LOW AS $13/PAGE
Order Essay

Sample input/output

Answered! Write an ANSI-C pragram that reads input from the standard input about date, and then calculate the number days... 2

INCOMPLETE CODE

#include <stdio.h>

#define N 3

int main(){

char input[30];

for(i=0; i<N;i++)
{
printf(“Enter month day and year separated by dash: ” );

fgets(input, 30, stdin); /* read in the whole line */

/* manipulate the input, count days and display */

}

return 0;

}

int countDays(int m, int d){

}

Write an ANSI-C pragram that reads input from the standard input about date, and then calculate the number days that has elapsed in the year. The program runs a loop for pre-defined N times. In each interaction, the user is prompted to enter Month-Day Year (three words separated by a dash and a space). For each input your program displays the approximate days that have elapsed from the start of the year.

Expert Answer

 Solution :

Code :

#include <stdio.h>
#define N 3

int main(){
char input[30];
int i, j=0;
int day=0, month=0, year =0 ;
int daycount=0;
for(i=0; i<N;i++)
{
printf(“n Enter month day and year separated by dash: ” );
fgets(input, 30, stdin); /* read in the whole line */
day =0; month =0; year = 0; j =0; daycount =0;
/* manipulate the input, count days and display */
// manipulating date
while(input[j]!=’-‘){
month = month*10 + (input[j]-48);
j++;
}
j++;
while(input[j]!=’ ‘){
day = day*10 + (input[j]-48);
j++;
}
j++;
while(input[j]>=48 && input[j] <= 58){
year = year*10 + (input[j]-48);
j++;
}

printf(“n Day : %d, month: %d, year: %d”, day, month, year);
daycount = countDays(month, day);
printf(“n Approximately %d days of year %d have elapsed.n”, daycount, year);
}

return 0;

}
int countDays(int m, int d){
int i =0;
int dayCount=0;
for(i=1 ; i<m; i++){
if(i==1 || i==3 || i==5 || i==7 || i==9 || i==11){
dayCount = dayCount + 31;
}
else if(i==2){
dayCount = dayCount + 28;
}
else{
dayCount = dayCount+30;
}
}
dayCount = dayCount + d;
return dayCount;
}

Output :

Answered! Write an ANSI-C pragram that reads input from the standard input about date, and then calculate the number days... 3

Still stressed from student homework?
Get quality assistance from academic writers!