Download as pdf or txt
Download as pdf or txt
You are on page 1of 43

Experiment No: 1

Name of the experiment: To write a C program to find the sum and average of 2
integers taken from the keyboard.

Theory: The scanf() keyword is used to input data through the keyboard. The sum is obtained
by adding the inputted data. Dividing the sum by the total number, the average is calculated.

 Uses of Device/Apparatus:
Hardware: A computer
Software:
o Operating system – Windows 7
o Programming language
o Turbo C++ Compiler

Uses: To complete the test using the apparatus, the following steps are followed –
1. At the beginning of the experiment, the electrical connection of the computer is checked.
2. If the electrical connection is ok, the computer is turned on by turning on the computer's
power switch.
3. It is checked whether the necessary programs are installed on the computer or not.
4. The required program is launched to complete the experiment.
5. When the test is completed, the running programs are closed and the computer is shut
down according to the rules. For extra safety, the power is disconnected by turning off
the electrical switch.

 The process to Follow:


 Procedure:

 At first, by double-clicking the Codeblocks icon on the desktop, the software is launched.
 Then the following program is written by using Codeblocks IDE (integrated development
environment)
 Program:
#include <stdio.h>

void main() {

int x, y, sum, avg;


printf("Enter first number:");
scanf("%d",&x);
printf("Enter second number:");
scanf("%d",&y);
sum = x+y;
avg = sum/2;
printf("Sum=%d\n",sum);
printf("Average=%d\n",avg);

 Save File:
1. "Save As" option is selected from the File menu.
2. In the "Save File As" text box "Program01" is written as the file name and the ok button
is clicked.
 Run the program:
1. When the compile button is clicked from the compile menu, the file is converted to
machine code from source code. If there are any errors, the errors are also shown. After
necessary correction file is saved again.
2. To run the program ctrl+F9 button is pressed simultaneously from the keyboard.

 Explanation:
The statements used in the above program are explained below-
 printf(“expression”)
 scanf(“input format”, &variable name)
 printf(“Expression with output format”, variable name)

expression = What you want to see on the monitor should be written here.
input/output format =
%d = The data type of the variable will be “int”
%f = The data type of the variable will be “float”
%c = The data type of the variable will be “char”
Observation:
When the experiment is completed, if we provide input 69 and 13 from the keyboard, the
following result will be shown:

Sum = 82
Average = 41

Flowchart:
Experiment No: 2
Name of the experiment: To write a C program to convert Celsius scale temperature
to Fahrenheit scale.

Theory: Any temperature can be easily converted from one scale to another by using formulas.
This task can be easily done through computer programming.

 Uses of Device/Apparatus:
Hardware: A computer
Software:
o Operating system – Windows 7
o Programming language
o Turbo C++ Compiler

Uses: To complete the test using the apparatus, the following steps are followed –
1. At the beginning of the experiment, the electrical connection of the computer is checked.
2. If the electrical connection is ok, the computer is turned on by turning on the computer's
power switch.
3. It is checked whether the necessary programs are installed on the computer or not.
4. The required program is launched to complete the experiment.
5. When the test is completed, the running programs are closed and the computer is shut
down according to the rules. For extra safety, the power is disconnected by turning off
the electrical switch.

 The process to Follow:


 Procedure:

 At first, by double-clicking the Codeblocks icon on the desktop, the software is launched.
 Then the following program is written by using Codeblocks IDE (integrated development
environment)
 Program:
#include <stdio.h>

void main() {

float c,f;
printf("Enter Celsius Scale Temperature:");
scanf("%f",&c);
f = ((9*c)/5)+32;
printf("Fahrenheit Scale Temperature = %f",f);

 Save File:
1. "Save As" option is selected from the File menu.
2. In the "Save File As" text box "Program01" is written as the file name and the ok button
is clicked.
 Run the program:
1. When the compile button is clicked from the compile menu, the file is converted to
machine code from source code. If there are any errors, the errors are also shown. After
necessary correction file is saved again.
2. To run the program ctrl+F9 button is pressed simultaneously from the keyboard.

 Explanation:
The statements used in the above program are explained below-
 printf(“expression”)
 scanf(“input format”, &variable name)
 printf(“Expression with output format”, variable name)

expression = What you want to see on the monitor should be written here.
input/output format =
%d = The data type of the variable will be “int”
%f = The data type of the variable will be “float”
%c = The data type of the variable will be “char”
𝐶 𝑓 − 32
=
5 9
→ 9 ∗ C = 5(f − 32)
→ 𝑓 = ((9 ∗ 𝑐)/5) + 32

Observation:
When the experiment is completed, if we provide input 100 as Celsius scale temperature,
the following result will be shown.:

Fahrenheit Scale Temperature = 212.000000


Flowchart:
Experiment No: 3
Name of the experiment: To Write a C program to find the area of a triangle from the
length of three sides.

Theory: When the length of three sides of a triangle is given, to find the area, the perimeter
of the triangle needs to be calculated first, then the area can be determined. The required
formula is given below:

Area = 𝑠 ∗ (𝑠 − 𝑎) ∗ (𝑠 − 𝑏) ∗ (𝑠 − 𝑐)
a
b
( )
Where s =

 Uses of Device/Apparatus:
Hardware: A computer
Software:
o Operating system – Windows 7
o Programming language
o Turbo C++ Compiler

Uses: To complete the test using the apparatus, the following steps are followed –
1. At the beginning of the experiment, the electrical connection of the computer is checked.
2. If the electrical connection is ok, the computer is turned on by turning on the computer's
power switch.
3. It is checked whether the necessary programs are installed on the computer or not.
4. The required program is launched to complete the experiment.
5. When the test is completed, the running programs are closed and the computer is shut
down according to the rules. For extra safety, the power is disconnected by turning off
the electrical switch.

 The process to Follow:


 Procedure:

 At first, by double-clicking the Codeblocks icon on the desktop, the software is launched.
 Then the following program is written by using Codeblocks IDE (integrated development
environment)

 Program:
#include <stdio.h>
#include <math.h>

void main() {

float a, b, c;
float s, area;
printf("Enter size of each sides of triangle=");
scanf("%f%f%f",&a,&b,&c);
s=(a+b+c)/2;
area = sqrt(s*(s-a)*(s-b)*(s-c));
printf("Area of the triangle is: %.3f",area);

 Save File:
1. "Save As" option is selected from the File menu.
2. In the "Save File As" text box "Program01" is written as the file name and the ok button
is clicked.
 Run the program:
1. When the compile button is clicked from the compile menu, the file is converted to
machine code from source code. If there are any errors, the errors are also shown. After
necessary correction file is saved again.
2. To run the program ctrl+F9 button is pressed simultaneously from the keyboard.

 Explanation:
The statements used in the above program are explained below-
 printf(“expression”)
 scanf(“input format”, &variable name)
 printf(“Expression with output format”, variable name)
expression = What you want to see on the monitor should be written here.
input/output format =
%d = The data type of the variable will be “int”
%.3f = Will display up to 3 digit values after the decimal point.
%c = The data type of the variable will be “char”
Observation:
When the experiment is done, inputting 2, 4, 3, and 5 for each side length from the
keyboard will give the following result:

Area of triangle is: 3.800

Flowchart:
Experiment No: 4
Name of the experiment: To write a C program to find the area of a circle when the
radius is given.

Theory: By taking the radius, the area of the circle needs to be determined. The required
formula is given below:

Area = Pie * radius *radius

Radius Here the value of Pi is constant.

Pi = 3.1416

 Uses of Device/Apparatus:
Hardware: A computer
Software:
o Operating system – Windows 7
o Programming language
o Turbo C++ Compiler

Uses: To complete the test using the apparatus, the following steps are followed –
1. At the beginning of the experiment, the electrical connection of the computer is checked.
2. If the electrical connection is ok, the computer is turned on by turning on the computer's
power switch.
3. It is checked whether the necessary programs are installed on the computer or not.
4. The required program is launched to complete the experiment.
5. When the test is completed, the running programs are closed and the computer is shut
down according to the rules. For extra safety, the power is disconnected by turning off
the electrical switch.

 The process to Follow:


 Procedure:
 At first, by double-clicking the Codeblocks icon on the desktop, the software is launched.
 Then the following program is written by using Codeblocks IDE (integrated development
environment)

 Program:
#include <stdio.h>
#include <math.h>
#define Pi 3.1416

void main() {

float r, a;
printf("Radius: ");
scanf("%f",&r);
a = Pi * r * r;
printf("Area = %f \n", a);

 Save File:
1. "Save As" option is selected from the File menu.
2. In the "Save File As" text box "Program01" is written as the file name and the ok button
is clicked.
 Run the program:
1. When the compile button is clicked from the compile menu, the file is converted to
machine code from source code. If there are any errors, the errors are also shown. After
necessary correction file is saved again.
2. To run the program ctrl+F9 button is pressed simultaneously from the keyboard.

 Explanation:
The statements used in the above program are explained below-
 printf(“expression”)
 scanf(“input format”, &variable name)
 printf(“Expression with output format”, variable name)
 define = Global variable

expression = What you want to see on the monitor should be written here.
input/output format =
%d = The data type of the variable will be “int”
%f = The data type of the variable will be “float”
%c = The data type of the variable will be “char”

Observation:
When the experiment is completed, if we provide input 5 as the radius of the circle, the
following result will be shown.
Area = 78.540001

Flowchart:
Experiment No: 5
Name of the experiment: To write a C program to check whether the number is even
or odd.

Theory: To determine whether a number is even or odd first, the number is divided by 2 to
find the remainder. If the remainder is equal to zero then the number will be an even number
otherwise it will be an odd number.

 Uses of Device/Apparatus:
Hardware: A computer
Software:
o Operating system – Windows 7
o Programming language
o Turbo C++ Compiler

Uses: To complete the test using the apparatus, the following steps are followed –
1. At the beginning of the experiment, the electrical connection of the computer is checked.
2. If the electrical connection is ok, the computer is turned on by turning on the computer's
power switch.
3. It is checked whether the necessary programs are installed on the computer or not.
4. The required program is launched to complete the experiment.
5. When the test is completed, the running programs are closed and the computer is shut
down according to the rules. For extra safety, the power is disconnected by turning off
the electrical switch.

 The process to Follow:


 Procedure:

 At first, by double-clicking the Codeblocks icon on the desktop, the software is launched.
 Then the following program is written by using Codeblocks IDE (integrated development
environment)
 Program:
#include <stdio.h>

void main() {

int x, y;
printf("Enter a number:");
scanf("%d",&x);
y = x % 2;
if (y == 0)
{
printf("\n You entered an even number");
printf("\n and the number is %d", x);
}
else
{
printf("\n You entered an odd number");
printf("\n and the number is %d", x);
}

 Save File:
1. "Save As" option is selected from the File menu.
2. In the "Save File As" text box "Program01" is written as the file name and the ok button
is clicked.
 Run the program:
1. When the compile button is clicked from the compile menu, the file is converted to
machine code from source code. If there are any errors, the errors are also shown. After
necessary correction file is saved again.
2. To run the program ctrl+F9 button is pressed simultaneously from the keyboard.

3.

 Explanation:
The statements used in the above program are explained below-
 printf(“expression”)
 scanf(“input format”, &variable name)
 printf(“Expression with output format”, variable name)
 if-else statement is the extended form of if statement. If the expression is true the
statement_1 will be executed otherwise statement_2 will be executed.

expression = What you want to see on the monitor should be written here.
input/output format =
%d = The data type of the variable will be “int”
%f = The data type of the variable will be “float”
%c = The data type of the variable will be “char”

Observation:
When the experiment is completed, if we provide input 69 as input from the keyboard, the
following result will be shown.

You entered an odd number


and the number is 69
Flowchart:
Experiment No: 6
Name of the experiment: T
Theory: To find the largest number out of three numbers, the numbers need to be compared
with each other. Following this procedure, the largest number can be determined.

 Uses of Device/Apparatus:
Hardware: A computer
Software:
o Operating system – Windows 7
o Programming language
o Turbo C++ Compiler

Uses: To complete the test using the apparatus, the following steps are followed –
1. At the beginning of the experiment, the electrical connection of the computer is checked.
2. If the electrical connection is ok, the computer is turned on by turning on the computer's
power switch.
3. It is checked whether the necessary programs are installed on the computer or not.
4. The required program is launched to complete the experiment.
5. When the test is completed, the running programs are closed and the computer is shut
down according to the rules. For extra safety, the power is disconnected by turning off
the electrical switch.

 The process to Follow:


 Procedure:

 At first, by double-clicking the Codeblocks icon on the desktop, the software is launched.
 Then the following program is written by using Codeblocks IDE (integrated development
environment)
 Program:
#include <stdio.h>

void main() {

int x,y,z,h;
printf("Enter 1st number:");
scanf("%d",&x);

printf("Enter 2nd number:");


scanf("%d",&y);

printf("Enter 3rd number:");


scanf("%d",&z);

h = x;
if(h<y)
{
h = y;
}

if(h<z)
{
h = z;
}

printf("The Largest number is =%d",h);

 Save File:
1. "Save As" option is selected from the File menu.
2. In the "Save File As" text box "Program01" is written as the file name and the ok button
is clicked.
 Run the program:
1. When the compile button is clicked from the compile menu, the file is converted to
machine code from source code. If there are any errors, the errors are also shown. After
necessary correction file is saved again.
2. To run the program ctrl+F9 button is pressed simultaneously from the keyboard.

 Explanation:
The statements used in the above program are explained below-
 printf(“expression”)
 scanf(“input format”, &variable name)
 printf(“Expression with output format”, variable name)
 if-else statement is the extended form of if statement. If the expression is true the
statement_1 will be executed otherwise statement_2 will be executed.
The structure is given below:
if(expression) statement_1;
else statement_2;

expression = What you want to see on the monitor should be written here.
input/output format =
%d = The data type of the variable will be “int”
%f = The data type of the variable will be “float”
%c = The data type of the variable will be “char”

Observation:
When the experiment is completed, if we provide input 7 as 1 st number, 13 as 2nd number
and 13 as 3rd the keyboard, the following result will be shown:

The Largest number is = 69


Flowchart:
Experiment No: 7
Name of the experiment: Write a program to find whether any English
letter received through keyboard is a vowel or not.
Theory:
There are 26 letters in English alphabet. There are 52 letters in upper-case and
lower-case letters. By inputting a letter from the keyboard, whether it is vowel or
not can be determined through computer programming.
Uses of devices :
 Hardware: A computer
 Software: Operating system- windows 10
Programming language- Turbo C++ compiler

Uses:
To complete the mentioned test, follow the procedure below for using the
equipment-

1. At the beginning of the work, check whether the electrical connection of the
computer is correct.

2. If the electrical connection is correct, the computer should be turned on by


turning on the power switch on the computer.
3. Check whether the mentioned software is installed on the computer.
4. The required program must be launched to complete the test described.
5. After the test is completed, the running programs should be closed and the
computer must be shut down according to the rules. If necessary, turn off the
electrical switch and disconnect the power.
Activities:
To complete the test, work according to the procedure described below:
Double-click on the icon located on the desktop, open the complier and write
the following program code in the code building editor:

Program :
#include<stdio.h>
#include<conio.h>
Int main ()
{
char ch;
clrscr ();
printf (“Enter a character\n”);
scanf (“%c”, &ch);
if (ch == ‘a’ || ch == ‘A’ || ch == ‘e’ || ch == ‘E’ || ch == ‘i’ || ch == ‘I’ || ch ==
‘o’ || ch == ‘O’ || ch == ‘u’ || ch == ‘U’)
printf (“%c is a vowel. \n”, ch);
else
printf (“%c is not a vowel. \n”, ch);
return 0;
getch();
}
Flow chart:

File Save :
1. Select save as option from the file menu.
2. Write the file name as ‘Program 09’ in the ‘Save file as’ text box obtained
from ‘Save file as’ dialog box and click on the OK button (the directory
in which the file will be saved is C:\TC\BIN).
Running the program:
1. Clicking compile button from the compile menu will convert the file
from source code (the original program written in a high-level language)
to machine code (the machine language converted into binary language).
Any error will show for correction. Save the file again after editing.

2. To run or execute the program, press ctrl+F9 from the key board.
Explanation:
 Statements used in the above program are explained below:
 printf (“expression”)
 scanf (“input format”, &variable name)
 printf (“expression with output format”, variable name)
 if-else statement is the extended form of if statement. In that word
statement-1 will be executed if expression is true and statement-2 will
be executed if expression is false. The structure is as follows:
if (expression)
statement-1;
else statement-2;
 Expression- What we want to see on the monitor.
Input/Output format:
%d = The data type of the variable will be integer.
%f = The data type of the variable will be floating-point.
%c = The data type of the variable will be character.
Observation:
After the test is completed, if a letter given as input from the keyboard, it will be
displayed on the monitor as vowel or not vowel.
Experiment No: 8
Experiment Name: Write a program to find whether an English year is
leap year or not.
Theory:
The following conditions apply to determine whether an English year is a leap year
or not:
1. The remainder must be zero (0) after dividing by 400. OR
2. If the remainder is not zero upon dividing the year by 100 then the
remainder must be zero after dividing by 4
Uses of device:
 Hardware: A computer
 Software: Operating system- windows 10
Programming language- Turbo C++ compiler
Uses:
To complete the mentioned test, follow the procedure below for using the
equipment-

1. At the beginning of the work, check whether the electrical connection of the
computer is correct.

2. If the electrical connection is correct, the computer should be turned on by


turning on the power switch on the computer.
3. Check whether the mentioned software is installed on the computer.
4. The required program must be launched to complete the test described.
5. After the test is completed, the running programs should be closed and the
computer must be shut down according to the rules. If necessary, turn off the
electrical switch and disconnect the power.
Activities :
To complete the test, work according to the procedure described below:
Double-click on the icon located on the desktop, open the complier and write
the following program code in the code building editor:

#include<stdio.h>
#include<conio.h>
void main()

{
int year;
scanf (“%d”, &year);
if ( (year%400 == 0) | |(year%100 != 0) && (year%4 == 0))
printf (“%d is a leap year.\n”, year);
else
printf (“%d is not a leap year.\n”, year);
getch ();
}
Flow chart:
File save:
1. Select save as option from the file menu.
2. Write the file name as ‘Program 08’ in the ‘Save file as’ text box obtained
from ‘Save file as’ dialog box and click on the OK button (the directory
in which the file will be saved is C:\TC\BIN).

Running the program:


1. Clicking compile button from the compile menu will convert the file
from source code (the original program written in a high-level language)
to machine code (the machine language converted into binary language).
Any error will show for correction. Save the file again after editing.

2. To run or execute the program, press ctrl+F9 from the key board.

Explanation:
 Statements used in the above program are explained below:
 printf(“expression”)
 scanf(“input format”, &variable name)
 printf(“expression with output format”, variable name)
 if-else statement is the extended form of if statement. In that word
statement-1 will be executed if expression is true and statement-2 will
be executed if expression is false. The structure is as follows:
if(expression)
statement-1;
else statement-2;
 Expression- What we want to see on the monitor.

Input/Output format:
%d = The data type of the variable will be integer.
%f = The data type of the variable will be floating-point.
%c = The data type of the variable will be character.
Observation :
After the test is completed, if the year 1996 is given as input from the keyboard
‘1996 is a leap year’ result will be obtained.
Experiment No: 9
Experiment Name: Write a program to find positive and negative numbers among
10 numbers accepted through the keyboard.
Theory:
To determine whether the number is positive or negative, the number must be
compared to zero. If the number is greater than zero then it will be a positive
number and if the number is less than zero it will a be negative number.
Uses of device:
 Hardware: A computer
 Software: Operating system- windows 10
Programming language- Turbo C++ compiler

Uses:
To complete the mentioned test, follow the procedure below for using the
equipment-

1. At the beginning of the work, check whether the electrical connection of the
computer is correct.

2. If the electrical connection is correct, the computer should be turned on by


turning on the power switch on the computer.
3. Check whether the mentioned software is installed on the computer.
4. The required program must be launched to complete the test described.
5. After the test is completed, the running programs should be closed and the
computer must be shut down according to the rules. If necessary, turn off the
electrical switch and disconnect the power.
Activities:
To complete the test, work according to the procedure described below:
Double-click on the icon located on the desktop, open the complier and write
the following program code in the code building editor:

#include<stdio.h>
#include<conio.h>
void main ()
{
int I, p=0, n=0, x;
clrscr();
for (i=1; i<10; i++)
{
printf (“Enter value for x=”);
scanf (“%d”, &x);
if (x>=0)
p=p+1;
else
n=n+1;
}
printf (“\n\tTotal Positive Number = %d”, p);
printf (“\n\tTotal Negative Number = %d”, n);
getch() ;
}
Flow chart:

File Save:
1. Select save as option from the file menu.
2. Write the file name as ‘Program 09’ in the ‘Save file as’ text box obtained
from ‘Save file as’ dialog box and click on the OK button (the directory
in which the file will be saved is C:\TC\BIN).
Running the program:
1. Clicking compile button from the compile menu will convert the file
from source code (the original program written in a high-level language)
to machine code (the machine language converted into binary language).
Any error will show for correction. Save the file again after editing.

2. To run or execute the program, press ctrl+F9 from the key board.
Explanation:
 Statements used in the above program are explained below:
 printf(“expression”)
 scanf(“input format”, &variable name)
 printf(“expression with output format”, variable name)
 if-else statement is the extended form of if statement. In that word
statement-1 will be executed if expression is true and statement-2 will
be executed if expression is false. The structure is as follows:
if(expression)
statement-1;
else statement-2;
 Expression- What we want to see on the monitor.

Input/Output format:
%d = The data type of the variable will be integer.
%f = The data type of the variable will be floating-point.
%c = The data type of the variable will be character.
Observation:
When the test is completed, input 50, -30, 40, 80, -25, 60, 45, 90, -35, 40 from the
keyboard and the following result is obtained:
Total Positive Number = 7
Total Negative Number = 3
Experiment No: 10
Experiment Name: Write a program to find the largest number among 10 numbers
received through keyboard.
Theory:
To find the largest number out of 10 numbers, first of all the numbers must be
stored in memory. This requires the use of array. An array is a collection or series
of data of the same type. Like other data structure (stack or queue etc) an array is a
data structure where data is written and read through indexing.
Uses of device:
 Hardware: A computer
 Software: Operating system- windows 10
Programming language- Turbo C++ compiler

Uses:
To complete the mentioned test, follow the procedure below for using the
equipment-

1. At the beginning of the work, check whether the electrical connection of the
computer is correct.

2. If the electrical connection is correct, the computer should be turned on by


turning on the power switch on the computer.
3. Check whether the mentioned software is installed on the computer.
4. The required program must be launched to complete the test described.
5. After the test is completed, the running programs should be closed and the
computer must be shut down according to the rules. If necessary, turn off the
electrical switch and disconnect the power.
Activities :
To complete the test, work according to the procedure described below:
Double-click on the icon located on the desktop, open the complier and write
the following program code in the code building editor:

#include<stdio.h>
#include<conio.h>
void main ()
{
int i, j, h;
int number [10];
clrscr ();
for (i=0; i<=9; i++)
{
printf(“Enter your number =”);
scanf(“%d”, &number [i]);
}
h= number [0];
for (i=1; i<=9; i++)
{
if (h<number[j])
h= number[j];
}
printf(“\n\tThe highest number is = %d”, h);
getch();
}
Flow chart:

 File Save :
1. Select save as option from the file menu.
2. Write the file name as ‘Program 09’ in the ‘Save file as’ text box obtained
from ‘Save file as’ dialog box and click on the OK button (the directory
in which the file will be saved is C:\TC\BIN).
Running the program:
1. Clicking compile button from the compile menu will convert the file
from source code (the original program written in a high-level language)
to machine code (the machine language converted into binary language).
Any error will show for correction. Save the file again after editing.

2. To run or execute the program, press ctrl+F9 from the key board.

Explanation:
 Statements used in the above program are explained below:
 printf(“expression”)
 scanf(“input format”, &variable name)
 printf(“expression with output format”, variable name)
 if-else statement is the extended form of if statement. In that word
statement-1 will be executed if expression is true and statement-2 will
be executed if expression is false. The structure is as follows:
if(expression)
statement-1;
else statement-2;
 Expression- What we want to see on the monitor.
Input/Output format:
%d = The data type of the variable will be integer.
%f = The data type of the variable will be floating-point.
%c = The data type of the variable will be character.
Observation :
When the test is completed, input 30,40,10,20,50,30,40,60,50,30 from the
keyboard and the following result is obtained:
The highest number is = 60
Experiment No: 11
Experiment Name: Write a program to find the factorial value of a positive
integer received through the keyboard.
Theory:
The factorial of a positive integer is the product of every number from that number
up to 1, So the factorial of 5 is 5*4*3*2*1= 120. Note that, the factorial value of
zero (0) is 1. Factorials are used for computations in recursion methods in
programming and for group-based decision making in mathematics. Factorial is
denoted by ! symbol in mathematics.
Uses of device:
 Hardware: A computer
 Software: Operating system- windows 10
Programming language- Turbo C++ compiler
Uses:
 To complete the mentioned test, follow the procedure below for using the
equipment-

1. At the beginning of the work, check whether the electrical connection of the
computer is correct.

2. If the electrical connection is correct, the computer should be turned on by


turning on the power switch on the computer.
3. Check whether the mentioned software is installed on the computer.
4. The required program must be launched to complete the test described.
5. After the test is completed, the running programs should be closed and the
computer must be shut down according to the rules. If necessary, turn off the
electrical switch and disconnect the power.
Activities :
To complete the test, work according to the procedure described below:
Double-click on the icon located on the desktop, open the complier and write
the following program code in the code building editor:
#include<stdio.h>
#include<conio.h>
void main ()
{
int f=1, x;
clrscr();
printf(“Enter number =”);
scanf(“%d”, &x);
if (x==0)
f=f;
else
{
do
{
f=f*x;
x=x-1;
} while (x>1);
}
printf(“\n\tFactorial value = %d”, f);
getch();
}
Flow chart:

File Save :
1. Select save as option from the file menu.
2. Write the file name as ‘Program 09’ in the ‘Save file as’ text box obtained
from ‘Save file as’ dialog box and click on the OK button (the directory
in which the file will be saved is C:\TC\BIN).

Running the program:


1. Clicking compile button from the compile menu will convert the file from
source code (the original program written in a high-level language) to
machine code (the machine language converted into binary language). Any
error will show for correction. Save the file again after editing.

2. To run or execute the program, press ctrl+F9 from the key board.

Explanation:
 Statements used in the above program are explained below:
 printf(“expression”)
 scanf(“input format”, &variable name)
 printf(“expression with output format”, variable name)
 if-else statement is the extended form of if statement. In that word
statement-1 will be executed if expression is true and statement-2 will
be executed if expression is false. The structure is as follows:
if(expression)
statement-1;
else statement-2;
 Expression- What we want to see on the monitor.
Input/Output format:
%d = The data type of the variable will be integer.
%f = The data type of the variable will be floating-point.
%c = The data type of the variable will be character.
Observation:
When the test is completed, taking input as 5 through the keyboard will give the
following result:
Factorial value = 120

You might also like