Write a function that accepts three arguments a number n, and two characters s and t. The function convert n from s unit to t unit of similar physical quantities. You can choose one of the following types to use in your program:
1. Length
2. Temperature
3. Area
4. Volume
5. Weight
6. Time
i want to time change in this question
#include<stdio.h>
void time_convert(double n, char s, char t){
double time,res;
switch(s){
case 'C':
            time = n*100*365.25 *24 * 3600;
            break;
        case 'Y':
            time = n*365.25*24*3600;
            break;
        case 'M':
            time = n*30*24*3600;
            break;
        case 'W':
            time = n*7*24*3600;
            break;
        case 'd':
            time = n*24*3600;
            break;
        case 'h':
            time= n*3600;
            break;
        case 'm':
            time = n*60;
            break;
        case 's':
            time = n;
            break;
        case 'l':
            time = n/1000;
            break;
        case 'u':
            time = n/1e6;
            break;
        case 'n':
            time = n/1e9;
            break;
default :printf("wrong source");
}
switch (t) {
        case 'C':
            res = time / (100 * 365.25 *24 * 3600);
            break;
        case 'Y':
            res = time / (365.25 * 24 * 3600);
            break;
        case 'M':
            res = time / (30 * 24 * 3600);
            break;
        case 'W':
            res = time / (7 * 24 * 3600);
            break;
        case 'd':
            res = time / (24 * 3600);
            break;
        case 'h':
            res = time / 3600;
            break;
        case 'm':
            res = time / 60;
            break;
        case 's':
            res = time;
            break;
        case 'l':
            res = time * 1000;
            break;
        case 'u':
            res = time * 1e6;
            break;
        case 'n':
            res = time * 1e9;
            break;
default: printf("wrong target");
}
printf("\n%.1f", res);
}
int main(){
double n;
printf("enter your time");
scanf("%f",&n);
time_convert(n,'m','s');
return 0;
}
Comments
Leave a comment