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

Similar documents
Computer System and programming in C

Subject: Fundamental of Computer Programming 2068

Computer programming UNIT IV UNIT IV. GPCET,Dept of CSE, P Kiran Rao

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

'C' Programming Language

FUNCTIONS OMPAL SINGH


MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION

IV Unit Second Part STRUCTURES

Q 1. Attempt any TEN of the following:

SAE1A Programming in C. Unit : I - V

F.E. Sem. II. Structured Programming Approach

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

BCSE1002: Computer Programming and Problem Solving LAB MANUAL

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

PERIYAR CENTENARY POLYTECHNIC COLLEGE Periyar Nagar- Vallam Thanjavur

Files and Streams Opening and Closing a File Reading/Writing Text Reading/Writing Raw Data Random Access Files. C File Processing CS 2060


int Return the number of characters in string s.

SELECTION STATEMENTS:

Structure, Union. Ashishprajapati29.wordpress.com. 1 What is structure? How to declare a Structure? Explain with Example

Darshan Institute of Engineering & Technology for Diploma Studies Unit 5

UIC. C Programming Primer. Bharathidasan University

Preprocessing directives are lines in your program that start with `#'. The `#' is followed by an identifier that is the directive name.

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

Unit 3 Functions. 1 What is user defined function? Explain with example. Define the syntax of function in C.

F.Y. Diploma : Sem. II [CO/CD/CM/CW/IF] Programming in C

Guide for The C Programming Language Chapter 4

***************OUTPUT*************************** Enter the two number The addition of two number is =100

Programming & Data Structure Laboratory. Arrays, pointers and recursion Day 5, August 5, 2014

Language comparison. C has pointers. Java has references. C++ has pointers and references

& Technology. G) Functions. void. Argument2, Example: (Argument1, Syllabus for 1. 1 What. has a unique. 2) Function name. passed to.

Unit 3 Decision making, Looping and Arrays

Prepared by: Shraddha Modi

Chapter-11 POINTERS. Important 3 Marks. Introduction: Memory Utilization of Pointer: Pointer:

Advanced C Programming and Introduction to Data Structures

Unit IV & V Previous Papers 1 mark Answers

UNIT-IV. Structure is a user-defined data type in C language which allows us to combine data of different types together.

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

Unit 8. Structures and Unions. School of Science and Technology INTRODUCTION

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

KareemNaaz Matrix Divide and Sorting Algorithm

struct structure_name { //Statements };

CS 345. Functions. Vitaly Shmatikov. slide 1

Vidyalankar F.Y. Diploma : Sem. II [CD/CM/CO/CW/DE/ED/EE/EI/EJ/EN/EP/ET/EV/EX/IC/IE/IF/IS/IU/MU] Programming in C

M1-R4: Programing and Problem Solving using C (JAN 2019)

SUMMER 13 EXAMINATION Model Answer

MCA Semester 1. MC0061 Computer Programming C Language 4 Credits Assignment: Set 1 (40 Marks)

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

Computer Programming Unit v

LAB 13 FILE PROCESSING

Scheme G. Sample Test Paper-I. Course Name : Computer Engineering Group Course Code : CO/CD/CM/CW/IF Semester : Second Subject Tile : Programming in C

MODULE 5: Pointers, Preprocessor Directives and Data Structures

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

To declare an array in C, a programmer specifies the type of the elements and the number of elements required by an array as follows

Aryan College. Fundamental of C Programming. Unit I: Q1. What will be the value of the following expression? (2017) A + 9

Sri vidya college of engineering and technology UNIT II FUNCTIONS, POINTERS, STRUCTURES AND UNIONS

Unit 6 Files. putchar(ch); ch = getc (fp); //Reads single character from file and advances position to next character

ME 172. C Programming Language Sessional Lecture 8

UNIT 3 FUNCTIONS AND ARRAYS

MTH 307/417/515 Final Exam Solutions

Example: Structure, Union. Syntax. of Structure: struct book { char title[100]; char author[50] ]; float price; }; void main( )

F.E. Sem. II. Structured Programming Approach

Prepared by: Shraddha Modi

4(a) ADDITION OF TWO NUMBERS. Program:

MODULE 3: Arrays, Functions and Strings

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING B.E SECOND SEMESTER CS 6202 PROGRAMMING AND DATA STRUCTURES I TWO MARKS UNIT I- 2 MARKS

