'C' Programming Language

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

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

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

Q 1. Attempt any TEN of the following:

PROGRAMMING IN C LAB MANUAL FOR DIPLOMA IN ECE/EEE

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

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

Question Bank (SPA SEM II)

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

Government Polytechnic Muzaffarpur.

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

F.E. Sem. II. Structured Programming Approach

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

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

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

Write a C program using arrays and structure

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

MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION

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

F.E. Sem. II. Structured Programming Approach

UNIT III ARRAYS AND STRINGS

BCSE1002: Computer Programming and Problem Solving LAB MANUAL

Subject: Fundamental of Computer Programming 2068

Arrays in C. By Mrs. Manisha Kuveskar.

SUMMER 13 EXAMINATION Model Answer

PROGRAMMING IN C AND C++:

Imperative Programming

Contents ARRAYS. Introduction:

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

Branching is deciding what actions to take and Looping is deciding how many times to take a certain action.

M3-R4: PROGRAMMING AND PROBLEM SOLVING THROUGH C LANGUAGE

VALLIAMMAI ENGINEERING COLLEGE SRM NAGAR, KATTANGULATHUR

Module 6: Array in C

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

Multiple Choice Questions ( 1 mark)

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

UNIT I : OVERVIEW OF COMPUTERS AND C-PROGRAMMING

Basics of Programming

SAE1A Programming in C. Unit : I - V

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

Subject: PIC Chapter 2.

Computers Programming Course 12. Iulian Năstac

It is necessary to have a single function main in every C program, along with other functions used/defined by the programmer.

A. Year / Module Semester Subject Topic 2016 / V 2 PCD Pointers, Preprocessors, DS

UNDERSTANDING THE COMPUTER S MEMORY

Lab Manual B.Tech 1 st Year

PES INSTITUTE OF TECHNOLOGY (BSC) I MCA, First IA Test, November 2015 Programming Using C (13MCA11) Solution Set Faculty: Jeny Jijo


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

Programming and Data Structures

Object Oriented Pragramming (22316)

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

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

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

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


MODULE V: POINTERS & PREPROCESSORS

B.V. Patel Institute of Business Management, Computer & Information Technology, Uka Tarsadia University

(i) Describe in detail about the classification of computers with their features and limitations(10)

Programming in C Lab

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

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

Computers Programming Course 6. Iulian Năstac

// CSE/CE/IT 124 JULY 2015, 2.a. algorithm to inverse the digits of a given integer. Step 1: Start Step 2: Read: NUMBER Step 3: r=0,rev=0

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

Procedural programming with C

Prepared by: Shraddha Modi

UIC. C Programming Primer. Bharathidasan University

ESC101N: Fundamentals of Computing End-sem st semester

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

Computer Programming Unit 3

F.E. Sem - 2 CBCGS SPA MAY 17

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

MODULE 2: Branching and Looping

1 P a g e A r y a n C o l l e g e \ B S c _ I T \ C \

