LABORATORY MANUAL. (CSE-103F) FCPC Lab

Similar documents
PROGRAMMING IN C LAB MANUAL FOR DIPLOMA IN ECE/EEE

Tutorial No. 2 - Solution (Overview of C)

Programming I Laboratory - lesson 01

Unit 3 Decision making, Looping and Arrays

Programming in C Lab

/* Area and circumference of a circle */ /*celsius to fahrenheit*/

PESIT Bangalore South Campus Hosur road, 1km before Electronic City, Bengaluru -100 Department of Basic Science and Humanities

Lab Manual B.Tech 1 st Year

Arrays. Arrays are of 3 types One dimensional array Two dimensional array Multidimensional array

Developed By: P.Venkateshwarlu, Alphores Womens Degree College, Karimnagar

1) Write a C Program to check whether given year is Leap year or not. AIM: A C Program to check whether given year is Leap year or not.

F.E. Sem. II. Structured Programming Approach

PROGRAMMING WITH C-LANGUAGE (EL-255) For S.E(EL)

International Journal of Mathematics & Computing. Research Article

C PROGRAMMING. Prof. (Dr.) S. N. Mishra (Prof. & Head, Dept. of CSEA, IGIT, Sarang)


Programming and Data Structures Mid-Semester - Solutions to Sample Questions Dept. of Computer Science and Engg. IIT Kharagpur Spring

Computers Programming Course 12. Iulian Năstac

Numerical Method (2068 Third Batch)

BCSE1002: Computer Programming and Problem Solving LAB MANUAL

PESIT Bangalore South Campus Hosur Road (1km before Electronic City), Bengaluru Department of Basic Science and Humanities

P.E.S. INSTITUTE OF TECHNOLOGY BANGALORE SOUTH CAMPUS 1 ST INTERNAL ASSESMENT TEST (SCEME AND SOLUTIONS)

Unit 1 - Arrays. 1 What is an array? Explain with Example. What are the advantages of using an array?

Subject: Fundamental of Computer Programming 2068

Q 1. Attempt any TEN of the following:

DEV BHOOMI INSTITUTE OF TECHNOLOGY

M4.1-R3: PROGRAMMING AND PROBLEM SOLVING THROUGH C LANGUAGE

Object Oriented Programming Using C++ Mathematics & Computing IET, Katunayake

Program. SUBJECT: ACP (C - Programming) Array Program. // Find the minimum number from given N element. Prepared By : Dhaval R.

WAP 10. WAP 11. WAP 12. WAP 13. WAP 14. WAP 15. WAP 16. WAP 1. : 17. WAP 18. WAP 19. WAP 20. WAP 21. WAP 22. WAP 23. WAP & 24. WAP

LAB MANUAL LAB. Regulation : 2013 Branch. : B.E. All Branches Year & Semester : I Year / I Semester GE6161 COMPUTER PRACTICES

Decision Making and Branching

C library = Header files + Reserved words + main method

Classification s of Data Structures

1. Simple if statement. 2. if else statement. 3. Nested if else statement. 4. else if ladder 1. Simple if statement

Array Initialization

Subject: PROBLEM SOLVING THROUGH C Time: 3 Hours Max. Marks: 100

C Program. Output. Hi everyone. #include <stdio.h> main () { printf ( Hi everyone\n ); }

'C' Programming Language

Computer Programming. C Array is a collection of data belongings to the same data type. data_type array_name[array_size];

P.E.S. INSTITUTE OF TECHNOLOGY BANGALORE SOUTH CAMPUS DEPARTMENT OF SCIENCE AND HUMANITIES EVEN SEMESTER FEB 2017

PESIT Bangalore South Campus Hosur road, 1km before Electronic City, Bengaluru -100 Department of Basic Science and Humanities

MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION

Arrays in C. By Mrs. Manisha Kuveskar.

7.STRINGS. Data Structure Management (330701) 1

1. FIBONACCI SERIES. Write a C++ program to generate the Fibonacci for n terms. To write a C++ program to generate the Fibonacci for n terms.

MAHALAKSHMI ENGINEERING COLLEGE B TIRUCHIRAPALLI

Worksheet 4 Basic Input functions and Mathematical Operators

