Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
9 views79 pages

PF Lab Manual

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

PF Lab Manual

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

EXP.

NO : 1
INTRODUCTION ON LINUX OS AND ITS FILE SYSTEMS
DATE :

AIM

To study the concepts of Linux OS and its file systems.

LINUX OS INTRODUCTION
 The entire Linux directory structure starting at the top (/) root directory.
 A specific type of data storage format, such as EXT3, EXT4, BTRFS, XFS, and so on. Linux supports
almost 100 types of filesystems, including some very old ones as well as some of the newest. Each of these
filesystem types uses its own metadata structures to define how the data is stored and accessed.
 A partition or logical volume formatted with a specific type of filesystem that can be mounted on a
specified mount point on a Linux filesystem.

BASIC FILESYSTEM FUNCTIONS

Disk storage is a necessity that brings with it some interesting and inescapable details. Obviously, a
filesystem is designed to provide space for non-volatile storage of data; that is its ultimate function.
However, there are many other important functions that flow from that requirement.

All filesystems need to provide a namespace—that is, a naming and organizational methodology. This
defines how a file can be named, specifically the length of a filename and the subset of characters that can be
used for filenames out of the total set of characters available. It also defines the logical structure of the data on a
disk, such as the use of directories for organizing files instead of just lumping them all together in a single,
huge conglomeration of files.

Once the namespace has been defined, a metadata structure is necessary to provide the logical foundation for
that namespace. This includes the data structures required to support a hierarchical directory structure; structures
to determine which blocks of space on the disk are used and which are available; structures that allow for
maintaining the names of the files and directories; information about the files such as their size and times they
were created, modified or last accessed; and the location or locations of the data belonging to the file on the
disk. Other metadata is used to store high-level information about the subdivisions of the disk, such as logical
volumes and partitions. This higher-level metadata and the structures it represents contain the information
describing the filesystem stored on the drive or partition, but is separate from and independent of the filesystem
metadata.

Filesystems also require an Application Programming Interface (API) that provides access to system
function calls which manipulate filesystem objects like files and directories. APIs provide for tasks such as
creating, moving, and deleting files. It also provides algorithms that determine things like where a file is placed
on a filesystem. Such algorithms may account for objectives such as speed or minimizing disk fragmentation.

Modern filesystems also provide a security model, which is a scheme for defining access rights to files and
directories. The Linux filesystem security model helps to ensure that users only have access to their own files
and not those of others or the operating system itself.

1
The final building block is the software required to implement all of these functions. Linux uses a two-
part software implementation as a way to improve both system and programmer efficiency.

Figure 1: The Linux two-part filesystem software implementation.

DIRECTORY STRUCTURE

As a usually very organized Virgo, I like things stored in smaller, organized groups rather than in one big
bucket. The use of directories helps me to be able to store and then locate the files I want when I am
looking for them. Directories are also known as folders because they can be thought of as folders in
which files are kept in a sort of physical desktop analogy.

In Linux and many other operating systems, directories can be structured in a tree-like hierarchy. The
Linux directory structure is well defined and documented in the Linux Filesystem Hierarchy Standard
(FHS). Referencing those directories when accessing them is accomplished by using the sequentially
deeper directory names connected by forward slashes (/) such as /var/log and /var/spool/mail. These are
called paths.

The following table provides a very brief list of the standard, well-known, and defined top-level Linux
directories and their purposes.

Directory Description

/(root The root filesystem is the top-level directory of the filesystem. It must
filesystem) contain all of the files required to boot the Linux system before other
filesystems are mounted. It must include all of the required executables
and libraries required to boot the remaining filesystems. After the
system is booted, all other filesystems are mounted on standard, well-
defined mount points as subdirectories of the root filesystem.

/bin The /bin directory contains user executable files.

/boot Contains the static bootloader and kernel executable and configuration
files required to boot a Linux computer.

/dev This directory contains the device files for every hardware device
attached to the system. These are not device drivers, rather they are files
that represent each device on the computer and facilitate access to those
devices.

/etc Contains the local system configuration files for the host computer.

2
/home Home directory storage for user files. Each user has a subdirectory in
/home.

/lib Contains shared library files that are required to boot the system.

/media A place to mount external removable media devices such as USB thumb
drives that may be connected to the host.

/mnt A temporary mountpoint for regular filesystems (as in not removable


media) that can be used while the administrator is repairing or working
on a filesystem.

/opt Optional files such as vendor supplied application programs should be


located here.

/root This is not the root (/) filesystem. It is the home directory for the root
user.

/sbin System binary files. These are executables used for system
administration.

/tmp Temporary directory. Used by the operating system and many programs
to store temporary files. Users may also store files here temporarily.
Note that files stored here may be deleted at any time without prior
notice.
/usr These are shareable, read-only files, including executable binaries and
libraries, man files, and other types of documentation.

/var Variable data files are stored here. This can include things like log files,
MySQL, and other database files, web server data files, email inboxes,
and much more.

Table 1: The top level of the Linux filesystem hierarchy.

RESULT
Thus, the introduction to Linux systems and its file systems has been studied successfully.

3
4
EXP. NO : 2
BASIC LINUX COMMANDS
DATE :

AIM :
To study and execute basic LINUX commands.

COMMANDS :

1) Who

Description :Print information about users who are currently logged in.

Synopsis :who[OPTION]….[ FILE ARG 1 ARG 2 ]

Output :who

Demo : 0 2018-06-23 09:35 (0:)

2) Who am I

Description :Print the user name associated with the current effective user id.

Synopsis :who am I [OPTION]

Output :who am I

3) Date
Description :The date command is used to print out, or change the value of, the system's
time and date information.
Synopsis :date[ OPTIONS ]…[FORMAT+] Date[-u]—utc|--universal]
[MMDDhhmm[[cc]YY][.ss]
Output: Thu Feb 8 16:47:32 MST 2001
4) Cal
Description :The cal command displays a simple, formatted calendar in your terminal.

Synopsis :cal [ month ] [ year ] [ m-month ] [y- year ] [ -3 ] [ -h ] [ -1 ] [ - A num ]


[- B num ] [ -d YYYY-MM ] [- j ] [-N]

5
Output: April 2016

Su Mo Tu We Fr Sa
Th
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15
16
17 19 20 22 23
18 21
24 25 26 27 28 29 30

