2. Write a function called hms_to_secs() that takes
three int values—for hours, minutes, and seconds—as
arguments, and returns the equivalent time in seconds..
Create a program that exercises this function by repeatedly
obtaining a time value in hours, minutes, and seconds from
the user (format 12:59:59), calling the function, and
displaying the value of seconds it returns.
Answer Posted / jay
#include<iostream>
using namespace std;
int hms_to_sec(int hr,int min, int sec);
int main()
{
int hr,min,sec;
int result =hms_to_sec(hr,min,sec);
cout << "result = " << result;
return 0;
}
int hms_to_sec(int hr,int min, int sec)
{
int seconds =0;
cout << "please enter hr" << endl;
cin >> hr;
cout << "please enter min" << endl;
cin >> min;
cout << "please enter sec" << endl;
cin >> sec;
seconds = (hr*60*60)+(min*60)+sec;
return seconds;
}
Is This Answer Correct ? | 20 Yes | 3 No |
Post New Answer View All Answers
Why is c called "mother" language?
What is file in c preprocessor?
What is s or c?
How many types of errors are there in c language? Explain
What is sizeof c?
Why is C language being considered a middle level language?
Why c is faster than c++?
please can any one suggest me best useful video tutorials on c i am science graduate.please help me.u can email me to sas29@in.com
write a program to find out prime number using sieve case?
any C program contains only one function, it must be a) void () b) main () c) message () d) abc ()
What does the format %10.2 mean when included in a printf statement?
Given only putchar (no sprintf, itoa, etc.) write a routine putlong that prints out an unsigned long in decimal. [ I gave the obvious solution of taking % 10 and / 10, which gives us the decimal value in reverse order. This requires an array since we need to print it out in the correct order. The interviewer wasn't too pleased and asked me to give a solution which didn't need the array ].
How are pointers declared in c?
how to find anagram without using string functions using only loops in c programming
the portion of a computer program within which the definition of the variable remains unchanged a) mode b) module c) scope d) none