0% found this document useful (0 votes)
25 views15 pages

Lab Manual 5 EXP

Uploaded by

Divya Krishna
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views15 pages

Lab Manual 5 EXP

Uploaded by

Divya Krishna
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 15

FUNDAMENTALS OF

C PROGRAMMING
LAB (3045)
LAB MANUAL 2023-24

GOVERNMENT WOMEN’S POLYTESVHNIC COLLEGE | KOTTAKKAL, MALAPPURAM


PROGRAMMING IN C LAB MANUAL

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:

CodeBlocks is an open-source, cross-platform (Windows, Linux, MacOS), and


free C/C++ IDE. It supports many compilers, such as GNU GCC (MinGW and
Cygwin) and MS Visual C++. It supports interactive debugging (via GNU GDB or
MS CDB).

Code::Blocks offers a very flexible and comprehensive project management


and is versatile. In Code::Blocks, the sources and the settings for the build process
are stored in a project file <name>.cbp. C/C++ sources and the corresponding header
files are the typical components of a project. The easiest way to create a new project
is executing the command ’File’ →’Project’ and selecting a wizard.

Code::Blocks governs the project files in categories according to their file


extensions. These are the preset categories:

Sources includes source files with the extensions *.c;*.cpp;.

ASM Sources includes source files with the extensions *.s;*.S;*.ss;*.asm.

Headers includes, among others, files with the extension *.h;.

2|Page
PROGRAMMING IN C LAB MANUAL

Creating a new project using Code::Blocks:

Open Code::Blocks from your desktop or programs menu.

Launch the Project Wizard through File->New->Project... to start a new


project. Here there are many pre-configured templates for various types of
projects, including the option to create custom templates. Select Console
application, as this is the most common for general purposes, an click Go.

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.

This file contains the following standard code. main.c


#include <stdio.h>
#include <stdlib.h>
int main()
{
printf("Hello world!\n");
return 0;
}
To build the program, select "Build" menu ⇒ Build

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

AIM : Write a C program to interactively get an integer and display it on screen.

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.

ALGORITHM: (to be written on left side of record)


Step 1: Start
Step 2: Input an integer
Step 3: Display the integer
Step 4: Stop

FLOW CHART: (to be drawn on left side of record)

Start

Input an integer

Display the 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);
}

ALGORITHM: (to be written on left side of record)


Step 1: Start
Step 2: Input a character
Step 3: Display the ASCII value of the character
Step 4: Stop

FLOW CHART: (to be drawn on left side of record)

Start

Input a character

Display the ASCII


value of the 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

ADDITION OF TWO NUMBERS


AIM: To write a C program to find the sum of two given numbers.

PROGRAM LOGIC: The two numbers to be added are read as two variables. The sum of the two
numbers is calculated and displayed.

ALGORITHM: (to be written on left side of record)


Step 1: Start
Step 2: Input num1, num2
Step 3: sum = num1+num2
Step 4: Display the sum
Step 4: Stop

FLOW CHART: (to be drawn on left side of record)

Start

Input two numbers

Sum = num1 + num2

Display the sum

Stop

8|Page
PROGRAMMING IN C LAB MANUAL

PROGRAM:
#include <stdio.h>
#include <stdlib.h>
int main()
{
int num1,num2,sum;

printf("ENTER TWO NUMBERs-");


scanf("%d %d",&num1, &num2);//reading the inputs
sum= num1 + num2;//calculate sum of the numbers
printf("THE SUM OF %d and %d IS-%d\n",num1,num2,sum);
return 0;
}

OUTPUT:
ENTER TWO NUMBERS- 3

THE SUM OF 3 AND 4 IS 7

RESULT: The program has been successfully executed and observed the output.

9|Page
PROGRAMMING IN C LAB MANUAL

EXPERIMENT NO: 4

SUBRACTION OF TWO NUMBERS


AIM: To write a C program to find the difference of two given numbers.

PROGRAM LOGIC: The two numbers to be subtracted are read as two variables. The difference of
the two numbers is calculated and displayed.

ALGORITHM: (to be written on left side of record)


Step 1: Start
Step 2: Input num1, num2
Step 3: difference = num1 - num2
Step 4: Display the difference
Step 4: Stop

