C++ Online Compiler
Example: Time Conversion Hackerrank Solution C++ Program
C
C++
C#
Java
Python
PHP
main.cpp
STDIN
Run
// Time Conversion Hackerrank Solution C++ Program #include <iostream> using namespace std; int main() { char timestamp[11]=""; int hr=0; cout << "INPUT TIME::\n"; cin >> timestamp; if (timestamp[8]=='P') { hr = 10*(timestamp[0]-'0')+(timestamp[1]-'0'); if (hr < 12) hr += 12; } else { hr = 10*(timestamp[0]-'0')+(timestamp[1]-'0'); if (hr==12) hr=0; } timestamp[0] = hr/10 + '0'; timestamp[1] = hr%10 + '0'; timestamp[8] = '\0'; timestamp[9] = '\0'; // It will print the final output cout << "\nCONVERTED TIME:: " << timestamp; return 0; }
09:30:30PM
Output
Clear
ADVERTISEMENTS