Arrays in C. By Mrs. Manisha Kuveskar.

The syntax of structure declaration is. struct structure_name { type element 1; type element 2; type element n;

COP 3223 Introduction to Programming with C - Study Union - Fall 2017

Lectures 5-6: Introduction to C

CS Introduction to Programming Midterm Exam #2 - Prof. Reed Fall 2015

LAB 13 FILE PROCESSING

COP 3223 Introduction to Programming with C - Study Union - Fall 2017

Questions Bank. 14) State any four advantages of using flow-chart

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


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

Government Polytechnic Muzaffarpur.

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

Learning C Language. For BEGINNERS. Remember! Practice will make you perfect!!! :D. The 6 th week / May 24 th, Su-Jin Oh

Pointers. Mr. Ovass Shafi (Assistant Professor) Department of Computer Applications

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING UNIT-1

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

DC104 DATA STRUCTURE JUNE Q.2 a. If you are using C language to implement the heterogeneous linked list, what pointer type will you use?

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

Arrays a kind of data structure that can store a fixedsize sequential collection of elements of the same type. An array is used to store a collection

Pointers and Structure. Bin Li Assistant Professor Dept. of Electrical, Computer and Biomedical Engineering University of Rhode Island

Decision Making and Branching

Classes and Objects. Instructor: 小黑

C Programming Language

Question Bank (SPA SEM II)

#3. (Recursion) Write a recursive function to compute f(x) = f(x - 1) + f(x - 2) with f(0) = 0 and f(1) = 1.

PROGRAMMING IN C LAB MANUAL FOR DIPLOMA IN ECE/EEE

Chapter 10. File Processing 248 FILE PROCESSING

E.G.S. PILLAY ENGINEERING COLLEGE (An Autonomous Institution, Affiliated to Anna University, Chennai) Nagore Post, Nagapattinam , Tamilnadu.


Lectures 5-6: Introduction to C

Bangalore South Campus

/* Polynomial Expressions Using Linked List*/ #include<stdio.h> #include<conio.h> #include <malloc.h> struct node. int num; int coeff;

Transcription:

SRI VIDYA COLLEGE OF ENGINEERING & TECHNOLOGY, VIRUDHUNAGAR Department of CSE & IT Internal Test I Year & Sem: I B.E (CSE) & II Date of Exam: 21/02/2015 Subject Code & Name: CS6202 & Programming & Data Structures I Total Marks: 50 Part A 1) Differentiate while & do while statement? While Statement (i) Executes the statements within the while block if only the condition is true. (ii) The condition is checked at the starting of the loop Do While Statement (i) Executes the statements within the while block at least once. (ii) The condition is checked at the end of the loop 2) Define structure. How to initialize a structure? A structure is a user defined data type that groups logically related data items of different data types into a single unit. struct student int rno; int age; char name[20]; ; struct student s1=223,17, john ; 3) What is the value of ptr[0] in the following program? void main() int num[5] = 1,3,6,7,9; int *ptr; ptr = &num[2]; Output: Ptr[0] = 6 4) How to handle function with variable number of arguments in C? Va_start Va_end Va_arg Va_list 5) Define file handling. What are the ways to access files? A file handling is set of records that is available in permanent storage. Ways to access files: Random access Sequential access

Part B 6) a) Write a C program to explain the concept of recursion. (8) #include<stdio.h> int fact(int); int main() int num,f; printf("\nenter a number: "); scanf("%d",&num); f=fact(num); printf("\nfactorial of %d is: %d",num,f); int fact(int n) if(n==1) return 1; return(n*fact(n-1)); 6) b) Define a structure called student that should contain name, regno and marks of 3 subjects and average. Write a C program to read the details of name, regno and marks of 3 subjects for 30 students. Calculate the average and display the name, regno, marks and average of each students. (8) #include<stdio.h> #include<conio.h> struct student int rollno; char name[20]; int m1,m2,m3; float avg; ; struct student s[50]; void main() int i,j,n; clrscr(); printf("\n enter the number of students record:"); scanf("%d",&n); for(i=0;i<n;i++) printf("\n enter the roll no=\n"); scanf("%d",&s[i].rollno); printf("\n enter the name \n"); scanf("%s",s[i].name); printf("\n enter the mark="); scanf("%d",&s[i].m1); printf("\n enter the mark="); scanf("%d",&s[i].m2); printf("\n enter the mark="); scanf("%d",&s[i].m3); s[i].avg=(s[i].m1+s[i].m2+s[i].m3)/3; for(i=0;i<n;i++) printf("\n rollno=%d",s[i].rollno); printf("\n name=%s",s[i].name); printf("\n mark1=%d",s[i].m1); printf("\n mark2=%d",s[i].m2); printf("\n mark3=%d",s[i].m3); printf("\n Average=%f",s[i].avg); getch();