5) Man:
Description: Man is the system’s manual pager. Each page argument given to man is
Normally the name of program , utility or function.
Synopsis :man [-c file ][-d][-D] [--warnings [warnings]] [-R encoding ] [ -L locate ]
[-m system[ ….] ] [ -M path ] [ -s list ] [ -e extension ] [ -I | -l ] [ --no
Justification ] [-p string ] [ - T [device]] [ -H [browser]] [[section ]page.. Section ]…]
Output: man date
( displays reference manual of date)

6) Pwd

Description : print the full filename of the current working directory.

Synopsis :pwd [OPTION]….

Output:pwd/home/demo

7) Ls

Description:List information about the files (the current directory by default)

Synopsis:ls [OPTIONS]…..[FILE]..

Output: ls
Desktop downloads hello helloworld
Music pictures templates videos

8) Echo
Description :Echo the strings to standard input
Synopsis :echo [SHORT-OPTION ] …[STRING]…
Echo [LONG-OPTION]

6
7
Output :echo hello
Hello
9) Head

Description: Print the first 10 lines of the file to standard output. With more than one file,
precode each file with a header giving to filename.

Synopsis :head [OPTIONS]…[FILE]

Output :head num 10

1
2
3
10) Tail

Description :Print the last 10 lines of the file to standard output. With more than one file,
precode each file with a header giving to filename.

Synopsis :tail [OPTION]…[FILE]..

Output: tail 6
5
4
3
2
1

11) Mkdir
Description :Create a directory if they don’t exist already .
Synopsis: mkdir [OPTION ] …DIRECTORY..
Output :mkdir versatile
( a directory named “versatile” is created)

12) Rmdir:
Description: Remove the directory if they are empty.
Synopsis: rmdir[OPTION ] …DIRECTORY
Output: rmdir versatile
( the empty directory “versatile “ is removed)

8
13) cp :
Description :Copy source to destination or multiple sources to directory.
Synopsis: cp[OPTION ] …..[-r] SOURCE
DESTINATION cp [OPTION] ….SOURCE …DIRECTORY
cp[ OPTION] …-t DIRECTORY…SOURCE
Output: cp ok google(contents of ok file is copied to google file)

14) Mv
Description :Rename source to destination or move source to directory.
Synopsis :mv[OPTION ] ….[-T] SOURCE DEST mv[OPTION]…
SOURCE … DIRECTORY
Output: mv binary systems
(the contents of binary are moved to systems)

15) Rm
Description: rm removes the specified file . By default, it does not remove directories.
Synopsis: rm[OPTION]..[FILE]…
Output: rm sheet
(the file sheet is removed )
16) wc
Description : Print newline,word and byte counts for each FILE, and a total line if
more than one FILE is specified.
Synopsis : wc [OPTION]...[FILE]...
wc [OPTION]...- -fileso-from-f
Output : wc hello
1 1 6 hello.
17) expr
Description : Print the value of expression to standard output.
Synopsis : expr EXPRESSION
expr OPTION
Output : expr 6 + 7
13.

9
18) cat
Description : Concatenate files to standard output.
Synopsis : cat [OPTION]...[FILE]...

Output : cat > computer


(This command is used to add strings toa file or directory)
cat computer
(Displays contents of file or directory).

19) grep
Description : Grep searches for PATTERN in each FILE by default, grep points the
matching lines. In addition, three variant programs egrep, fgrep, rgrep.
Synopsis : grep [OPTION] PATTERN [FILE]...
grep [OPTION]-e PATTERN...[FILE]...
grep [OPTION]-f FILE...[FILE]...
Output : cot num 10 1 grep 2
2
(In a file with numbers 1 to 10, grep searches 2 and returns when found).

20) sort
Description : Write sorted concatenation of all FILE(s) to standard output.
Synopsis : sort [OPTION]...[FILE]...
sort [OPTION]...- -files 0 from –f
Output : sort names
(alphabetically arranges the strings in the file).

21) bc
Description : Bc is a language that supports arbitrary precision numbers with interactive
execution of statements.
Synopsis : bc [-nlwsqv] [long-options] [file]...
Output : echo “12+5” | bc
17

10
22) passwd
Description : The passwd command changes passwords for user accounts.
Synopsis : passwd [OPTION] [LOGIN]
Output : passwd
Changing password for demo.
(current) UNIX password:
Enter new UNIX password:
Retype new UNIX password:
passwd : password updated successfully.

23) clear
Description : Clears your screen, if this is possible, including its scrollback buffer.
Synopsis : clear [-T type] [-v] [-x]
Output : clear
(clears the terminal).
24) du
Description : Summarise disk usage of the set of FILE(s), recursively for directories.
Synopsis : du [OPTION]...[FILE]... -files 0 - from = f

Output : du hello
4 hello
25) nl
Description : Write each FILE to standard output, with line numbers added.
Synopsis : nl [OPTION]...[FILE]...
Output : nl atoj
1 a
2 b
3 c
4 d
5 e
6 f
7 g

11
26) df
Description : df displays the amount of disk space available on the file system containing
each file name argument.
It is helpful in finding the amount of space available for storing files.
It is an important command in linux environment.
Synopsis : df [OPTION]...[FILE]..

Output : df hello
Filesystem 1K-blocks Used Available Use% Mountedon
/dev/sda1 10253588 5366436 4346584 56% /
27) od
Description : Write an unambiguous representation, octal lengths by default of FILE to
standard output.
Synopsis : od [OPTION]...[FILE]...
od [-abcd filesx]... [FILE][ [+] OFFSET [.][b] ]
od [- -traditional [OPTION]...[FILE][ [+][LABEL][.][b] ]
Output : od hello
0000000 062550 0601154 005157 0000000

28) cut
Description : Print selected fonts of lines from each FILE to standard output.
Synopsis : cut[0 PT10]...[FILE]...
Output : ad – b 1,2 helloworld
he

29) paste
Description : Write lines consisting of the sequentially corresponding lines from each FILE
, separated by tabs,to standard output.
Synopsis : paste[OPTION]...[FILE]...
Output : paste Hello world
Hello world

12
30) cmp
Description : Compare two files byte by byte.
Synopsis : cmp [OPTION]... FILE1 [FILE2 [SKIP1[SKIP2] ] ]
Output : cmp Hello World
Hello World differ: byte1, line1.

RESULT:
Thus the basic LINUX commands were executed and the output was verified
successfully.

13
EXPERIMENT NO : 3
INTRODUCTION TO LINUX TOOL CHAINS
DATE :

