I need to modify my C code to use functions. I shouls implement functions going
ID: 3819518 • Letter: I
Question
I need to modify my C code to use functions. I shouls implement functions going from total seconds to hours, total seconds to remaining minutes and total seconds to remaining seconds.
#include <stdio.h>
int main(){
int s = 0;
int min = 0;
int hrs = 0;
int rh = 0;
int sh = 0;
printf("Enter number of seconds:");
scanf("%d",&s);
hrs = s/3600;
rh = s%3600;
min = rh/60;
sh = rh%60;
printf("Break down of seconds = %d hours, %d mins, %d seconds", hrs, min, sh);
return 0;
}
Explanation / Answer
#include <stdio.h>
void hours(int seconds){
int hrs = seconds/3600;
printf("Brakdown of seconds hours = %d",hrs);
findRemainingMin(seconds%3600);
}
void findRemainingMin(int remaininghours){
int min = remaininghours/60;
printf("min = %d",min);
remainingSeconds(remaininghours);
}
void remainingSeconds(int min){
int seconds = min%60;
printf(" seconds = %d",seconds);
}
int main(){
int s = 0;
printf("Enter number of seconds:");
scanf("%d",&s);
hours(s);
}