Thursday, November 13, 2008

C programs + flow chart

Gandhiji Institute Of Science & Technology Jaggiahpet-521175


Department of Computer Sciences

C and data structures
Lab Manual [Subject Code : CS ]
For the Academic year 2008-09
I B Tech – [Common to all Branches]
Document No: Verified By
Version: HOD CSE

Gandhiji Institute Of Science & Technology Jaggiahpet-521175
Department of Computer Science

LAB MANUAL FOR THE ACADEMIC YEAR 2008-09





SUB : C & DATA STRUCTURES

SUB CODE :

STREAM : COMMON TO ALL BRANCHES

INSTRUCTORS : 1.
2.

PROGRAMMERS : 1.

VENUE : LAB I/III (GROUND FLOOR)
BLOCK : CSE
INDEX

S.No CONTENT Page. No Credits/
Grads Faculty
Signature Remarks
If any
1 Introduction About Lab 4
2 Guidelines to Students 6
3 List of Lab Exercises
Syllabus Programs (JNTU)
7
4 Solutions for Programs 10
5 References 237


Result: ________________ Signature of the faculty incharge


INTRODUCTION:
ABOUT LAB:
There are 66 systems (Compaq Presario) installed in this Lab. Their configurations are as follows:
Processor : AMD Athelon ™ 1.67 GHz
RAM : 256 MB
Hard Disk : 40 GB
Optical Drive : 52X CD-ROM
Monitor : 15” CRT Color Monitor
Mouse : Optical Mouse
Key Board : 105 MMX Key Board
Network Topology : Star Topology
Network Interface card : Present

Software
1 All systems are configured in DUAL BOOT mode i.e, Students can boot from Windows XP or Linux as per their lab requirement.
This is very useful for students because they are familiar with different Operating Systems so that they can execute their programs in different programming environments.
2 Each student has a separate login for database access
Oracle 9i client version is installed in all systems. On the server, account for each student has been created.
This is very useful because students can save their work ( scenarios’, pl/sql programs, data related projects ,etc) in their own accounts. Each student work is safe and secure from other students.
3 Latest Technologies like DOT NET and J2EE are installed in some systems. Before submitting their final project, they can start doing mini project from 2nd year onwards.
4 MASM ( Macro Assembler ) is installed in all the systems
Students can execute their assembly language programs using MASM. MASM is very useful students because when they execute their programs
They can see contents of Processor Registers and how each instruction is being executed in the CPU.
1. Rational Rose Software is installed in some systems
Using this software, students can depict UML diagrams of their projects.
2 Softwares installed: C, C++, JDK1.5, MASM, OFFICE-XP, J2EE and DOT NET, Rational Rose.

3 Systems are provided for students in the 1:1 ratio.

4 Systems are assigned numbers and same system is allotted for students when they do the lab.

GUIDELINES TO STUDENTS:


1 Equipment in the lab for the use of student community. Students need to maintain a proper decorum in the computer lab. Students must use the equipment with care. Any damage is caused is punishable.
2 Students are required to carry their observation / programs book with completed exercises while entering the lab.
3 Students are supposed to occupy the machines allotted to them and are not supposed to talk or make noise in the lab. The allocation is put up on the lab notice board.
4 Lab can be used in free time / lunch hours by the students who need to use the systems should take prior permission from the lab in-charge.
5 Lab records need to be submitted on or before date of submission.
6 Students are not supposed to use floppy disks


LIST OF LAB EXERCISES:

PROGRAMS (AS PER JNTU SYLLABUS)
S No Name of the program Page no
WEEK1

a)
b)
c) Write C Programs for the Following
Sum of digits of a given number
Write a program to print Fibonacci series
To print prime up to n no
WEEK 2
a)

b) Write a C program to calculate the following Sum:
Sum=1-x2/2! +x4/4!-x6/6!+x8/8!-x10/10!
Write a C program to find the roots of a quadratic equation.
WEEK 3



a)
b) Write C Programs in both using recursive and non-recursive methods to find the following

Factorial of a given number
To find the GCD (greatest common divisor) of two given integers

WEEK 4
a)
b)
To perform the arithmetic expression using switch statement
WEEK 5
a)

b) Write a C program to find both the largest and smallest number in a list of integers
Write a C program that uses functions to perform the following:
i) Multiplication of Two Matrices
ii) Addition of Two Matrices
WEEK 6
a)