AIM
To study about the Linux tool chains.
LINUX TOOL CHAINS
 A tool chain is a set of distinct software development tools that are linked together by
specific stages such as GCC, binutils and glibc .
 Optionally, a tool chain may contain other tools such as a debugger or a compiler for a
specific programming language, such as C++.
TOOLCHAIN COMPONENT
BINUTILS
The GNU Binutils is the first component of a toolchain. The GNU Binutils contains two very important
tools:
 as - the assembler, that turns assembly code (generated by GCC) to binary.
 ld - the linker, that links several object code into a library, or an executable.

C, C++, JAVA, ADA, FORTRAN, OBJECTIVE-C COMPILER

The second major component of a toolchain is the compiler. In the embedded Linux, the only realistic
solution today is GCC, the GNU Compiler Collection. Nowadays, as input, it not only supports C, but
also C++, Java, Fortran, Objective-C and Ada. As output, it supports a very wide range of
architectures.

C LIBRARY

The C library implements the traditional POSIX API that can be used to develop userspace
applications. It interfaces with the kernel through system calls and provides higher-level services.

Realistically, there are nowadays two options for the C Library:

 glibc - is the C library from the GNU project. It's the C library used by virtually all desktop
and server GNU/Linux systems. It's feature-full, portable, complies to standards, but a bit
bloated.
 Embedded GLIBC (EGLIBC) is a variant of the GNU C Library (GLIBC) optimized for
embedded systems - Its goals include reduced footprint, support for cross-compiling and
cross- testing, while maintaining source and binary compatibility with GLIBC. The project is
discontinued.
 uClibc - is an alternate C library, which features a much smaller footprint. This library can be an
interesting alternative if flash space and/or memory footprint is an issue.

14
 uClibc-ng - is a spin-off of uClibc C library. The main goal of the spin-off is to do
regular releases and do a lot of automatic runtime testing.
 musl - New standard C library. musl is lightweight, fast, simple, free, and strives to
be correct in the sense of standards-conformance and safety.

 The C library has a special relation with the C compiler, so the choice of the C library
must be done when the toolchain is generated. Once the toolchain has been built, it is
no longer possible to switch to another library.

DEBUGGER
The debugger is also usually part of the toolchain, as a cross-debugger is needed to
debug applications running on your target machine. In the embedded Linux world, the
typical debugger is GDB.
COMPILATION, LINKING, EXECUTING THE CODE IN VARIOUS STEPS
C IS A COMPILED LANGUAGE
 Its source code is written using any editor of a programmer’s choice in the form of
a text file, then it has to be compiled into machine code.
 C source files are by convention named with (.c extension) and we use the command
“gcc” to compile C source files. (GCC stands for GNU Compiler Collection and it is
a compiler system produced by the GNU Project.

FOUR STEPS OF COMPILATION

 PREPROCESSING
 COMPILING
 ASSEMBLY
 LINKING

PREPROCESSING

> cpp hello.c > hello.i

Preprocessing is the first step. The preprocessor obeys commands that begin with # (known as
directives) by:

 removing comments
 expanding macros
 expanding included files

If you included a header file such as #include <stdio.h>, it will look for the stdio.h file
and copy the header file into the source code file.

15
The preprocessor also generates macro code and replaces symbolic constants defined using
#define with their values.

COMPILING

> gcc -S hello.i

Compiling is the second step. It takes the output of the preprocessor and generates assembly
language, an intermediate human readable language, specific to the target processor.

ASSEMBLY
> as -o hello.o hello.s
Assembly is the third step of compilation. The assembler will convert the assembly code into
pure binary code or machine code (zeros and ones). This code is also known as object code.
LINKING
> ld -o hello.exe hello.o ...libraries...
Linking is the final step of compilation. The linker merges all the object code from multiple
modules into a single one. If we are using a function from libraries, linker will link our code
with that library function code.
In static linking, the linker makes a copy of all used library functions to the executable file. In
dynamic linking, the code is not copied, it is done by just placing the name of the library in the
binary file.
EXECUTABLE
After the four main stages through which a source code passes in order to finally become
an executable.
PROGRAM
 Let’s now compile! For our example, we’ll use “main.c” as our source file:
#include <stdio.h>int main(void)
{
printf("Hello, World!\n");
return (0);
}
 At the shell prompt, enter the command “gcc main.c” and hit Enter. If it successfully compiles,
the shell prompt will be displayed again. If it does not compile, it will display error
message(s).
vagrant@vagrant-ubuntu-trusty-64:~$ gcc main.c
vagrant@vagrant-ubuntu-trusty-64:~$ ls
a.out main.c
 After main.c is compiled, type the command “ls” to list your directory contents and you will
see an executable file named a.out. To run the program, type “./a.out” at the shell prompt
and hit Enter.

16
vagrant@vagrant-ubuntu-trusty-64:~$ ./a.out
Hello, World!
vagrant@vagrant-ubuntu-trusty-64:~$

 If you don’t want your output file to be named a.out, which is the default output filename,
you can specify a different output filename with the -o option.
gcc -o <desired_output_filename> <source filename>
 Let’s see an example below where we want the output file to be named main.
vagrant@vagrant-ubuntu-trusty-64:~$ gcc -o main
main.c vagrant@vagrant-ubuntu-trusty-64:~$ ls
main main.c
vagrant@vagrant-ubuntu-trusty-64:~$
 To run the main program, we type “./main” into the terminal.
vagrant@vagrant-ubuntu-trusty-64:~$ ./main
Hello, World!
vagrant@vagrant-ubuntu-trusty-64:~$
 If you make changes to your code (i.e. make any changes to your source file), you will need
to save and recompile.

RESULT
Hence, the Linux tool chains and its various stages have been Studied successfully.

17
Ex.No. 4 a
Date: PROGRAM USING OPERATORS

AIM
To write a C program to perform all the arithmetic operators.

ALGORITHM
Step 1: Start the process.
Step 2: Initialize the variables.
Step 3: Enter the arithmetic operators to be
performed. Step 4: Print the operators.
Step 5: End of process(exit).

