Tuesday, April 30, 2013
c Program to Convert Time in Seconds to Hours, Minutes and Seconds
/*
Program to Convert Time in Seconds to Hours, Minutes and Seconds
*/
#include <stdio.h>
main()
{
long sec, hr, min, t;
printf("\nEnter time in seconds: ");
scanf("%ld", &sec);
hr = sec/3600;
t = sec%3600;
min = t/60;
sec = t%60;
printf("\n\nTime is %ld hrs %ld mins %ld secs", hr, min, sec);
getch();
}
hr = sec/3600;
This program follows the general logic of converting second to hour.ie divide the total second by 3600 thus we get the Hour,
t = sec%3600
Then make a modular division on the total second ,thus we get the remaining seconds that can not form a hour.
min = t/60;
divide the 't' (seconds)with 60 ,then we get the remaining minutes.
sec = t%60;
modular division on the 't' result in the remaining seconds....
Subscribe to:
Post Comments (Atom)
Thank u very much
ReplyDeleteCan you explain the 3600 ?
ReplyDelete60*60=3600,cause change sec into hour
Delete3600 may be 60 sec in a min and 60 min in a hour
ReplyDeleteit is showing the wrong compalier
ReplyDeleteI just wanted to covert second into min and sec, and the following code creating run time error kindly help.
ReplyDelete#include
main(){
long min, sec,time;
printf("Enter the desired second you want to convert :");
scanf("%ld",time);
min=time/60;
sec=time%60;
printf("The converted time is %ld:%ld",&min,&sec);
}
mistake 1 : first line should be "#include ". you did not mention the stdio part
Deletemistake 2 : fifth line should be "scanf("%ld",&time);".dont forge the &
mistake 3 : eight line should be "printf("The converted time is %ld:%ld",min,sec);". you shouldn"t keep & here
#inlude
Delete#include
void main()
{
clrsrc();
int a,b,c;
printf("\nenter hour\n")
scanf(%d",&a);
b=a*60;
c=b*60;
printf("\n the convert hour is%d",c)
getch();
}
printf("The converted time is %ld:%ld",&min,&sec);
ReplyDeleteusing &min &sec here is wrong! Those are the addresses, not the values.
I am proud of your site, & interested.
ReplyDeleteJob Typing
hello friends
ReplyDeleteI just want algorithm of this coding
can you help me to describe the difference between \ and / operator ?
ReplyDelete#include
#include
main()
{
int sec, mint, hr;
printf("\n enter time in seconds");
scanf("%d",&sec);
hr=sec/3600;
sec=sec%3600;
mint=sec/60;
sec=sec%60;
printf("\n %d : %d : %d",hr,mint,sec);
getch();
}
I have wrote the header files but it was not shown, why?
DeleteI have wrote the header files but it was not shown, why?
Deleteafter doing all this in dev c++ my answer is wrong .please guide my mistake
ReplyDelete#include
using namespace std;
int main()
{
char time;
double second,hours,minutes;
cout<<"please enter the time";
cin>>time;
hours=time/;
time=time%3600;
minutes=time/60;
time=time%60;
second=time;
cout<<hours<<" "<<"hours"<<minutes<<" "<<"minutes"<<second <<" "<<"second"<<endl;
}
ReplyDeleteThe competition
The Sensitive Society Club organizes a donation campaign. To put more fun in the campaign, they organize a competition among departments. In the competition top donating students and the department are awarded with a certificate.
Question: Write a program that reads the information for n students then it shows
the name of the student who donated the most amount
and the department whose average is the highest
Input specification: You will be given one integer (n) in the beginning. Then, the following n lines will have three information:
Student name: names are at most 20 char strings containing only 26 English (uppercase or lowercase) letters
his/her department: at most 4 chars long string (only 3 departments in the competition: CEN, ECE or BINF)
The amount donated: a positive integer not greater than 20,000
where n is between 1 and 10,000.
Output specification: Show two strings:
the name of the student who donated the most,
The department whose average is the highest.
Note: If there are two students with the same value, show the first one.
Sample Input
6
Alban CEN 15
Redi ECE 7
Erda CEN 4
Kei BINF 9
Ardi BINF 11
Arli ECE 12
Sample Output
Alban BINF
Accept min from user and convert in hours, min and sec.
ReplyDeletePlease help me.
#include
ReplyDelete#include
void main()
{
int sec, mint, hr;
printf("\n enter time in seconds");
scanf("%d",&sec);
hr=sec/3600;
sec=sec%3600;
mint=sec/60;
sec=sec%60;
printf("\n %d : %d : %d",hr,mint,sec);
getch();
}
Design a program to find number of minutes and number of seconds from given number of
ReplyDeleteyears.