Algorithms_in_C 1.0.0
Set of algorithms implemented in C.
Loading...
Searching...
No Matches
celsius_to_fahrenheit.c File Reference

Conversion of temperature in degrees from Celsius to Fahrenheit. More...

#include <assert.h>
#include <stdio.h>
Include dependency graph for celsius_to_fahrenheit.c:

Functions

double celcius_to_fahrenheit (double celsius)
 for assert More...
 
static void test ()
 Self-test implementations. More...
 
int main ()
 Main function. More...
 

Detailed Description

Conversion of temperature in degrees from Celsius to Fahrenheit.

Author
Focusucof

Function Documentation

◆ celcius_to_fahrenheit()

double celcius_to_fahrenheit ( double  celsius)

for assert

for IO operations

Convert celsius to Fahrenheit

Parameters
celsiusTemperature in degrees celsius double
Returns
Double of temperature in degrees Fahrenheit
17 {
18 return (celsius * 9.0 / 5.0) + 32.0;
19 }

◆ main()

int main ( void  )

Main function.

Returns
0 on exit
71 {
72 test(); // run self-test implementations
73 return 0;
74}
static void test()
Self-test implementations.
Definition: celsius_to_fahrenheit.c:25
Here is the call graph for this function:

◆ test()

static void test ( void  )
static

Self-test implementations.

Returns
void
25 {
26 // 1st test
27 double input = 0.0;
28 double expected = 32.0;
29
30 double output = celcius_to_fahrenheit(input);
31
32 // 1st test
33 printf("TEST 1\n");
34 printf("Input: %f\n", input);
35 printf("Expected Output: %f\n", expected);
36 printf("Output: %f\n", output);
37 assert(output == expected);
38 printf("== TEST PASSED ==\n\n");
39
40 // 2nd test
41 input = 100.0;
42 expected = 212.0;
43
44 output = celcius_to_fahrenheit(input);
45
46 printf("TEST 2\n");
47 printf("Input: %f\n", input);
48 printf("Expected Output: %f\n", expected);
49 printf("Output: %f\n", output);
50 assert(output == expected);
51 printf("== TEST PASSED ==\n\n");
52
53 // 3rd test
54 input = 22.5;
55 expected = 72.5;
56
57 output = celcius_to_fahrenheit(input);
58
59 printf("TEST 3\n");
60 printf("Input: %f\n", input);
61 printf("Expected Output: %f\n", expected);
62 printf("Output: %f\n", output);
63 assert(output == expected);
64 printf("== TEST PASSED ==\n\n");
65}
double celcius_to_fahrenheit(double celsius)
for assert
Definition: celsius_to_fahrenheit.c:17
Here is the call graph for this function: