Write a C++ program to convert a given number into hours and minutes. Separate the number of hours and minutes with a colon.

  • برمجة سي بلس بلس
  • برمجة

Write a C++ program to convert a given number into hours and minutes. Separate the number of hours and minutes with a colon.

For example if a given number is 67 the output should be 1:7

Sample Output:

H:M 1:7

H:M 1:0

الأجوبة

#include <iostream>
#include <string>
using namespace std;
void Time_Convert(int num) {
	bool flag;
	int hr = 0;
	do
	{
		flag = false;
		if (num >= 60)
		{
			hr++;
			num -= 60;
			flag = true;
		}
	} while (flag);
	cout << "\nH:M " << hr << ":" << num << endl;
}

int main() {
	Time_Convert(67);
	Time_Convert(60);
	Time_Convert(120);
	Time_Convert(40);
	return 0;
}
هل كان المحتوى مفيد؟

تبحث عن مدرس اونلاين؟

محتاج مساعدة باختيار المدرس الافضل؟ تواصل مع فريقنا الان لمساعدتك بتأمين افضل مدرس
ماهو التخصص الذي تبحث عنه؟
اكتب هنا...