- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Find a time for which angle between hour and minute hands is given theta in C++
Suppose we have one theta, or angle value. We have to find one time in hh:mm format, that creates the angle by the hour and minute hands. Suppose the angle is 90°, then the result can be 3:00.
As there are 12 hours, so there are 12 possibilities for hours and 60 possibilities for minutes. We will loop through all possible times. If angle for any time is same as given theta, then print that time.
Example
#include<iostream> #include<cmath> using namespace std; float angleFromClockHand(int hour, int minute) { float hour_angle = 0.5 * (hour*60 + minute); float minute_angle = 6*minute; float angle = abs(hour_angle - minute_angle); angle = min(360-angle, angle); return angle; } void findTime(float theta) { for (int hour=0; hour<12; hour++) { for (int min=0; min<60; min++) { if (angleFromClockHand(hour, min)==theta) { cout << hour << ":"<< min; return; } } } cout << "Unable to find time"; } int main() { float angle = 45.0; findTime(angle); }
Output
4:30
- Related Articles
- Program to find angle between hour and minute hands of a clock in C++?
- What is the smaller angle between the minute and hour hands at 12:46 AM? Â
- Angle Between Hands of a Clock in C++
- Angle between a chord and a tangent when angle in the alternate segment is given in C++?
- Find the angle measure between the hands of the clock in each figure:"
- Find the time which is palindromic and comes after the given time in Python
- Display just hour and minute using Formatter in Java
- Find the equations of the lines for which $tantheta=−1$, where $theta$ is the angle of inclination of the line and y− intercept is $-frac{1}{2}$.​
- $ABC$ is a right angled triangle in which $angle A = 90^o$ and $AB = AC$. Find $angle B$ and $angle C$.
- Python program to find difference between current time and given time
- Java Program to display hour and minute in AM or PM
- $ABCD$ is a parallelogram in which $angle A = 70^o$. Compute $angle B, angle C$ and $angle D$.
- Largest Time for Given Digits in C++
- Extract day, hour, minute, etc. from a datetime column in PostgreSQL?
- Given $angle POR = 3x$ and $angle QOR = 2x + 10^o$, find the value of $x$ for which $POQ$ will be a line."\n

Advertisements