Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 5

Experiment Number : 02

Experiment Name : Addition, Subtraction, Multiplication & Division of two


Numbers.

Theory: There are fundamental arithmetic operators supported by C language,


which are addition(+), subtraction(-), multiplication(*), division(/) of two
numbers. All arithmetic operators compute the result of specific arithmetic
operation and returns its result. In C programming , to performs basic binary
arithmetic operation on two integer operands like addition, subtraction, division
and modulus and prints result in screen ,it first takes two integers as input from
user using scanf function and stores them in 'firstNumber' and 'secondNumber'
int variables and performs addition, subtraction, multiplication, division and
modulus operations and stores results in 'sum', 'difference' , 'product', 'quotient'
variables respectively. Next, it prints the result on screen using printf function.

Code 1 :
#include<stdio.h>
int main ()
{
float a,b,c,d,e,f;
a=23;
b=5;
c=a+b;
d=a-b;
e=a*b;
f=a/b;
printf("sum=%f\n",c);
printf("sub=%f\n",d);
printf("product=%f\n",e);
printf("division=%f\n",f);
return 0;
}

Output :

Discussion: In this programme, I have used the arithmetic and logical operators.
Floating function used to declare variables for integer numbers and decimal
point . Then I had run some arithmetic operation by using the operators. Basic
arithmetic operators are used to perform Addition, Subtraction, Multiplication
& Division of two Numbers. There was no error in this experiment.

Conclusion: As most of the computer programs are designed to calculate


mathematical calculations, arithmetic operators are of important in
programming languages. Basic data types are used to initialize local variables,
to declare local variables and to perform simple arithmetic operators use.

Experiment Number : 02
Experiment Name : Temperature conversion from Fahrenheit to Celsius.
Theory: Formula to convert temperature from degree Fahrenheit to degree
Celsius is given by -
Code 2:
#include<stdio.h>
int main()
{
float C,F;
F=100;
C=(F-32)*5/9;

printf("%f",C);
return 0;
}

Output:

Discussion: Floating function used to declare variables for integer numbers and
decimal.As there is no error in this code,the input value in Fahrenheit converted
into Celsius.
The above function fahrenheit_to_celsius() convert the temperature values
from Fahrenheit to Celsius.
And the function celsius_to_fahrenheit() will convert the temperature values
from Celsius to Fahrenheit.
The formula to convert Fahrenheit to Celsius we used here was:
temp_c = (temp_f -32) * 5/9. As there is no error in this code,the input value in
Fahrenheit converted into Celsius.

Conclusion: A temperature converter helps in the conversion of the


measurement units of the temperature recorded in a particular unit.IN this
experiment we learned about it.
Experiment Number : 03
Experiment Name : Swapping two numbers.
Theory:
Swapping two number in C programming language means exchanging the
values of two variables Let’s understand the logic behind this by taking an
example. Here we will be using the function method. We will use the call by
value method.

We will ask users to input two values for the variables a & b, respectively. Then
we pass those values through the swapping(a, b) function.

The values of both a and b are entered into the local variables of the
swapping(a, b) function, that is x and y, respectively.

The Following logic was followed inside the swapping(a, b) function:

Here, we have used “third” as the temporary variable, in which the


valvariable(x) was assigned.
Then, the value of the second variable(y) was assigned to the first variable(x).
Finally, the third variable(which holds the value of x(first variable)) is assigned
to the second variable(y).

Code 3:
#include<stdio.h>
int main()
{
float a,b,c;
a=56;
b=67;
c=a;
a=b;
b=c;
printf("%f\n",a);
printf("%f",b);
return 0;
}

Output:

Discussion:

You might also like