7) a) i) Explain in detail about macro substitution. (8) Assign symbolic constants. #define identifier srting/integer Simple macro #define age 20 #define pi 3.14 Argumented macro #define sq n *n Nested macro #define A 50 #define B + A 7) a) ii) Explain about function pointers. (8) #include <stdio.h> #include<conio.h> void swap(int *x, int *y); int main () int a,b; printf("\n Enter the value of a:"); scanf("%d",&a); printf("\n Enter the value of b:"); scanf("%d",&b); printf("before swap, value of a and b is: %d\t %d\n", a,b ); swap(&a, &b); printf("\nin main, value of a and b is: %d \t %d\n", a,b ); void swap(int *x,int *y) int temp; temp=*x; *x=*y; *y=temp; printf("after swap, value of a and b is: %d \t %d\n", *x,*y ); 7) b) i) Explain about Control statements in detail. (16) if statement: if (condition is true) True statements; If : if(condition) Statement1;... Statement n; Statement1;... Statement n;

Nested if : if(condition 1) if(condition 2) True statement 2; False statement 2; False statement 1; Switch(): switch(expression) case constant-expression : break; /* optional */ case constant-expression : break; /* optional */. default : /* Optional */ While: while(condition) Continue: Continue; Break: Do: For: Break; do while( condition ); for ( init; condition; increment ) 8) a) i) Write a C program to perform matrix Multiplication. (8) #include<stdio.h> #include<conio.h> void main() int a[25][25],b[25][25],c[25][25],i,j,k,r,s; int m,n; clrscr(); printf(" Enter the row and columns of A matrix..."); scanf("%d%d",&m,&n); printf("enter the row and columns of B matrix,,,,,,,,,,"); scanf("%d%d",&r,&s); if(m!=r) printf("\n The matrix cannot multipled"); printf("\n Enter the elements of A matrix"); scanf("\t%d",&a[i][j]); printf("\n Enter the elements of B matrix");

matrix"); matrix"); scanf("\t%d",&b[i][j]); printf("\n the elements of A printf("\t%d",a[i][j]); printf("\n the elements of B printf("\t%d",b[i][j]); c[i][j]=0; for(k=0;k<m;k++) c[i][j]=c[i][j]+a[i][k]*b[k][j]; printf("the multiplication of two matrixes"); printf("\t%d",c[i][j]); getch(); 8) a) ii) Explain about union with an example. (8) Union is also a derived type as structure. Union can be defined in same manner as structures just the keyword used in defining union in union where keyword used in defining structure was struct. union car char name[50]; int price; ; union car c1, c2, *c3; Program: #include <stdio.h> union job char name[32]; float salary; int worker_no; u; int main() printf("enter name:\n"); scanf("%s",&u.name); printf("enter salary: \n"); scanf("%f",&u.salary); printf("displaying\nname :%s\n",u.name); printf("salary: %.1f",u.salary); 8) b) Explain in detail about file manipulation. (16) A file is a collection of related data that a computers treats as a single unit. Steps in Processing a File 1. Create the stream via a pointer variable using the FILE structure: FILE *p;

2. Open the file, associating the stream name with the file name. 3. Read or write the data. 4. Close the file. Opening a file FILE *fopen(filename, mode); Example: FILE *p1, *p2; p1 = fopen( INPUT.txt, r ); p2 =fopen( OUTPUT.txt, w );.... fclose(p1); fclose(p2); Closing a file fclose(file_pointer); fscanf() fscanf (fp,"string",identifiers); fprintf() fprintf (fp,"string",variables); fseek() Example: #include <stdio.h> int main() FILE * f; f = fopen("myfile.txt", "w"); fputs("hello World", f); fseek(f, 6, SEEK_SET); fputs(" India", f); fclose(f);