b) Write a C Program that uses functions to perform the following operations
i) To insert a given substring in to given main string from a given position
ii) To delete n Characters from a given position in a given string.
Write a C program to determine if the given string is a palindrome or not
WEEK 7
a)

b) Write a C program that displays the position or index in the string S
where the string T begins, or - 1 if S doesn't contain T.
Write a C program to count the lines, words and characters in a given text
WEEK 8
a)
b) Write a C program to generate Pascal's triangle.
Write a C program to construct a pyramid of numbers

WEEK 9
a) Write a C program to read in two numbers, x and n, and then compute the sum of this geometric progression:
1+x+x2+x3+………….+xn For example: if n is 3 and x is 5, then the program computes 1+5+25+125.
Print x, n, the sum Perform error checking. For example, the formula does not make sense
for negative exponents - if n is less than 0. Have your program print an error message if n<0,
then go back and read in the next pair of numbers of without computing the sum.
Are any values of x also illegal ? If so, test for them too.
WEEK 10
a)




b) 2’s complement of a number is obtained by scanning it from right to left and complementing all
the bits after the first appearance of a 1. Thus 2’s complement of 11100 is 00100.
Write a C program to find the 2’s complement of a binary number.
Write a C program to convert a Roman numeral to its decimal equivalent
WEEK 11
Write a C Program that performs the following
i) Reading a Complex number
ii) Writing a Complex number
iii) Addition of two Complex numbers
iv) Multiplication of two numbers
Note: represent complex number using a structure
WEEK 12
a)
b) Write a c Program which copies one file to another
Write a c Program to reverse the first n characters in a file
Note: The file name and n are specified on the command line
WEEK 13
Write a C program that uses functions to perform the following operations on single linked list.:
i) Creation
ii) Insertion
iii) Deletion
iv) Traversal

WEEK 14
Write a C program that uses functions to perform the following operations on double linked list.:
i) Creation
ii) Insertion
iii) Deletion
iv) Traversal

WEEK 15
Stack operations using i) arrays ii) Pointers
WEEK 16
C programs that implement queue (its operations) using
i) Arrays ii) pointers
WEEK 17
a)
b) Infix-postfix operations
Prefix-evaluation
WEEK 18
a) Write a C program that uses functions to perform the following:
i) Creating a Binary Tree of integers
ii) Traversing the above binary tree in preorder, inorder and postorder

WEEK 19
a)
b) Linear search
Binary search
WEEK 20
Bubble sort
Quick sort
WEEK 21
a)
b) Insertion sort
Merge sort
WEEK 22
a) Write C program to implement the Legrange Interpolation and Newton- Gregory forward interpolation
WEEK 23
a) Write C program to implement the linear regression and polynomial
WEEK 24
a) Write C program to implement Trapezoidal method and Simpson method.

SOLUTIONS FOR PROGRAMS (AS PER JNTU SYLLABUS)

WEEK 1

Name of the Experiment:

a) AIM: Program to find sum of digits of a number
Software/Hardware Requirements:

S/W: Turbo C, Office XP, Windows NT Server with Service Pack
H/W: Pentium IV, Intel Mother Board Processor, 40 GB HDD, 256 MB RAM

ALGORITHM:
Step1:start
Step2:input n,r,s
Step3:s=0
Step4:d=n%10
Step5:s=s+d
Step6:n=n/10
Step7: is n!=0
Step8: repeat step 4 to step 6 till step 7 is true
Step9:when step 7 falls
Step10:print s
Step11:stop


Test Data:

Valid Data Set:
Invalid Data Set:
Limiting Data Sets:

Name of the Experiment:

b) AIM: Program to print Fibonacci series

Software/Hardware Requirements:

S/W: Turbo C, Office XP, Windows NT Server with Service Pack
H/W: Pentium IV, Intel Mother Board Processor, 40 GB HDD,256 MB RAM

ALGORITHM:
Step1: start
Step2: read I, x, f,f1,f2
Step3: f=0,f1=1,f2=1
Step4: do
I++
F1=f2
F2=f
F=f1+f2
While (i<=n)
Step5: print f
Step6: stop



Test Data:

Valid Data Set:
Invalid Data Set:
Limiting Data Sets:

Name of the Experiment:

c) AIM: Program to generate prime number till nth number

Software/Hardware Requirements:

S/W: Turbo C, Office XP, Windows NT Server with Service Pack
H/W: Pentium IV, Intel Mother Board Processor, 40 GB HDD,256 MB RAM

