17 Mar 2016

Clock angle problem


/*

Find minimum angle between hour and minute hand. 

Input:
The first line contains the number of test cases, T. T lines follow, each of which contains two integer Hour hand H and minute hand M .

Output:
Print the minimum angle between the hands.
Constraints
1<=T<=100
01<=H<=12
01<=M<=59

*/ 

#include <stdio.h>

int main()
{
    int T,*h,*m,h_angle,m_angle,angle,i;
   
    scanf("%d",&T);
    h=(int*)malloc(T*sizeof(int));
    m=(int*)malloc(T*sizeof(int));
   
    for(i=0;i<T;i++){
       
        scanf("%d %d",&h[i],&m[i]);   
        if (h[i] == 12) h[i] = 0;
        if (m[i] == 60) m[i] = 0;
       
        h_angle=0.5 * (h[i]*60 + m[i]);
        m_angle=6*m[i];
        angle=abs(h_angle-m_angle);
       
        if(360-angle <angle) angle=360-angle;
       
        printf("%d\n",angle);
    }
   
   
    return 0;
}


Categories: , , , ,

Trailing Zeroes


/*

Given a number find the number of trailing zeroes in its factorial.
Input Format
A single integer - N
Output Format
Print a single integer which is the number of trailing zeroes.
Input Constraints
1 <= N <= 1000

*/

#include <stdio.h>

int main(){
   
    int i,N,z,k;
    scanf("%d",&N);
   
    z=0;
    k=1;
    i=1;
    while(1){
       
        k=(int)(N/pow(5,i));
        if(k<1) break;
        z+=k;
        i++;
    }
   
    printf("%d",z);
    return 0;
}

Categories: , , ,

Copyright © UPgradeCODING | Powered by Blogger