PROGRAM
#include<stdio.h>
int main()
{
int a, b, c, d,
e; float f;
printf("a:",a);
scanf("%d",&a);
printf("b:",b);
scanf("%d",&b);
c=a+b;
d=a-b;
e=a*b;
f=a/b;
printf("Sum=%d\n",c);
printf("Difference=%d\n",d);
printf("Product=%d\n",e);
printf("Quotient=%d\n",c);
return 0;

SAMPLE OUTPUT:

RESULT:
Thus the C program to perform all the arithmetic operation was completed and the output was verified
successfully

18
Ex.No. 4 b
Date: PROGRAM TO FIND AREA OF SQUARE AND
RECTANGLE

AIM
To find the area of square and rectangle.

ALGORITHM
Step 1:a Start the process.
Step 2: Initialize the
variables.
Step 3: Enter the formulae of area of square and
rectangle. Step 4: Print the area of square and rectangle.
Step 5: End of process(exit).

PROGRAM

Area of square :

#include<stdio.h>
int main()
{
int side, area;
printf("\nEnter the Length of Side : "); scanf("%d",
&side); area = side * side;
printf("\nArea of Square : %d", area); return (0);
}

Area of rectangle :

#include <stdio.h>
int main()
{
int width;
int height;
printf("enter the width");
scanf("%d",&width);
printf("enter the height");
scanf("%d",&height);
int area=width*height;
printf("Area of the rectangle=%d",area);

19
20
SAMPLE OUTPUT :

Area of Square :

Area of rectangle :

RESULT:
Thus the C program to find the area of square and rectangle. was completed and the output was
verified successfully

21
Ex.No. 4 c
Date: PROGRAM TO FIND SQUARE ROOT OF NUMBER

AIM

To find Square root of

number ALGORITHM

Step 1: Start the process.


Step 2: Initialize the variables.
Step 3: Get the input (number) from the
user. Step 4: Find the square root of the
number.
Step 5:Display the number.
Step 6: End of
process(exit).

PROGRAM
#include<stdio.h>
#include<math.h>
int main()
{
int n;
double sr;
printf("Enter a Number:
"); scanf("%d",&n);
sr = sqrt(n);
printf("Square Root of %d is %f",n,sr);

OUTPUT

RESULT:
Thus the C program to find Square root of number was completed and the output was verified
successfully
22
23
Ex.No. 5 a
Date: ELIGIBILITY FOR VOTING

AIM

To write c program to find eligibility of voting using simple if-else statements.

ALGORITHM

Step 1: Start the process.


Step 2: Initialize the variables.
Step 3: Get the input age from the
user. Step 4: Check the eligibility for
voting.
Step 5:If true then print eligible else print not eligible.
Step 6: End of process(exit).

PROGRAM

#include<stdio.h>
int main()
{
int age;
printf("Enter your age:
"); scanf("%d",&age);
if(age>18)
printf("You are eligible for
voting"); else
printf("You are not eligible for
voting"); return 0;
}

OUTPUT

RESULT:
Thus the C program to find eligibility of voting using simple if-else statements was completed and
the output was verified successfully

24
Ex.No. 5 b
ODD or EVEN
Date:

AIM

To write a program to find given no is odd or even using simple if-else statements

ALGORITHM

Step 1: Start the process.


Step 2: Initialize the variables.
Step 3: Get the input (number) from the
user. Step 4: Check the condition for odd or
even. Step 5:If true then print even else print
odd. Step 6: End of process(exit).

PROGRAM
#include<stdio.h>
int main()
{
int n;
printf("Enter any number
"); scanf("%d",&n); if(n
%2==0)
printf("\n %dis an even
number",n); else
printf("\n %dis a odd
number",n); return 0;
}

OUTPUT

RESULT:
Thus the C program to find given no is odd or even using simple if-else statements was completed
and the output was verified successfully

25
Ex.No. 5 c
Date: LEAP YEAR or NOT

AIM

To write c program to find whether the given year is a leap year or not.

ALGORITHM

Step 1: Start the process.


Step 2: Initialize the variables.
Step 3: Get the input (year) from the
user. Step 4: Check the condition for leap
year.
Step 5:If true then print leap year else print not a leap
year. Step 6: End of process(exit).

PROGRAM

#include <stdio.h>
int main()
{
int year;
printf("enter a year :");
scanf("%d",&year);
if((year%4==0)&&((year%100!=0)||(year%400==0)))
{
printf("\n %d is a leap year ",year);
}
else
{
printf("\n %dit is not a leap year",year);
}
return 0;
}

OUTPUT

RESULT:
Thus the C program to find whether the given year is a leap year or not was completed and the
output was verified successfully

26
Ex.No. 5 d
Date: GREATEST OF THREE NUMBERS

AIM
To write c program to find greatest among three numbers using nested if-else statements.

ALGORITHM

Step 1: Start the process.


Step 2: Initialize the variables.
Step 3: Get the input (number) from the user.
Step 4: Check the condition for first two
numbers. Step 5: Check the condition for the
third number. Step 6: Print the greatest number.
Step 7: End of process(exit).

PROGRAM

#include<stdio.h>
int main()
{
int n1,n2,n3;
printf("\nEnter value of n1, n2 and
n3:"); scanf("%d %d
%d",&n1,&n2,&n3);
if((n1>n2)&&(n1>n3))
printf("\n Number1 is greatest");
else if((n2>n3)&&(n2>n1))
printf("\n Number2 is greatest");
else
printf("\n Number3 is
greatest"); return 0;
}

OUTPUT

RESULT:
Thus the C program to find greatest among three numbers using nested if-else statements was
completed and the output was verified successfully

27
Ex.No.5 e
Date: GRADING SYSTEM

AIM

To write c program to find the grade of obtained marks as given below: grade a= above 60 grade
b= 60-50 grade c= 50-30 grade f = less than 30

ALGORITHM
Step 1: Start the process.
Step 2: Initialize the variables.
Step 3: Get the input (alphabet) from the
user. Step 4: Check the condition for vowels.
Step 5: Print the vowels.
Step 6: End of process(exit).

PROGRAM

#include<stdio.h>
int main()

{
int score;
char grade;
printf("Enter score(0-100): ");
scanf("%d",&score);
if(score<0 || score>100)
{
printf("Invalid Score");
return 0;
}
if(score>=60 &&
score<=100) grade = 'A';
else if(score>60 &&
score<=50) grade = 'B
else if(score>50 &&
score<=30) grade = 'C';
else
grade = 'F';
printf("Grade: %c\n", grade);
return 0;
}

28
OUTPUT

RESULT:
Thus the C program to find the grade of obtained marks was completed and the output was
verified successfully

29
Ex.No.6 a
ARITHMETIC OPERATION
Date:

AIM
To write c program to do arithmetic operations (+,-,*, /) using switch case.

ALGORITHM

Step 1: Start the process.


Step 2: Initialize the variables.
Step 3: Get the input from the
user.
Step 4: Enter the case for the
operation. Step 5: Print the selected
case.
Step 7: End of process(exit).

PROGRAM

#include<stdio.h>
#include<conio.h>
int main()
{
int a,b;
int c;
printf(" 1.Addition\n 2.Subtraction\n 3.Multiplication\n 4.Division\
n"); printf("Enter the values of a & b: ");
scanf("%d %d",&a,&b);
printf("Enter your Choice :
"); scanf("%d",&c);
switch(c)
{
case 1 :
printf("Sum of %d and %d is :
%d",a,b,a+b); break;
case 2 :
printf("Difference of %d and %d is : %d",a,b,a-
b); break;
case 3 :
printf("Multiplication of %d and %d is :
%d",a,b,a*b); break;
case 4 :
printf("Division of Two Numbers is %d : ",a/b);
break;
default :
printf(" Enter Your Correct
Choice."); break;
}
return 0;
30
}

31
OUTPUT

RESULT:
Thus the C program to do arithmetic operations (+,-,*, /) using switch case was completed
and the output was verified successfully

32
Ex.No.6 b
VOWELS or CONSONANTS
Date:

AIM

To write c program to check the character is vowel or consonants using switch case.

ALGORITHM

Step 1: Start the process.


Step 2: Initialize the variables.
Step 3: Get the input from the
user.
Step 4: Check the condition for vowels.
Step 5: Print the selected case.
Step 6: End of process(exit).

PROGRAM

#include <stdio.h>

int main()
{
char ch;

printf("Enter any alphabet:


"); scanf("%c", &ch);
switch(ch)
{
case 'a':
printf("Vowel");
break;
case 'e':
printf("Vowel");
break;
case 'i':
printf("Vowel");
break;
case 'o':
printf("Vowel");
break;
case 'u':
printf("Vowel");
break;

33
case 'A':
printf("Vowel");
break;
case 'E':
printf("Vowel");
break;
case 'I':
printf("Vowel");
break;
case 'O':
printf("Vowel");
break;
case 'U':
printf("Vowel");
break;
default:
printf("Consonant");
}

return 0;
}

OUTPUT

RESULT:
Thus the C program to check the character is vowel or consonants using switch case was
completed and the output was verified successfully

34
Ex.No.7 a
FACTORIAL OF A NUMBER
Date:

AIM

To write c program to find the factorial of a given number using for while and do while loop.

ALGORITHM
Step 1: Start the process.
Step 2: Initialize the variables.
Step 3: Get the input from the
user.
Step 4: Check the condition for factorial.
Step 5: Print the factorial of the number.
Step 6: End of process(exit).

PROGRAM

Using for loop :

#include<stdio.h>
int main()
{
int i,f=1,num;
printf("Enter a number:
"); scanf("%d",&num);
for(i=1;i<=num;i++)
f=f*i;

printf("Factorial of %d is:
%d",num,f); return 0;

35
Using while loop :

#include <stdio.h>
int main()
{
int n,i,f;
f=i=1;
printf("Enter a Number to Find Factorial:
"); scanf("%d",&n);
while(i<=n)
{
f*=i;
i++;
}
printf("The Factorial of %d is : %
d",n,f); return 0;
}

Using do while loop :

#include<stdio.h>
#include<conio.h> void
main()
{
int n,i=1,f=1;
printf("\n Enter The Number:");
scanf("%d",&n);
do
{
f=f*i;
i++;
}while(i<=n);
printf("\n The Factorial of %d is %d",n,f); getch();
}

36
OUTPUT :

Using for loop

Using while loop

Using do while loop

RESULT:
Thus the C program to find the factorial of a given number using for while and do while
loop was completed and the output was verified successfully

37
Ex.No. 7 b
Date: FIBONACCI SERIES

AIM

To write c program to find the Fibonacci series using 'for loop'.

ALGORITHM

Step 1: Start the process.


Step 2: Initialize the variables.
Step 3: Get the input from the
user.
Step 4: Enter the looping for Fibonacci
series. Step 5: Print the Fibonacci series.
Step 6: End of process(exit).
PROGRAM
#include <stdio.h>
int main()
{
int i, n, a=0,b=1,c;
printf("Enter the number of terms: ");
scanf("%d", &n);
printf("%d %d",a,b);
c=a+b;
for (i = 3; i <= n; ++i)
{
printf(" %d",c);
a = b;
b = c;
c = a + b;
}
return 0;
}

OUTPUT

RESULT:
Thus the C program to find the Fibonacci series using 'for loop' was completed and the output was
verified successfully.

38
Ex.No.7 c ARMSTRONG NUMBER
Date:

AIM

To write c program to find the Armstrong number using 'do while loop'.

ALGORITHM
Step 1: Start the process.
Step 2: Initialize the variables.
Step 3: Get the input from the
user.
Step 4: Check the condition for Armstrong
number Step 5: Print the output for Armstrong
number.
Step 6: End of process(exit).

PROGRAM

#include<stdio.h>
#include<conio.h>
void main()
{
int no,b,sum=0,temp;

printf("Enter the
Number:");
scanf("%d",&no);
temp=no;

do
{
b=no%10;
sum=sum+b*b*b;
no=no/10;
} while(no>0);
if(sum==temp)
{
printf("Number is Armstrong");
}
else
{
printf("Number is not Armstrong");
}

getch();

OUTPUT

RESULT:

39
Thus the C program to find the Armstrong number using 'do while loop' was completed and the
output was verified successfully.

40
Ex.No. 7 d
Date: FLOYD’S TRIANGLE AND PASCALS TRIANGLE

AIM:
To Write c program to print Floyd’s triangle pattern and Pascals triangle pattern using 'for loop' and
'while loop' respectively. Using 'switch case' to choose any of the options.

ALGORITHM:
Step 1 :start
Step 2:using switch case get value a(floyd triangle) or b(pascals triangle).
Step 3:case a:declare variables i, j, rows. Input the number of rows.
Step 4:using for loops print * for the given number of rows.
Step 5:case b:initialize rows,i,j,space,count=1.
Step 6:get the number of rows and print the desired output using while
loop. Step 7:stop.

PROGRAM:

Floyd’s triangle :
#include <stdio.h>
int main()
{
int n, i, c, a = 1;

printf("Enter the number of rows of Floyd's triangle to print\n");


scanf("%d", &n);

for (i = 1; i <= n; i++)


{
for (c = 1; c <= i; c++)
{
printf("%d ", a); // Please note space after
%d a++;
}
printf("\n");
}

return 0;
}

41
Pascals triangle:

#include <stdio.h>
int main()
{
int rows, cal = 1, space, i, j;

printf("Enter number of rows: ");


scanf("%d",&rows);

for(i=0; i<rows; i++)


{
for(space=1; space <= rows-i; space++)
printf(" ");

for(j=0; j <= i; j++)


{
if (j==0 || i==0)
cal = 1;
else
cal = cal*(i-j+1)/j;

printf("%4d", cal);
}
printf("\n");
}

return 0;

OUTPUT :

Floyd’s triangle

Pascals triangle

RESULT:
Thus the C program to print Floyd’s triangle pattern and Pascals triangle pattern using 'for loop'
and 'while loop' was completed and the output was verified successfully.

42
Ex.No.8 a
Date: SMALLEST/ LARGEST ELEMENT OF THE
ARRAY.

AIM:
To Write program to print the smallest/largest element of the array.

ALGORITHM:
Step 1:Start
Step 2:declare the variables arr[100], n, i, small,
large Step 3:input the array elements
Step 4: Initialize small = large = arr[0]
Step 5:using for loop,check condition if(arr[i] > large) large = arr[i] if(arr[i] < small) small = arr[i]
Step 6:print output large/small
Step 7:stop

PROGRAM:
#include <stdio.h>
int main()
{
int arr[100], n, i, small, large;
printf("Enter the number of elements:
"); scanf("%d", &n);
for (i = 0; i < n; i++)
{
printf("Enter element %d : ", i +
1); scanf("%d", &arr[i]);
}
small =
arr[0]; large =
arr[0];
for (i = 1; i < n; i++)
{
if (arr[i] < small)
{
small = arr[i];
}
if (arr[i] > large)
{
large = arr[i];
}
}
printf("\nLargest element is : %d", large);
printf("\nSmallest element is : %d", small);
return 0;
}
43
44
RESULT:
Thus the C program to print the smallest/largest element of the array was completed and the
output was verified successfully.

45
Ex.No.8 b
Date: 3X3 MATRIX AND PERFORM MATRIX
ADDITION.
AIM:
To Write to program to create 3x3 matrix and perform matrix addition.

ALGORITHM:
Step 1:start
Step 2:initialize r, c, a[100][100], b[100][100], sum[100][100], i, j.
Step 3: input the number of rows and columns.
Step 4:get the elements of 1st matrix and 2nd matrix using for
loops. Step 5:store the addition by sum[i][j] = a[i][j] + b[i][j].
Step 6:by the end of the loop,the result of addition is stored in
sum. Step 7:stop.

PROGRAM:
#include <stdio.h>
int main()
{
int r, c, a[100][100], b[100][100], sum[100][100], i, j;
printf("Enter the number of rows (between 1 and 100):
"); scanf("%d", &r);
printf("Enter the number of columns (between 1 and 100): ");
scanf("%d", &c);
printf("\nEnter elements of 1st matrix:\
n"); for (i = 0; i < r; ++i)
for (j = 0; j < c; ++j)
{
printf("Enter element a%d%d: ", i + 1, j +
1); scanf("%d", &a[i][j]);
}
printf("Enter elements of 2nd matrix:\n");
for (i = 0; i < r; ++i)
for (j = 0; j < c; ++j)
{
printf("Enter element b%d%d: ", i + 1, j +
1); scanf("%d", &b[i][j]);
}
for (i = 0; i < r; ++i)
for (j = 0; j < c; +
+j)
{
sum[i][j] = a[i][j] + b[i][j];
}
printf("\nSum of two matrices: \n");
for (i = 0; i < r; ++i)
46
for (j = 0; j < c; ++j)

47
{
printf("%d ", sum[i][j]);
if (j == c - 1)
{
printf("\n\n");
}
}
return 0;
}

OUTPUT

RESULT:
Thus the C program to create 3x3 matrix and perform matrix addition was completed and
the output was verified successfully.

48
Ex.No.8 c
Date: REVERSING THE ARRAY ELEMENTS

AIM:

To write a C program for reversing the array

elements. ALGORITHM:

Step 1:start
Step 2:initialize variable i, j, array1[50], array2[50].
Step 3:input the number of array elements and elements of the array using
for loop. Step 4:store and display the reversed array.
Step 5:stop.

PROGRAM:

#include <stdio.h>
int main()
{
int num, i, j, array1[50], array2[50];
printf("Enter no of elements in array\n");
scanf("%d", &num);
printf("Enter array elements\n");
for (i = 0; i < num ; i++)
scanf("%d", &array1[i]);
for (i = num - 1, j = 0; i >= 0; i--,j+
+) array2[j] = array1[i];
for (i = 0; i < num; i++)

array1[i] = array2[i];
printf("The reversed array:\
n"); for (i = 0; i< num; i++)
printf("%d\n", array1[i]);
return 0;
}

49
OUTPUT

RESULT:
Thus the C program for reversing the array elements was completed and the output was verified
successfully.

50
Ex.No. 9 a
Date: PALINDROME

AIM:
To write a program to display the string is palindrome or not.

ALGORITHM:
Step 1: Start
Step 2: read the string
Step 3: store reverse of the given string in a temporary
string Step 4: compare the two strings
Step 5: if both are equal then print
palindrome Step 6: otherwise print not
palindrome
Step 7: Stop

PROGRAM :
#include <stdio.h>
#include <string.h>
int main()
{
char string1[20];
int i, length;
int flag = 0;
printf("Enter a string:");
scanf("%s", string1);
length = strlen(string1);
for(i=0;i < length ;i++)
{
if(string1[i] != string1[length-i-1])
{ flag = 1;
break;
}
}
if (flag) {
printf("%s is not a palindrome", string1);
}
else {
printf("%s is a palindrome", string1);
}
return 0;
}
OUTPUT :

RESULT:
Thus the C program to display the string is palindrome or not was completed and the output was
51
verified successfully.

52
Ex.No. 9 b INDIVIDUAL CHARACTERS OF STRING IN REVERSE ORDER
Date:

AIM :

To write the program to reverse the string

given. ALGORITHM:

Step 1: Start
Step 2: Take the string which you have to reverse as the input variable says
str. Step 3: Reverse the string using strrev() function
Step 4: Print the reversed
string. Step 5: Stop.

PROGRAM:

#include <stdio.h>
#include <stdlib.h>
#include<string.h>
void main()
{
char str[20];
int l,i;
printf("***Print individual characters of string in reverse order***\n");
printf("Enter input string : ");
fgets(str, sizeof str, stdin);
printf("The characters in reverse are : \n");
l=strlen(str);
for(i=l-1;i>=0;i--)
{
printf("%c ", str[i]);

}
printf("\n");
}

OUTPUT

RESULT:
Thus the C program to reverse the string given was completed and the output was verified
successfully.

53
Ex.No. 9 c
Date: PROGRAM USING STRING HANDLING FUNCTIONS

AIM:

To write the program using one of the types of string

function. ALGORITHM:

Step 1 : Start.
Step 2 : Initialize the char a.
Step 3 : Measure the length using function
strlen(). Step 4 : Print the strlen(a).
Step 5 : Stop.

PROGRAM:

#include<stdio.h>
#include<string.h>
main()
{
char a[10],b[10];
int ch,len;
printf("enter str1
"); scanf("%s",a);
printf("enter str2
"); scanf("%s",b);
while(1)
{
printf("\n choose ur option");
printf("\n 1.length\n 2.compare\n 3.copy\n 4.concat\n");
printf("enter ur choice: ");
scanf("%d",&ch);
switch(ch)
{
case 1: len=strlen(a);
printf("length is %d\n",len);
break;
case 2:if(strcmp(a,b)==0)
{
printf("both strings are equal\n");
}
else
if(strcmp(a,b)>0)
printf("%s is greater than %s\
n",a,b); else
printf("%s is greater than %s\
n",b,a); break;
case 3: printf(" str1 %s\n",a);
printf("str2 %s\n",b);
strcpy(a,b);
printf("after copy strings are\n");

54
printf(" str1 %s\n",a);
printf("str2 %s\n",b);
break;
case 4:printf(" str1 %s\n",a);
printf("str2 %s\n",b);
strcat(a,b);
printf(" str1 %s\n",a);
break;
}
}
}

OUTPUT

RESULT:
Thus the C program to use the string handling functions was completed and the output
was verified successfully.

55
Ex.No. 10 a
STUDENT DETAIL
Date:

AIM:
To Write a C program to find student details using Structure.

ALGORITHM:
Step 1: Start
Step 2: Get the number of Students whose details are to be stored.
Step 3: Create a variable of Student structure to access the records
Step 4: After all the data is stored, print the records of each
students Step 5: Stop.

PROGRAM:
#include <stdio.h>
struct student
{
char firstName[50];
int roll;
float marks;
}
s[5];
int main()
{
int i;
printf("Enter information of students:\n");
for (i = 0; i <= 2; ++i)
{
s[i].roll = i + 1;
printf("\nFor roll number%d,\n",
s[i].roll); printf("Enter first name: ");
scanf("%s", s[i].firstName);
printf("Enter marks: ");
scanf("%f", &s[i].marks);
}
printf("Displaying Information:\n\n"); for
(i = 0; i <=2; ++i) {
printf("\nRoll number: %d\n", i +
1); printf("First name: ");
puts(s[i].firstName);
printf("Marks: %.1f",
s[i].marks); printf("\n");
}
return 0;
}

56
OUTPUT

RESULT

Thus the C program to find student details using Structure has been executed and the output was
verified successfully.

57
Ex.No. 10 b
EMPLOYEE RECORD
Date:

AIM:

To Write a C program to store Employee record using Structure.

ALGORITHM:

Step 1: Start
Step 2: Define one structure to hold the details of an
employee. Step 3: Define variables of this structure.
Step 4: Enter the details one by one and store them in the variable
details. Step 5: Print
Step 6: Stop

PROGRAM

#include <stdio.h>
struct employee
{ char name[30];
int empId;

float salary;
}
int main()
{
struct employee emp;
printf("\nEnter details :\n");
printf("Name ?:");
gets(emp.name);
printf("ID ?:");
scanf("%d",&emp.empId);
printf("Salary ?:");
scanf("%f",&emp.salary);
printf("\nEntered detail is:");
printf("Name: %s" ,emp.name);
printf("Id: %d",emp.empId);
printf("Salary: %f\n",emp.salary);
return 0;
}

58
RESULT

Thus the C program to store Employee record using Structure has been executed and the output
was verified successfully.

59
Ex.No. 11 a
Date: SWAP TWO VALUES

AIM
To Swap two values using call by value and call by reference.

ALGORITHM

Step 1: Start the process.


Step 2: Initialize the variables.
Step 3: Get the input from the
user. Step 4:Perform the
operation.
Step 5: Print the operation .
Step 6: End of
process(exit).

PROGRAM

Call by value

#include <stdio.h>,
void swap(int x, int
y)
{
int temp =
x; x = y;
y = temp;
}

int main()
{
int x, y;
printf("\nSwapping of two numbers using call by value\n");
printf("Enter Value of x ");
scanf("%d", &x); printf("\
nEnter Value of y ");
scanf("%d", &y);
printf("\nBefore Swapping: x = %d, y = %d", x,
y); swap(x, y);
printf("\nAfter Swapping: x = %d, y = %d", x,
y); return 0;
}

Call by reference

#include <stdio.h>
void swap(int *xp, int *yp)
{
int temp = *xp;
*xp = *yp;
*yp = temp;
}

int main()
{
60
int x, y;
printf("--SWAPPING OF TWO NUMBERS USING CALL BY REFERENCE--");

61
printf("Enter Value of x ");
scanf("%d", &x); printf("\
nEnter Value of y ");
scanf("%d", &y);
printf("\nBefore Swapping: x = %d ,y = %d",x,y);
swap(&x, &y);
printf("\nAfter Swapping: x = %d, y = %d", x, y);
return 0};

OUTPUT:

Call by value

call by reference

RESULT:
Thus the C program to swap two values using call by value and call by reference was
completed and the output was verified successfully.

62
Ex.No.11 b
Date: SQUARE OF THE NUMBER

AIM
To find the square of the given numbers using functions.

ALGORITHM
Step 1: Start the process.
Step 2: Initialize the variables.
Step 3: Get the input from the
user. Step 4:Perform the
operation. Step 5: Print the
operation .
Step 6: End of process(exit).

PROGRAM

#include <stdio.h>
int find_square_number(int num)
{
return num*num;
}
int main()
{
int num;
printf("Enter the Number:");
scanf("%d", &num);
int square_of_number=find_square_number(num);
printf("Square of Given Number is:
%d",square_of_number);
}

OUTPUT

RESULT:
Thus the C program to find the square of the given numbers using functions was completed
and the output was verified successfully.
63
64
EXPERIMENT NO : 11 c

GDB PROFILER COMMANDS


DATE :

AIM
To study about GDB Profiler.
INTRODUCTION
 GNU or GDB debugger is an application for finding out how your C or C++ program
runs or for analyzing the moment the program crashes.

 You can perform many useful tasks with GDB: run the program, stop the program
under specific conditions, analyze the situation, make modifications, and test new
changes.

COMPLILING
 To prepare your program for debugging with gdb, you must compile it with the -g flag.

 So, if your program is in a source file called memsim.c and you want to put the
executable in the file memsim.

 Then you would compile with the following command: gcc -g -o memsim memsim.c.

INVOKING AND QUITTING GDB


 To start gdb, just type gdb at the unix prompt.

 Or, you can start gdb and give it the name of the program executable you want to
debug by saying

GDB EXCUTABLE
 To exit the program just type quit at the (gdb) prompt.

 Actually just typing q is good enough.

COMMANDS

1. help
Gdb provides online documentation. Just typing help will give you a list of topics. Then
you can type help topic to get information about that topic. Or you can just type help
command and get information about any other command.

2. file
File executable specifies which program you want to debug.

62
65
66
3. run
Run will start the program running under gdb. The program that starts will be the one
that you have previously selected with the file command, or on the unix command line
when you started gdb. You can even do input/output redirection: run > outfile.txt.
4. break
A ``breakpoint'' is a spot in your program where you would like to temporarily stop
execution in order to check the values of variables, or to try to find out where the
program is crashing, etc. To set a breakpoint you use the break command. Break
function sets the breakpoint at the beginning of function. If your code is in multiple files,
you might need to specify filename: function.
5. break linenumber
It sets the breakpoint to the given line number in the source file. Execution will stop
before that line has been executed.
6. delete
Delete will delete all breakpoints that you have set. Delete number will delete breakpoint
numbered number. You can find out what number each breakpoint is by doing info
breakpoints.
7. clear
Clear function will delete the breakpoint set at that function. Similarly for linenumber,
filename:function, and filename:linenumber.
8. continue
Continue will set the program running again, after you have stopped it at a breakpoint.
9. step
Step will go ahead and execute the current source line, and then stop execution again
before the next source line.
10. next
Next will continue until the next source line in the current function. This is similar to
step, except that if the line about to be executed is a function call, then that function call
will be completely executed before execution stops again, whereas with step execution
will stop at the first line of the function that is called.
11. until
Until is like next, except that if you are at the end of a loop, until will continue execution
until the loop is exited, whereas next will just take you back up to the beginning of the
loop. This is convenient if you want to see what happens after the loop, but don't want to
step through every iteration.
12. list
List linenumber will print out some lines from the source code around linenumber. If
you give it the argument function it will print out lines from the beginning of that
function. Just list without any arguments will print out the lines just after the lines that
you printed out with the previous list command.
13. print
Print expression will print out the value of the expression, which could be just a variable
name. To print out the first 25 (for example) values in an array called list, do print
list[0]@25.

63
67
A SAMPLE C PROGRAM WITH ERRORS FOR DEBUGGING PURPOSE

68
LET US DEBUG IT WHILE REVIEWING THE MOST USEFUL COMMANDS IN GDB

STEP 1: Compile the C program with debugging option –g.


Compile your C program with -g option. This allows the compiler to collect the
debugging information.

STEP 2: Launch gdb.


Launch the C debugger (gdb) as shown below.

STEP 3: Set up a break point inside C program.

STEP 4: Execute the C program in gdb debugger.

69
STEP 5: Printing the variable values inside gdb debugger.

As you see above, in the factorial.c, we have not initialized the variable j. So, it gets garbage
value resulting in a big numbers as factorial values. Fix this issue by initializing variable j
with 1, compile the C program and execute it again.

Even after this fix there seems to be some problem in the factorial.c program, as it still gives
wrong factorial value. So, place the break point in 10th line.

STEP 6: Continue, stepping over and in – gdb commands.


There are three kind of gdb operations you can choose when the program stops at a break
point. They are continuing until the next break point, stepping in, or stepping over the
next program lines.

 c or continue: Debugger will continue executing until the next break point.
 n or next: Debugger will execute the next line as single instruction.
 s or step: Same as next, but does not treats function as a single instruction, instead
goes into the function and executes it line by line.

By continuing or stepping through you could have found that the issue is because we have not
used the <= in the ‘for loop’ condition checking. So changing that from < to <= will solve the
issue.

70
GDB COMMANDS SHORTCUT

Use following shortcuts for most of the frequent gdb operations.

 l – list
 p – print
 c – continue
 s – step
 ENTER: pressing enter key would execute the previously executed command.

RESULT
Thus, the GDB Profiler was executed and the output was verified and studied successfully.

71
EXPERIMENT NO : 12 a
EXPERIMENT WITH FILE HANDLING
DATE :

AIM
To write a C program to read numbers from a file and write even, odd and prime numbers
to separate file.

ALGORITHM
Step 1: Start.

Step 2: Declaring File as pointer variables fptrIn, fptrEven, fptrOdd, fptrPrime.


Step 3: Open all the files in write mode.
Step 4: Find all the even, odd, prime numbers in the file.
Step 5: Print all the even, odd, prime numbers in the
file. Step 6: Close all the files.
Step 7: Stop.

72
73
PROGRAM

61
OUTPUT

RESULT

Thus, the C program to read numbers from a file and write even, odd and prime numbers
to separate file was executed and output was verified successfully.

62
EXPERIMENT NO : 12 b
EXPERIMENT WITH COMMANDLINE ARGUMENTS
DATE :

AIM
To write a C program to read a number and string from command line and print whether
they are palindrome.
ALGORITHM

Step 1: Start.

Step 2: Get the string or number from the user.

Step 3: Check whether the string or number is same in the reverse also.

Step 4: If so print the result is Yes.

Step 5: Else , print the the result is

No. Step 6: Stop.

PROGRAM

63
64
OUTPUT

RESULT
Thus, C program to read a number and string from command line and print whether they
are palindrome was executed and the output was verified successfully.

65

You might also like