Convert Fahrenheit To Degree Celsius: C Program

Temperature of a city in Fahrenheit degree is input through the keyboard. Write a program to convert this temperature into Degree Celsius / Centigrade.

Related Read:
Basic Arithmetic Operations In C
Convert Degree Celsius To Fahrenheit: C Program

Formula to Convert Fahrenheit To Celsius.

From our previous video tutorial Convert Degree Celsius To Fahrenheit: C Program we already know the formula to convert temperature from Celsius to Fahrenheit. We will use the same formula and convert it to calculate Degree celsius from Fahrenheit.

Fahrenheit = (Centigrade * 1.8) + 32;
(Fahrenheit – 31) = (Centigrade * 1.8);
(Fahrenheit – 31) / 1.8 = (Centigrade);

So we’ll use this formula Centigrade = (Fahrenheit – 31) / 1.8; to calculate Degree Centigrade by getting Fahrenheit value from the user.

Convert Fahrenheit To Degree Celsius: C Program


[youtube https://www.youtube.com/watch?v=jBR9hco2O-w]

YouTube Link: https://www.youtube.com/watch?v=jBR9hco2O-w [Watch the Video In Full Screen.]


Source Code: Convert Fahrenheit To Degree Celsius: C Program

#include < stdio.h >

int main()
{
    float c, fh;

    printf("Enter temperature in Fahrenheit\n");
    scanf("%f", &fh);

    c = (fh - 32) / 1.8;

    printf("Temperature in Degree Celius is %f\n", c);

    return 0;
}

Output 1:
Enter temperature in Fahrenheit
212
Temperature in Degree Celius is 100.000000

Output 2:
Enter temperature in Fahrenheit
113
Temperature in Degree Celius is 45.000000

For list of all c programming interviews / viva question and answers visit: C Programming Interview / Viva Q&A List

For full C programming language free video tutorial list visit:C Programming: Beginner To Advance To Expert

Convert Degree Celsius To Fahrenheit: C Program

Temperature of a city in Degree Celsius / Centigrade degree is input through the keyboard. Write a program to convert this temperature into Fahrenheit.

Related Read:
Basic Arithmetic Operations In C
Division of 2 Numbers: C
Convert Fahrenheit To Degree Celsius: C Program

Formula to Convert Celsius To Fahrenheit

Fahrenheit = (Centigrade * (9/5)) + 32;
But in C programming, any number divided by an integer number will return integer value. So 9/5 will give 1 and not 1.8

So we need to be careful while doing division operation in C. To solve this issue we can write following formula in C program to convert degree celsius to Fahrenheit.

Fahrenheit = (Centigrade * (9/5.0)) + 32;
OR
Fahrenheit = (Centigrade * 1.8) + 32;

Convert Degree Celsius To Fahrenheit: C Program


[youtube https://www.youtube.com/watch?v=UFtA-OVypHs]

YouTube Link: https://www.youtube.com/watch?v=UFtA-OVypHs [Watch the Video In Full Screen.]


Source Code: Convert Degree Celsius To Fahrenheit: C Program

#include < stdio.h >

int main()
{
    float c, fh;

    printf("Enter temperature in Centigrade\n");
    scanf("%f", &c);

    fh = (c * 1.8) + 32;

    printf("Temperature in Fahrenheit is %f\n", fh);

    return 0;
}

Output 1:
Enter temperature in Centigrade
100
Temperature in Fahrenheit is 212.000000

Output 2:
Enter temperature in Centigrade
45
Temperature in Fahrenheit is 113.000000

For list of all c programming interviews / viva question and answers visit: C Programming Interview / Viva Q&A List

For full C programming language free video tutorial list visit:C Programming: Beginner To Advance To Expert

Draw Arcs/Circle with Canvas: HTML5

Today lets learn how to use arcs and paths to draw circle.

Arcs are curves that are portions of a circle. A full circle is a 360 degree arc!
A Path is a collection of some lines(or shapes) that once defined can be either filled or stroked.

index.html and myStyle.css files are kept same as illustrated in previous video tutorial: Canvas State: HTML5

Syntax
arc(x, y, r, sA, eA, TF);

arc method takes 6 parameters. x and y are the x-axis and y-axis, which is the center of the circle.
i.e., The x and y parameters determine where the center of the circle will be located on your canvas.

r is the radius of the circle, in pixels.
i.e., the distance of the curve from the center of the circle.

sA is start angle of the circle.
eA is the end angle of the circle.

TF is the direction – which can take 2 values i.e., True or False.

True: negative degrees, counter-clockwise direction.
False: positive degrees, clockwise direction.

Javascript file
myScript.js

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
window.onload = canvas;
 
function canvas()
{
var myCanvas = document.getElementById("myCanvas");
 
if( myCanvas && myCanvas.getContext("2d") ) 
{
var context         = myCanvas.getContext("2d");
 
context.lineWidth= 6;
context.beginPath();
 
var degree = 270;
var radian = ( Math.PI / 180 ) * degree;
 
context.arc(100, 100, 50, 0, radian, false);
context.strokeStyle= "red";
context.fillStyle= "blue";
context.stroke();
context.fill();
context.closePath();
 
}
}

Degree to Radian

radians-and-degrees

We convert degrees to radians using a simple mathematical formula:
Radians = (PI / 180 ) * degree;

Draw Arcs/Circle with Canvas: HTML5


[youtube https://www.youtube.com/watch?v=vE0bstctkp4]

YouTube Link: https://www.youtube.com/watch?v=vE0bstctkp4 [Watch the Video In Full Screen.]



Note:
1. By default, direction of drawing the arc is clockwise/positive degrees(i.e., the value of last parameter is false).
2. PI value is 180.
3. 2 * PI is 360!
4. arc method should be passed with radian values and not degrees.