Solution Set(Reference Book - Programming with c By Byron Gottfried Thrid Edition)

FUNCTIONS OMPAL SINGH

MODULE 2: Branching and Looping

Saini Technologies ADVANCED C PROGRAMMING WITH SAINI TECHNOLOGIES. Sushil Kumar Saini Mo.

TEST BDA24202 / BTI10202 COMPUTER PROGRAMMING May 2013

CS11001/CS11002 Programming and Data Structures (PDS) (Theory: 3-1-0) Introduction to arrays

2. First C. Algorithm

Worksheet 11 Multi Dimensional Array and String


MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION (Autonomous) (ISO/IEC Certified)

F.E. Sem. II. Structured Programming Approach

Unit 5. Decision Making and Looping. School of Science and Technology INTRODUCTION

Multiple Choice Questions ( 1 mark)

UNIT 3 FUNCTIONS AND ARRAYS

Government Polytechnic Muzaffarpur.

MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION (Autonomous) (ISO/IEC Certified) MODEL ANSWER

PDS Lab Section 16 Autumn Tutorial 3. C Programming Constructs

Pointers and scanf() Steven R. Bagley


SRI VIDYA COLLEGE OF ENGINEERING & TECHNOLOGY, VIRUDHUNAGAR Department of CSE & IT Internal Test I

UNDERSTANDING THE COMPUTER S MEMORY

What is recursion. WAP to find sum of n natural numbers using recursion (5)

CSE101-Lec#18. Multidimensional Arrays Application of arrays. Created By: Amanpreet Kaur & Sanjeev Kumar SME (CSE) LPU. LPU CSE101 C Programming

SOFTWARE TESTING LABORATORY. Subject Code: 10ISL68 I.A. Marks: 25 Hours/Week: 03 Exam Hours: 03 Total Hours: 42 Exam Marks: 50

List of Programs: Programs: 1. Polynomial addition

THE BAPATLA ENGINEERING COLLEGE:: BAPATLA DEPARTMENT OF MCA. Subject name: C programing Lab. Subject code: MCA 107. LAB manual of c programing lab

GE Computer Practices Lab

only in the space provided. Do the rough work in the space provided for it. The question paper has total 12 pages.

Question Bank (SPA SEM II)

Contents. Sr. No. Title of the Practical: Page no Signature. Gate. OR gate. EX-OR gate. gate. identifying ODD and EVEN number.

Tribhuvan University Institute of Science and Technology 2065

UNIT III ARRAYS AND STRINGS

Problem # 1. calculate the grade. Allow a student the next grade if he/she needs only 0.5 marks to obtain the next grade. Use else-if construction.

Prepared by: Shraddha Modi

UIC. C Programming Primer. Bharathidasan University

Programming & Data Structure Laboratory. Day 2, July 24, 2014

Computers Programming Course 7. Iulian Năstac

AMCAT Automata Coding Sample Questions And Answers

Fundamentals of Computer Programming Using C

The inverse of a matrix

Ex. No. 3 C PROGRAMMING

CS11001/CS11002 Programming and Data Structures (PDS) (Theory: 3-0-0)

Overview of Transformations (18 marks) In many applications, changes in orientations, size, and shape are accomplished with

Case Control Structure. Rab Nawaz Jadoon DCS. Assistant Professor. Department of Computer Science. COMSATS IIT, Abbottabad Pakistan

Available online through ISSN

Chapter 11 Introduction to Programming in C

United States Naval Academy Electrical and Computer Engineering Department EC310-6 Week Midterm Spring AY2017

Sample Paper - II Subject Computer Science

Array. Arijit Mondal. Dept. of Computer Science & Engineering Indian Institute of Technology Patna IIT Patna 1

Single Dimension Arrays

UNIT - II Selections Statements Iteration Statements Jump Statements- Expression Statements - Block Statements. Single Dimensional Arrays Generating

The program simply pushes all of the characters of the string into the stack. Then it pops and display until the stack is empty.

Transcription:

LABORATORY MANUAL (CSE-103F) FCPC Lab Department of Computer Science & Engineering BRCM College of Engineering & Technology Bahal, Haryana