ALGORITHM:
Step1: start
Step2: read n value
Step3: for i=1 i<=n
Step4: repeat a b c d e
a)factorial equal to 0
b) for i=1,j<=1 repeat c,d
c)if i percentage j equal to zero
d) fact equal to factorial added with one
e) if factorial equal to2print as prime number
Step5: display the prime no till nth num
Step56: stop


Test Data:

Valid Data Set:
Invalid Data Set:
Limiting Data Sets:

WEEK 2

Name of the Experiment:

a) AIM: Write a C program to calculate the following Sum:
Sum=1-x2/2! +x4/4!-x6/6!+x8/8!-x10/10!

Software/Hardware Requirements:

S/W: Turbo C, Office XP, Windows NT Server with Service Pack
H/W: Pentium IV, Intel Mother Board Processor, 40 GB HDD,256 MB RAM

ALGORITHM :

Step1: Start
Step2: read counter,f_coun,x,power,fact
Step3: for(counter=0, power=0; power<=10; counter++,power=power+2)
fact=1
Step4: for(f_coun=power; f_coun>=1; f_coun--)
fact *= f_coun
Step5: sum=sum+(pow(-1,counter)*(pow(x,power)/fact));
Step6: print sum
Step7: Stop


Test Data:

Valid Data Set:
Invalid Data Set:
Limiting Data Sets:

Name of the Experiment:

b) AIM: Write a C program to find the roots of a quadratic equation.

Software/Hardware Requirements:

S/W: Turbo C, Office XP, Windows NT Server with Service Pack
H/W: Pentium IV, Intel Mother Board Processor, 40 GB HDD,256 MB RAM

ALGORITHM:

Step1: Start
Step2: read a,b,c
Step3: d=sqrt(b*b-4*a*c)
Step4: if(d==0)
Root1=-b/2*a
Root2=-b/2*a
print Root1,Root2
Step5: else if(d>0)
Root1=-d/2*a
Root2=d/2*a
print Root1,Root2
Step6: else if(d<0)
Print ’Imaginary roots’
Step7: Stop


Test Data:

Valid Data Set:
Invalid Data Set:
Limiting Data Sets:








WEEK 3:

Name of the Experiment:

a) AIM: Program to find the factorial of a given number
Software/Hardware Requirements:

S/W: Turbo C, Office XP, Windows NT Server with Service Pack
H/W: Pentium IV, Intel Mother Board Processor, 40 GB HDD,256 MB RAM
ALGORITHM:
Step1: start
Step2: input n,I,f
Step3: f=i=1
Step4: if(i<=n)
Step5: f=f*i
Step6: i=i+1
Step7: repeat from step5 to step6 till steps true
Step8: print f
tep9: stop


Test Data:

Valid Data Set:
Invalid Data Set:
Limiting Data Sets:

Name of the Experiment:


b) AIM: Write C programs that use both recursive and non-recursive functions
To find the GCD (greatest common divisor) of two given integers

ALGORITHM:

Step1: Start
Step2: read a,b
Step3: if(n>m)
rem=p-(p/q*q)
if(rem==0)
return q
else
rem=q-(q/rem*rem)
repeat the step3
Step4: else if(n==0)
return m
Step5: else if
return p-(p/p%q)
Step6: Stop


Test Data:

Valid Data Set:
Invalid Data Set:
Limiting Data Sets:
WEEK 4:

Name of the Experiment:

AIM: Program to perform the arithmetic expression using switch statement
Software/Hardware Requirements:

S/W: Turbo C, Office XP, Windows NT Server with Service Pack
H/W: Pentium IV, Intel Mother Board Processor, 40 GB HDD, 256 MB RAM
ALGORITHM:
Step1:start
Step2:input a,b
Step3:switch(result)
Step4:case ‘+’:print num of a& b is a+b
Step5: case ‘-’:print num of a& b is a-b
Step6: case ‘*’:print num of a& b is a*b
Step7: case ‘/’:print num of a& b is a/b
Step8: case ‘%’:print num of a& b is a%b
Step9: default: invalid option
Step10: stop

3 comments:

KARTHIK said...

orey yedava, programs pettav, bagane vundi.
flow charts avi ra?????
neku burra dobinda?
programs & flow charts ani pedda aksharalutho headding pettadam kadu.
ee sari nunchi flow charts kuda pettadam nerchuko.
yedava sannasi

ZuBaiR said...

avunu be flow charts avi ???

sanjay varma said...

Appreciation for nice Updates, I found something new and folks can get useful info about BEST ONLINE TRAINING