FLOW CHART: (to be drawn on left side of record)

Start

Input two numbers

Difference = num1 - num2

Display the difference

Stop

10 | P a g e
PROGRAMMING IN C LAB MANUAL

PROGRAM:
#include <stdio.h>
#include <stdlib.h>
int main()
{
int num1,num2,diff;

printf("ENTER TWO NUMBERs-");


scanf("%d %d",&num1, &num2);//reading the inputs
difference= num1 - num2;//calculate difference of the numbers
printf("THE DIFFERENCE OF %d and %d IS-
%d\n",num1,num2,difference);
return 0;
}

OUTPUT:
ENTER TWO NUMBERS- 7

THE DIFFERENCE OF 7 AND 4 IS 3

RESULT: The program has been successfully executed and observed the output.

11 | P a g e
PROGRAMMING IN C LAB MANUAL

EXPERIMENT NO: 5

MULTIPLICATION AND DIVISION OF TWO NUMBERS


AIM: To write a C program to find the multiplication and division of two given numbers.

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.

ALGORITHM: (to be written on left side of record)


Step 1: Start
Step 2: Input num1, num2
Step 3: product = num1 * num2
Step 4: div = num1/num2
Step 4: Display the product and quotient obtained
Step 4: Stop

FLOW CHART: (to be drawn on left side of record)

Start

Input two numbers

product = num1 * num2

div = num1 / num2

Display the product

Display the quotient

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;

printf("ENTER TWO NUMBERs-");


scanf("%d %d",&num1, &num2);//reading the inputs
product= num1 * num2;//calculate product of the numbers
div= num1 / num2;//divide to get quotient of the numbers
printf("THE PRODUCT OF %d and %d IS-%d\n",num1,num2,product);
printf("THE DIVISION OF %d and %d IS-%f\n",num1,num2,div);
return 0;
}

OUTPUT:
ENTER TWO NUMBERS- 15

THE PRODUCT OF 15 AND 3 IS 45

THE DIVISION OF 15 AND 3 IS 5

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

'5' has the int value 53


if we write '5'-'0' it evaluates to 53-48, or the int 5
if we write char c = 'B'+32; then c stores 'b'

Dec Char Dec Char Dec Char Dec Char


--------- --------- --------- ----------
0 NUL (null) 32 SPACE 64 @ 96 `
1 SOH (start of heading) 33 ! 65 A 97 a
2 STX (start of text) 34 " 66 B 98 b
3 ETX (end of text) 35 # 67 C 99 c
4 EOT (end of transmission) 36 $ 68 D 100 d
5 ENQ (enquiry) 37 % 69 E 101 e
6 ACK (acknowledge) 38 & 70 F 102 f
7 BEL (bell) 39 ' 71 G 103 g
8 BS (backspace) 40 ( 72 H 104 h
9 TAB (horizontal tab) 41 ) 73 I 105 i
10 LF (NL line feed, new line) 42 * 74 J 106 j
11 VT (vertical tab) 43 + 75 K 107 k
12 FF (NP form feed, new page) 44 , 76 L 108 l
13 CR (carriage return) 45 - 77 M 109 m
14 SO (shift out) 46 . 78 N 110 n
15 SI (shift in) 47 / 79 O 111 o
16 DLE (data link escape) 48 0 80 P 112 p
17 DC1 (device control 1) 49 1 81 Q 113 q
18 DC2 (device control 2) 50 2 82 R 114 r
19 DC3 (device control 3) 51 3 83 S 115 s
20 DC4 (device control 4) 52 4 84 T 116 t
21 NAK (negative acknowledge) 53 5 85 U 117 u
22 SYN (synchronous idle) 54 6 86 V 118 v
23 ETB (end of trans. block) 55 7 87 W 119 w
24 CAN (cancel) 56 8 88 X 120 x
25 EM (end of medium) 57 9 89 Y 121 y
26 SUB (substitute) 58 : 90 Z 122 z
27 ESC (escape) 59 ; 91 [ 123 {
28 FS (file separator) 60 < 92 \ 124 |
29 GS (group separator) 61 = 93 ] 125 }
30 RS (record separator) 62 > 94 ^ 126 ~
31 US (unit separator) 63 ? 95 _ 127 DEL

14 | P a g e

You might also like