Aim: Main aim of this course is to understand and solve logical & mathematical problems through C language and Flowchart. Strengthen knowledge of a procedural programming language. Design and develop solutions to intermediate level problems using the C language. Further develop your skills in software development using a procedural language. Objectives: The C language is a simple computer language designed to enable sophisticated object-oriented programming. C is defined as a small but powerful set of extensions to the standard ANSI C language. Its additions to C are mostly based on Smalltalk, one of the first object-oriented programming languages. C is designed to give C full object-oriented programming capabilities, and to do so in a simple and straightforward way. Most object-oriented development environments consist of several parts: An object-oriented programming language A library of objects A suite of development tools A runtime environment

DESCRIPTION OF SCHEDULE: S.No List of Experiments 1. Introduction of Turbo C IDE and Programming Environment. 2. Write a program to find the largest of three numbers. (if-then-else) 3. Write a program to find the largest of ten numbers (for-statement) 4. Write a program to find the average mail height & average female heights in the class (input is in the form of sex code, height). 5. Write a program to find roots of a quadratic equation using functions and switch statements. 6. Write a program using arrays to find the largest and second largest numbers out of given 50 numbers. 7. Write a program to multiply two matrices. 8. Write a program to read a string and write it in reverse order. 9. Write a program to concatenate two strings of different lengths. 10 Write a program to check that the input string is a palindrome or not. 11. Programs on file handling. Lab No. 01

OBJECTIVE: Introduction of Turbo C IDE and Programming Environment THEORY The Development Environment - Integrated Development Environment (IDE): The Turbo C compiler has its own built-in text editor. The files you create with text editor are called source files, and for C++ they typically are named with the extension.cpp,.cp, or.c. The C Developing Environment, also called as Programmer s Platform, is a screen display with windows and pull-down menus. The program listing, error messages and other information are displayed in separate windows. The menus may be used to invoke all the operations necessary to develop the program, including editing, compiling, linking, and debugging and program execution. Invoking the IDE To invoke the IDE from the windows you need to double click the TC icon in the directory c:\tc\bin. The alternate approach is that we can make a shortcut of tc.exe on the desktop. This makes you enter the IDE interface, which initially displays only a menu bar at the top of the screen and a status line below will appear. The menu bar displays the menu names and the status line tells what various function keys will do. Default Directory The default directory of Turbo C compiler is c:\tc\bin.

Using Menus If the menu bar is inactive, it may be invoked by pressing the [F10] function key. To select different menu, move the highlight left or right with cursor (arrow) keys. You can also revoke the selection by pressing the key combination for the specific menu. Opening New Window To type a program, you need to open an Edit Window. For this, open file menu and click new. A window will appear on the screen where the program may be typed.

Writing a Program When the Edit window is active, the program may be typed. Use the certain key combinations to perform specific edit functions. Saving a Program To save the program, select save command from the file menu. This function can also be performed by pressing the [F2] button. A dialog box will appear asking for the path and name of the file. Provide an appropriate and unique file name. You can save the program after compiling too but saving it before compilation is more appropriate. Making an Executable File The source file is required to be turned into an executable file. This is called Making of the.exe file. The steps required to create an executable file are: 1. Create a source file, with a.c extension. 2. Compile the source code into a file with the.obj extension. 3. Link your.obj file with any needed libraries to produce an executable program. All the above steps can be done by using Run option from the menu bar or using key combination Ctrl+F9 (By this linking & compiling is done in one step).

Compiling the Source Code Although the source code in your file is somewhat cryptic, and anyone who doesn't know C will struggle to understand what it is for, it is still in what we call humanreadable form. But, for the computer to understand this source code, it must be converted into machine-readable form. This is done by using a compiler. Hence, compiling is the process in which source code is translated into machine understandable language. It can be done by selecting Compile option from menu bar or using key combination Alt+F9. Creating an Executable File with the Linker After your source code is compiled, an object file is produced. This file is often named with the extension.obj. This is still not an executable program, however. To turn this into an executable program, you must run your linker. C programs are typically created by linking together one or more OBJ files with one or more libraries. A library is a collection of linkable files that were supplied with your compiler. Compiling and linking in the IDE In the Turbo C IDE, compiling and linking can be performed together in one step. There are two ways to do this: you can select Make EXE from the compile menu, or you can press the [F9] key. Executing a Program If the program is compiled and linked without errors, the program is executed by selecting Run from the Run Menu or by pressing the [Ctrl+F9] key combination. The Development Cycle If every program worked the first time you tried it that would be the complete development cycle: Write the program, compile the source code, link the program, and run it. Unfortunately, almost every program, no matter how trivial, can and will have errors, or bugs, in the program. Some bugs will cause the compile to fail, some will cause the link to fail, and some will only show up when you run the program.