Syntax of for loop is as follows: for (inite; terme; updatee) { block of statements executed if terme is true;

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

Unit IV & V Previous Papers 1 mark Answers

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

Fundamental of Programming (C)

Computers Programming Course 5. Iulian Năstac

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

Introduction to C Language (M3-R )

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

Two Dimensional Array - An array with a multiple indexs.

Unit 3 Decision making, Looping and Arrays

Classification s of Data Structures

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

C Language Part 2 Digital Computer Concept and Practice Copyright 2012 by Jaejin Lee

Ex. No. 3 C PROGRAMMING

Structured programming

Preview from Notesale.co.uk Page 4 of 63

Functions. Arash Rafiey. September 26, 2017

ARRAYS(II Unit Part II)

UNIT - I. Introduction to C Programming. BY A. Vijay Bharath

Informatica e Sistemi in Tempo Reale

Fundamentals of Programming

INDORE INDIRA SCHOOL OF CAREER STUDIES C LANGUAGE Class B.Sc. - IIND Sem

Characters in C consist of any printable or nonprintable character in the computer s character set including lowercase letters, uppercase letters,

COMPUTER SCIENCE HIGHER SECONDARY FIRST YEAR. VOLUME II - CHAPTER 10 PROBLEM SOLVING TECHNIQUES AND C PROGRAMMING 1,2,3 & 5 MARKS

Transcription:

F.Y. Diploma : Sem. II [DE/EJ/ET/EN/EX] 'C' Programming Language Time: 3 Hrs.] Prelim Question Paper Solution [Marks : 70 Q.1 Attempt any FIVE of the following : [10] Q.1(a) Define pointer. Write syntax for pointer declaration. [2] Ans.: Definition: A pointer is a variable that stores memory address of another variable which is of similar data type. Declaration: datatype *pointer_variable_name; Q.1(b) Draw and label symbols used in flow chart. [2] Ans.: Symbol Name Function Process Input/ Output Indicates any type of internal operation inside the Processor or Memory Used for any Input/ Output (I/O) operation. Indicates that the computer is to obtain data or output results Decision Used to ask a question that can be answered in a binary format (Yes/ No, True/False) Connector Allows the flowchart to be drawn without intersecting lines or without a reverse flow. Predefined Process Used to invoke a subroutine or an Interrupt program. Terminal Indicates the starting or ending of the program, process, or interrupt program Flow Lines Shows direction to flow. Q.1(c) Define : (i) Two dimensional array (ii) Multi dimensional array [2] Ans.: (i) Two dimensional array Two dimensional array is a collection of similar type of data elements arranged in the form of rows & columns. E.g. Array can be declared as int arr[3][3]; In this there can be 9 elements in an array with 3 rows and 3 columns. (ii) Multi-dimensional array: An array with more than one dimension is called as multidimensional array. For example, float x[3][4]; Similarly, you can declare a three-dimensional (3d) array. For example, float y[2][4][3]; - 1 -

Vidyalankar : F.Y. Diploma 'C' Programming Language Q.1(d) Define type casting. Give any one example. [2] Ans.: Definition type casting: The conversion of one data type to another is known as type casting. The values are changed for the respective calculation only, not for any permanent effect in a program. For example, x = int (7.5) means 7.5 is converted to integer by truncating it i.e. 7 b = (int) 22.7/(int) 5.3 means 22.7 will be converted to 22 and 5.3 to 5 so answer will be 22/5 = 4 c = (double) total/num means the answer will be in float value. p = sin((int)x) means x will be converted to integer and then sine angle will be calculated. Q.1(e) Define Array [2] Ans.: An array is a collection of similar type of elements. Q.1(f) State different data types supported by C language. [2] Ans.: Data types in C language are: Primary or basic data types User defined data types Character (char) is used to store single character or number at a time. Integer (int) is used to store only integer values with no decimal points. Float (float) is used to store only floating point numbers with decimal points are allowed. Double (double) has double value than float Void void Defined by users as per their need Array, structure Q.1(g) Give syntax of declaring and initialization of structure. [2] Ans.: Structure: A structure is a collection of one or more variables of same or different data types grouped together under a single name. Syntax of declaration of structure: struct structure_name Data_type1 variable 1; Data_type2 variable 2;.. Data_typen variable n; ; Syntax of initialization of structure: struct structure_name Data_type1 variable 1; Data_type2 variable 2;.. Data_typen variable n; variable_name; (OPTIONAL) struct book char tit[20]; char auth[20]; int price; b1; - 2 -

Prelim Question Paper Solution Q.2 Attempt any THREE of the following : [12] Q.2(a) Explain do - while loop with example. [4] Ans.: Do-While statement: In some applications it is necessary to execute the body of the loop before the condition is checked; such situation can be handled by do statement. At least once the body of loop will be executed. Do statement, first executes the body of the loop. At the end of the loop, the test condition in the while statement is evaluated. If the condition is true, then it continues to execute body of the loop once again. This process continues as long as the condition is true. When the condition becomes false, the loops will be terminated and the control goes to next statement after while statement. #include <stdio.h> #include <conio.h> int i=1; printf("\n Odd numbers from 1 to 20 are \n"); do if(i%2! = 0) printf("\n %d", i); i++; while(i<=20); /* The loop iterates till the value of i is less than or equal to 20 */ Q.2(b) Develop a program to accept an integer number and print whether it is palindrome or not. int n, num, rev = 0, digit, i; printf("enter the number: "); scanf("%d", & num); n = num; for(i = 0; num! = 0; ++i) digit = num%10; rev = rev*10+digit; num = num/10; if(n==rev) printf("number is palindrome"); else printf("number is not palindrome"); [4] - 3 -

Vidyalankar : F.Y. Diploma 'C' Programming Language Q.2(c) Explain the use of the following function with syntax : [4] (i) Strcmp () (ii) Strlen () Ans.: (i) strcmp():this library function is used to compare two strings. If the strings are equal then function returns value as 0 and if they are not equal then the function returns ASCII value difference of the first mismatched characters from the strings. Syntax: strcmp(string1,string2); Consider str1 = abc and str2 = abc i = strcmp(str1,str2) strcmp function compares characters from str1 and str2 and returns 0 as both the strings are same. (ii) strlen(): This library function is used to count the length of the string i.e. number of characters including blank spaces from a string. Syntax: strlen(string1); int i; char string1[] = abc ; i = strlen(string1); strlen function counts number of characters from string1 and stores the count in the variable i. Q.2(d) Explain recursion functions with example and state its advantages. [4] Ans.: Recursive function: Recursion is the process of function calling itself again and again. Definition: Recursion function is the process in which function calls itself. Recursive function: Recursion is the process of function calling itself again and again. A Recursive function contains function call to itself in the body of function. void recurse() recurse(); /* Function calls itself */ int main() recurse(); /* Sets off the recursion */ return 0; #include<stdio.h> int n,fact; printf("enter the number"); scanf("%d",&n); fact=factorial(n); printf("factorial of %d=%d",n,fact); int factorial(int n); - 4 -

Prelim Question Paper Solution if(n==1) return(1); else return(n * factorial(n-1)); --------------------Recursive function call In the above example recursive function factorial() is used to print the Factorial of a number. Advantages: Reduces length of the program Reduces unnecessary calling of a function. Useful when same solution is to be applied many times. Q.3 Attempt any THREE of the following : [12] Q.3(a) Explain conditional operator with example. [4] Ans.: Conditional operators return one value if condition is true and returns another value is condition is false. This operator is also called as ternary operator as it takes three arguments. Syntax: (Condition? true_value: false_value); #include<stdio.h> int i; printf("enter a number:"); scanf("%d", &i); i%2==0?printf("%d is even", i):printf("%d is odd", i) ; Q.3(b) Explain any four library functions under conio.h header file. [4] Ans.: clrscr() -This function is used to clear the output screen. getch() - It reads character from keyboard getche() - It reads character from keyboard and echoes to o/p screen putch - Writes a character directly to the console. textcolor() -This function is used to change the text color textbackground() - This function is used to change text background Q.3(c) Write an algorithm and flowchart to swap the contents of two variables. [4] Ans.: Algorithm: Step 1: Start Start 2: READ num1, num2 Start 3: temp = num1 Start 4: num1 = num2 Start 5: num2 = temp Start 6: PRINT num1, num2 Start 7: Stop - 5 -

Vidyalankar : F.Y. Diploma 'C' Programming Language Flowchart: Q.3(d) Explain array of structure with example. [4] Ans.: Array of structure: A structure is a composite data type with a collection of variables. These variables can have different data types and collectively form a structure of a composite data type. An array of structures is a sequential collection of structures. With structures, you can store mixed record types and with an array supporting this, you can have a list of mixed record types. It can be used when we want to use many variables of the same structure. If a structure for student data is defined and it has to be used for 10 different students, then array of structure can be declared as struct student int rollno; char name[20]; s[10]; Here data in the form of rollno and name can be stored or accessed for 10 students. Here s[0].rollno and s[0].name will be the data for first student. s[1].rollno and s[1].name will be the data for second student and so on. Q.4 Attempt any THREE of the following : [12] Q.4(a) Write a program to accept the value of year as input from the keyboard & print [4] whether it is a leap year or not. int year; printf("enter year"); scanf("%d", &year); if(year%4==0) printf("year %d is a leap year", year); else printf("year %d is not a leap year", year); - 6 -

- 7 - Prelim Question Paper Solution Q.4(b) State and explain four arithmetic operations perform on pointer. [4] Ans.: Arithmetic operations perform on Pointer: Basic operations +, -, *, /, ++, -- can be done using pointer notation. Some of the following operations are possible: e.g. add = *p1 + *p2 Adds the value of pointer p1 and p2 y = *p1 -*p2 Subtracts values of pointer p1 and p2 x = *p1 / *p2 Divide the values of p1 and p2 x = *p1 ** p2 Multiplies values of p1 and p2 (*pl)++ :- This statement increments value, stored at the memory address pointed by pointerpl, by 1. #include<stdio.h> int a = 10,b = 2, sum, mul; int *p1, *p2; p1 = & a; p2 = & b; sum = *p1+*p2; mul = *p1**p2; printf("\naddition = %d\nmultiplication = %d", sum, mul); Q.4(c) Write a C program to find whether the given number is prime or non prime. [4] Ans.: #include <stdio.h> int n, i, c = 0; printf("enter the number :"); scanf("%d", &n); for (i = 1; i <= n; i++) if (n % i == 0) c++; if (c == 2) printf("%d is a Prime number",n); else printf("%d is not a Prime number",n); return 0; Output: Enter the number:7 7 is a prime number

Vidyalankar : F.Y. Diploma 'C' Programming Language Q.4(d) Write a C program to declare a structure student with members as Roll no., [4] name and marks. Accept and display data for one instance. Ans.: #include<stdio.h> struct student int roll_no; char name[10]; float marks; s; printf( Enter roll number: ); scanf( %d,&s.roll_no); printf( Enter name: ); scanf( %s,&s.name); printf( Enter marks: ); scanf( %f,&s.marks); printf( The given information is:\nroll no = %d\ tname = %s\tmarks = %f, s.roll_no, s.name, s.marks); Output: Enter roll number:10 Enter name:abc Enter marks:75.89 The given information is: Roll no=10 Name=ABC Marks=75.89 Q.5 Attempt any TWO of the following : [12] Q.5(a) Write a program for addition of two 3 3 matrices. [6] int a[3][3],b[3][3],c[3][3], i, j; printf("enter first matrix elements:\n"); for(i=0;i<3;i++) for(j=0;j<3;j++) scanf("%d", & a[i][j]); printf("\nenter second matrix elements:\n"); for(i=0;i<3;i++) for(j=0;j<3;j++) scanf("%d", & b[i][j]); for(i=0;i<3;i++) - 8 -

Prelim Question Paper Solution for(j=0;j<3;j++) c[i][j] = a[i][j] + b[i][j]; printf("\n\naddition of two matrices is:"); for(i=0;i<3;i++) for(j=0;j<3;j++) printf("%d\t", c[i][j]); Q.5(b) Write a program to exchange values of two variables using pointers. [6] int a, b, *p; printf("enter value of a: "); scanf("%d", & a); printf("enter value of b: "); scanf("%d", & b); printf("before swapping: a:%d b:%d", a, b); *p = a; a = b; b = *p; printf("\nafter swapping: a:%d b:%d", a, b); Q.5(c) Write the program to accept 10 (ten) numbers from user using array, search and print the location of a given number. Ans.: Program: #include <stdio.h> void main( ) int array[100], search, c; printf("enter 10 numbers\n"); for (c = 0; c < 10; c++) scanf("%d", &array[c]); printf("enter a number to search\n"); scanf("%d", &search); for (c = 0; c < 10; c++) if (array[c] == search) /* If required element is found */ printf("%d is present at location %d.\n", search, c+1); break; [6] - 9 -

Vidyalankar : F.Y. Diploma 'C' Programming Language if (c == 10) printf("%d isn't present in the array.\n", search); getch( ); Output: Enter 10 numbers 4 3 7 2 9 6 5 1 8 10 Enter a number to search 2 2 is present at location 4. Q.6 Attempt any TWO of the following : [12] Q.6(a) Develop a program to find diameter, circumference and area of circle using [6] function. void circle(float r) float diameter, circumference, area; diameter = 2*r; printf("\n Diameter = %f", diameter); circumference = 2*3.14*r; printf("\n Circumference = %f", circumference); area = 3.14*r*r; printf("\n Area = %f", area); float radius; printf("\n Enter radius:"); scanf("%f", & radius); circle(radius); Q.6(b) Write a program to print table of a given number. [6] int n, i; printf("enter a number: "); scanf("%d", & n); printf("\ntable of %d :\n", n); - 10 -

Prelim Question Paper Solution for(i=1; i<=10; i++) printf("%d * %d = %d\n", n, i, n*i); Q.6(c) Write a C program to find sum of natural number entered by user. [6] Ans.: #include <stdio.h> void main( ) int n, i, sum = 0; printf("enter a positive integer: "); scanf("%d", & n); for(i=1; i < = n; ++i) sum + = i; // sum = sum + i; printf("sum = %d", sum); getch( ); Output: Enter a positive integer: 100 Sum = 5050-11 -