Lab Manual 5 EXP
Lab Manual 5 EXP
C PROGRAMMING
LAB (3045)
LAB MANUAL 2023-24
1|Page
PROGRAMMING IN C LAB MANUAL
C language
Introduction:
C is a programming language developed by Dennis Ritchie at AT&T‟s BELL
Laboratory of USA in 1972. Because of its reliability, C is very popular. C is highly
portable & it is well suited for structured programming. C program consists of
collection of functions.
Hardware Requirement:
Desktop Computer/ Laptop computer
Software Requirement:
Linux Operating System with GCC/ Turbo C/C++ or Windows Operating
System with Code::Blocks IDE.
Code::Blocks IDE:
2|Page
PROGRAMMING IN C LAB MANUAL
The console application wizard will appear next. Continue through the
menus, selecting C when prompted for a language. In the next screen, give the
project a name and type or select a destination folder. Code::Blocks will
generate the remaining entries from these two.
Finally, the wizard will ask if this project should use the default compiler
(normally GCC) and the two default builds: Debug and Release. All of these
settings are fine. Press finish and the project will be generated. The main
window will turn gray, but that is not a problem, the source file needs only to
be opened. In the Projects tab of the Management pane on the left expand the
folders and double click on the source file main.cpp to open it in the editor.
To run the program, select "Build" menu ⇒ Run. Now the output screen can be seen.
3|Page
PROGRAMMING IN C LAB MANUAL
EXPERIMENT NO: 1
INPUTTING AN INTEGER
PROGRAM LOGIC: The number entered is stored in a variable declared as integer data type.
The value of the variable is printed on screen as integer.
Start
Input an integer
Stop
4|Page
PROGRAMMING IN C LAB MANUAL
PROGRAM:
main()
{
int number; //variable declaration
printf("ENTER AN INTEGER NUMBER-\n");
scanf("%d",&number);//reading the number
printf("THE NUMBER YOU ENTERED IS-%d",number);
}
OUTPUT:
ENTER AN INTEGER NUMBER-
123
THE NUMBER YOU ENTERED IS-123
RESULT: The program has been successfully executed and observed the output.
5|Page
PROGRAMMING IN C LAB MANUAL
EXPERIMENT NO: 2
INPUTTING A CHARACTER
AIM : Write a C program to interactively get a character from keyboard and display its ASCII value.
PROGRAM LOGIC: The character is read in to a variable of character data type. The value of the
character is displayed on screen as an integer, which is nothing but the ASCII value of the character.
PROGRAM:
main()
{
char my_alphabet; // declaration
printf("ENTER A CHARACTER-");
my_alphabet=getchar(); // getting the alphabet
printf("THE ASCII VALUE OF ‘%c’ IS %d",my_alphabet,my_alphabet);
}
Start
Input a character
Stop
6|Page
PROGRAMMING IN C LAB MANUAL
OUTPUT:
ENTER A CHARACTER-S
THE ASCII VALUE OF ‘S’ IS 83
RESULT: The program has been successfully executed and observed the output.
7|Page
PROGRAMMING IN C LAB MANUAL
EXPERIMENT NO: 3
PROGRAM LOGIC: The two numbers to be added are read as two variables. The sum of the two
numbers is calculated and displayed.
Start
Stop
8|Page
PROGRAMMING IN C LAB MANUAL
PROGRAM:
#include <stdio.h>
#include <stdlib.h>
int main()
{
int num1,num2,sum;
OUTPUT:
ENTER TWO NUMBERS- 3
RESULT: The program has been successfully executed and observed the output.
9|Page
PROGRAMMING IN C LAB MANUAL
EXPERIMENT NO: 4
PROGRAM LOGIC: The two numbers to be subtracted are read as two variables. The difference of
the two numbers is calculated and displayed.
Start
Stop
10 | P a g e
PROGRAMMING IN C LAB MANUAL
PROGRAM:
#include <stdio.h>
#include <stdlib.h>
int main()
{
int num1,num2,diff;
OUTPUT:
ENTER TWO NUMBERS- 7
RESULT: The program has been successfully executed and observed the output.
11 | P a g e
PROGRAMMING IN C LAB MANUAL
EXPERIMENT NO: 5
PROGRAM LOGIC: The two numbers to be multiplied and divided are read as two variables. The
multiplication and division of the two numbers is calculated and displayed as two variables. It is to be
ensured that the second number entered is non-zero.
Start
Stop
12 | P a g e
PROGRAMMING IN C LAB MANUAL
PROGRAM:
#include <stdio.h>
#include <stdlib.h>
int main()
{
int num1,num2,product, div;
OUTPUT:
ENTER TWO NUMBERS- 15
RESULT: The program has been successfully executed and observed the output.
13 | P a g e
PROGRAMMING IN C LAB MANUAL
Appendix I
ASCII Table
Dec = Decimal Value
Char = Character
14 | P a g e