Whatever type of bug you find, you must fix it, and that involves editing your source code, recompiling and relinking, and then rerunning the program. Correcting Errors If the compiler recognizes some error, it will let you know through the Compiler window. You ll see that the number of errors is not listed as 0, and the word Error appears instead of the word Success at the bottom of the window. The errors are to be removed by returning to the edit window. Usually these errors are a result of a typing mistake. The compiler will not only tell you what you did wrong; they ll point you to the exact place in your code where you made the mistake. Exiting IDE An Edit window may be closed in a number of different ways. You can click on the small square in the upper left corner, you can select close from the window menu, or you can press the [Alt][F3] combination. To exit from the IDE, select [Alt][X] Combination. EXERCISE Exit from the File Menu or press 1. Type the following program in C Editor and execute it. Mention the Error. void main(void) printf( This is my first program in C );

Lab No. 02 OBJECTIVE: Write a program to find the largest of three numbers. (if-then-else) #include<stdio.h> #include<conio.h> void main( ) float a,b,c; printf( Enter any three numbers: ); scanf( %f%f%f,&a,&b,&c); if((a>b)&&(a>c)) printf( Largest of three numbers: %f,a); else if((b>a)&&(b>c)) printf( Largest of three numbers: %f,b); else printf( Largest of three numbers: %f,c); getch( );

Lab No. 03 OBJECTIVE: Write a program to find the largest of ten numbers (for-statement) #include<stdio.h> #include<conio.h> void main() int a[10],i,s=0,j,t; clrscr(); printf( Enter ten numbers: ); for(i=0;i<10;i++) scanf("%d",&a[i]); for(i=0;i<10;i++) for(j=i+1;j<10;j++) if(a[i]>a[j]) t=1; else t=0; break; if(t==1) printf("\nlargest no.:%d",a[i]); break; getch();

Lab No. 04 OBJECTIVE: Write a program to find the average mail height & average female heights in the class (input is in the form of sex code, height). #include<stdio.h> #include<conio.h> void main() int mh[5],fh[5],i; float mavg,favg,msum=0,fsum=0; clrscr(); printf( enter the height of male\n ); for(i=0;i<5;i++) scanf( %d,&mh[i]); msum=msum+mh[i]; mavg=msum/5; printf( enter the height of female\n ); for(i=0;i<5;i++) scanf( %d,&fh[i]); fsum=fsum+fh[i]; favg=fsum/5; printf( the average of male height is %f \n,mavg); printf( the average of female height is %f \n,favg); getch();

Lab No. 05 OBJECTIVE: Write a program to find roots of a quadratic equation using switch statements. #include<stdio.h> #include<conio.h> #include<math.h> main() float a,b,c,d,x1,x2; int ch; clrscr(); printf("enter a,b,c values"); scanf("%f%f%f",&a,&b,&c); d=pow(b,2)-4*a*c; if(d==0) ch=1; else if(d>0) ch=2; else ch=3; printf("a=%6.2f\nb=%6.2f\nc=%6.2f\n",a,b,c); printf("discriminate D=%6.2f\n",d); switch(ch) case 1: printf("equal Roots"); x1=x2=-b/(2*a); printf("x1=x2=%6.2f\n",x1); break; case 2: printf("roots are Real and inequal"); x1=(-b+sqrt(d))/(2*a); x2=(-b-sqrt(d))/(2*a); printf("x1=%6.2f\n",x1); printf("x2=%6.2f\n",x2);

break; case 3: printf("imaginary roots \n"); printf("x1=%6.2f+i%6.2f\n",-b/(2*a), sqrt(-d)/(2*a)); printf("x2=%6.2f-i%6.2f\n",-b/(2*a), sqrt(-d)/(2*a)); break; getch();

