![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 | |||
|
Programmer
Join Date: May 2005
Posts: 48
Rep Power: 0
![]() |
Some exercises
Hello I'm a n00b ate programming and I think I need some help solving one exercise that I saw in a Google search.It says exactly:
Quote:
Well this problem was solved almost successfully: /*Horas. minutos e segundos*/
#include <stdio.h>
#include <stdlib.h>
int main()
{
int horas,min,seg;
long int result_em_segundos;
printf("\nDiga que horas, quantos minutos e quantos segundos são respectivamente: ");
scanf("%d%d%d",&horas,&min,&seg);
horas=60*60*horas;
min=60*min;
printf("O resultado em segundos e de %d ",horas+min+seg);
system("PAUSE");Some things are in portuguese btu I think the code is quite understandable... Well, my big problem is the second exercise: Quote:
#include <stdio.h>
#include <stdlib.h>
int main()
{
int horas,sec,min;
printf(" Say how many seconds you intend to convert for hourly time....");
scanf("%d",&sec);
horas=sec/60/60;
min=sec/60;
printf("Sao %d horas %d minutos e %d segundos",horas,min,sec);
system("PAUSE");
}Quote:
|
|||
|
|
|
|
|
#2 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
When you use part (or all) of the seconds to make the appropriate number of hours, you have to only use the remainder for the minutes, and the remainder of that operation for the seconds. You may find the modulus operator (%) useful for that.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code. Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers |
|
|
|
|
|
#3 | |
|
Programmer
Join Date: May 2005
Posts: 48
Rep Power: 0
![]() |
Quote:
horas = sec/3600; min = (sec%3600)/60; sec = sec%60; And it functioned prety well.... Thanks for helping ![]() |
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|