C Program 1 To 11
C Program 1 To 11
Uses:
To complete the above experiment, the steps of using devices are as follows:
Activities:
File Save :
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:
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 Devices:
Hardware: A computer
Software:
o Operating system – Windows 7
o Programming language
o Turbo C++ Compiler
Uses:
To complete the above experiment, the steps of using devices are as follows:
Activities:
File Save:
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 100 as Celsius scale
temperature, the following result will be shown.:
Area = ƒ𝑠 ∗ (𝑠 − 𝑎) ∗ (𝑠 − 𝑏) ∗ (𝑠 − 𝑐)
(a+b+c)
Where s =
2
a
Uses of Devices:
Hardware: A computer
Software:
o Operating system – Windows 7
o Programming language
o Turbo C++ Compiler
Uses:
To complete the above experiment, the steps of using devices are as follows:
File Save:
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:
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:
Uses of Devices:
Hardware: A computer
Software:
o Operating system – Windows 7
o Programming language
o Turbo C++ Compiler
Uses:
To complete the above experiment, the steps of using devices are as follows:
Program:
File Save:
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:
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 Devices:
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.
Activities:
File Save :
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.
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:
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.
Activities:
File Save :
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:
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.
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.
#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).
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.
#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.
#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.
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).
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