Lab No. 6 OBJECTIVE: Write a program using arrays to find the largest and second largest numbers out of given 50 numbers. #include<stdio.h> #include<conio.h> void main() int i,a[55],n,l=0,sl; clrscr(); printf("how many no. will you enter: "); scanf("%d",&n); for(i=0;i<n;i++) scanf("%d",&a[i]); l=a[1]; for(i=0;i<n;i++) if(a[i]>l) l=a[i]; printf("largest element is:%d",l); sl=a[1]; for(i=0;i<n;i++) if(a[i]>sl) sl=a[i]; printf("second Largest element is:%d",sl); getch();

Lab No. 7 OBJECTIVE: Write a program to multiply two matrices. #include<stdio.h> #include<conio.h> #include<process.h> void main() int a[10][10],b[10][10],c[10][10]; int i,j,m,n,p,q,s; clrscr(); printf("input row and column of matrix-a\n"); scanf("%d%d",&m,&n); printf("input row and column of matrix-b\n"); scanf("%d%d",&p,&q); if(n!=p) printf("matrix cannot be multiplied\n"); getch(); exit(0); printf("input Matrix-A\n"); for(i=0;i<m;i++) for(j=0;j<n;j++) scanf("%d",&a[i][j]); printf("input Matrix-B\n"); for(i=0;i<p;i++) for(j=0;j<q;j++) scanf("%d",&b[i][j]);

c[i][j]=0; for(s=0;s<n;s++) c[i][j]=c[i][j]+a[i][s]*b[s][j]; printf("\nproduct of matrix A and matrix B is:\n"); for(i=0;i<m;i++) for(j=0;j<q;j++) printf("\t%d",c[i][j]); printf("\n"); getch();

Lab No. 8 OBJECTIVE: Write a program to read a string and write it in reverse order. #include<stdio.h> #include<conio.h> void main() char a[20],i, b[20],g=0,j; clrscr(); printf("enter any string: "); scanf("%s",a); for(i=0;a[i]!='\0';i++) g++; j=g-1; for(i=0;i<g;i++) b[j]=a[i]; j--; printf("reverse order of string: %s",b); getch();

Lab No. 9 OBJECTIVE: Write a program to concatenate two strings of different lengths. #include<stdio.h> #include<conio.h> void main() char a[25],b[25],c[25]; int i.j; clrscr(); printf( Enter first string: ); scanf( %s,a); printf( Enter second string: ); scanf( %s,b); for(i=0;a[i]!= \0 ;i++) c[i]=a[i]; for(j=0; b[j]!= \0 ; j++) c[i+j]=b[j]; c[i+j]= \0 ; printf( The concatenated string is:\n%s,c ); getch();

Lab No. 10 OBJECTIVE: Write a program to check that the input string is a palindrome or not. #include<stdio.h> #include<conio.h> #include<process.h> void main() char a[ 20],i,b[20],g=0,j,m; clrscr(); printf("enter any string: "); scanf("%s",a); for(i=0;a[i]!='\0';i++) g++; j=g-1; for(i=0;i<g;i++) b[j]=a[i]; j--; for(i=0;i<g;i++) if(b[i]==a[i]) m=0; else

m=1; break; if(m==0) printf("string is a Palindrome"); else if(m==1) printf("string is not a Palindrome");

Lab No. 11 OBJECTIVE: Programs on file handling, which copies one file to another Program: #include<stdio.h> #include<string.h> #include<dos.h> #include<conio.h> #define L 80 main(int argc, char *argv[]) FILE *sfpt,*dfpt; char c; char sfname[l],dfname[l]; clrscr(); if(argc!=3) printf("invalid No of parameters."); exit(1); strcpy(sfname,argv[1]); strcpy(dfname,argv[2]); sfpt=fopen(sfname,"r"); if(sfpt==null) printf("file can't be opend %s",sfname); else dfpt=fopen(dfname,"w"); if(dfpt==null) printf("file can't be found: %s",sfname); else while(!feof(sfpt))

fclose(sfpt); fclose(dfpt); getch(); c=getc(sfpt); putc(c,dfpt);