Implement the following problem in C programming language with following functions:
1- A function “Speed” that takes meters and seconds as parameters and returns the speed in meter
per second (m/s).
2- A function “Convert” that returns the kilometer per hour (kph) equivalent of m/s.
Call the above created function in main to test them.
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
//Implement function Speed
double Speed(unsigned metr,unsigned sec)
{
//Take two argument
//@metr-Metr
//@sec-Second
return (metr*1.0)/(sec*1.0);
}
//Convert m/s to km/h
double Convert(double ms)
{
return ms*3.6;
}
int main(void) {
unsigned metr;
unsigned second;
printf("Please enter metr:");
scanf("%u",&metr);
printf("Please enter second:");
scanf("%u",&second);
double ms=Speed(metr,second);
printf("%lf m/s\n",ms);
double km=Convert(ms);
printf("%lf km/h\n",km);
return 0;
}
Comments
Leave a comment