Follow Our FB Page << CircleMedia.in >> for Daily Laughter. We Post Funny, Viral, Comedy Videos, Memes, Vines...

2. Write a function called hms_to_secs() that takes
three int values&#8212;for hours, minutes, and seconds&#8212;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.

Answers were Sorted based on User's Feedback

2. Write a function called hms_to_secs() that takes three int values&#8212;for hours, minutes,..

#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;
system("pause");
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 ? 40 Yes 8 No

2. Write a function called hms_to_secs() that takes three int values&#8212;for hours, minutes,..

#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 ? 12 Yes 2 No

2. Write a function called hms_to_secs() that takes three int values&#8212;for hours, minutes,..

#include<iostream>
#include<cstdlib>
using namespace std;
long hms_to_secs(int hr, int min, int sec){
long secs =0;
secs = (hr * 60 * 60)+(min * 60)+sec;
return secs;
}
int main(){
int hr,min,sec; long secs;
cout<<"Enter Hours: ";cin>>hr;
cout<<"Enter Minutes: ";cin>>min;
cout<<"Enter Seconds: ";cin>>sec;
secs = hms_to_secs(hr,min,sec);
cout<<"Seconds is: "<<secs<<endl;

system("pause");
return 0;
}

 Is This Answer Correct ? 5 Yes 2 No

2. Write a function called hms_to_secs() that takes three int values&#8212;for hours, minutes,..

#include <iostream >
Using namespace std ;
long hms_to_secs (int, int, int) ;
int main ()
{int hrs, min, sec;
cout <<"Enter hours" <<endl ;cin>>hrs;
cout <<"Enter minutes " <<endl ;cin>>min;
cout <<"Enter seconds" <<endl ;cin <<sec;
cout <<hrs<<":" <<min<<":" <<sec<<":" <<endl ;
cout <<The time in seconds<<hms_to_secs (int hrs, int min, int sec) ;
}
long hms_to_secs (int h, int m, int s)
return( h*3600+m*60+s);

 Is This Answer Correct ? 2 Yes 1 No

More C Interview Questions

Is there a way to jump out of a function or functions?

What are local and global variables?

#include<stdio.h> int main( ) { Int a=300, b, c; if(a>=400) b=300; c=200; printf(“%d%d ”, b, c); return0; }

what is the output of the below code? main( ) { printf ( "\nOnly stupids use C?" ) ; display( ) ; } display( ) { printf ( "\nFools too use C!" ) ; main( ) ; }

How many types of operators are there in c?

without a terminator how can we print a message in a printf () function.

What is scope rule in c?

why we wont use '&' sing in aceesing the string using scanf

Find duplicates in a file containing 6 digit number (like uid) in O (n) time.

What is the use of volatile?

What is the memory allocated by the following definition ? int (*x)[10];

what is the output for this question: main() { int i=1; printf("%d%d%d",i,i++,++i); }

Categories