Subject: Fundamental of Computer Programming 2068

Similar documents
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

C Programming Lecture V

Functions. Arash Rafiey. September 26, 2017

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

IV Unit Second Part STRUCTURES

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

Dynamic Memory Allocation

Pointers (part 1) What are pointers? EECS We have seen pointers before. scanf( %f, &inches );! 25 September 2017

ESC101N: Fundamentals of Computing End-sem st semester

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

A3-R3: PROGRAMMING AND PROBLEM SOLVING THROUGH 'C' LANGUAGE

Compiling and Running a C Program in Unix

Computer Programming Unit 3

PERIYAR CENTENARY POLYTECHNIC COLLEGE Periyar Nagar- Vallam Thanjavur

UNIT - V STRUCTURES AND UNIONS

Computer Science & Engineering 150A Problem Solving Using Computers

MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION

CS561 Manju Muralidharan Priya Structures in C CS200 STRUCTURES. Manju Muralidharan Priya

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

Variables Data types Variable I/O. C introduction. Variables. Variables 1 / 14

AMCAT Automata Coding Sample Questions And Answers

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

Unit IV & V Previous Papers 1 mark Answers

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

'C' Programming Language

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

M3-R4: PROGRAMMING AND PROBLEM SOLVING THROUGH C LANGUAGE

int marks[10]; // fixed size and fixed address No change in Memory address.

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

Multiple Choice Questions ( 1 mark)

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

Unit 7. Functions. Need of User Defined Functions

Dynamic memory allocation

Tribhuvan University Institute of Science and Technology 2065

Decision Making -Branching. Class Incharge: S. Sasirekha

Module 4: Decision-making and forming loops

AN OVERVIEW OF C, PART 3. CSE 130: Introduction to Programming in C Stony Brook University

Arrays and Pointers (part 1)

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

Question Bank (SPA SEM II)

For Solved Question Papers of UGC-NET/GATE/SET/PGCET in Computer Science, visit

Introduction to C Language (M3-R )

C Program Development and Debugging under Unix SEEM 3460

Lecture 5: Multidimensional Arrays. Wednesday, 11 February 2009

COP 3223 Introduction to Programming with C - Study Union - Spring 2018

Fundamental of Programming (C)

NCS 301 DATA STRUCTURE USING C

Fundamentals of Programming & Procedural Programming

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

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

Week 9 Part 1. Kyle Dewey. Tuesday, August 28, 12

CS113: Lecture 5. Topics: Pointers. Pointers and Activation Records

Procedural programming with C

Linked-List Basic Examples. A linked-list is Linear collection of self-referential class objects, called nodes Connected by pointer links

Functions. Functions are everywhere in C. Pallab Dasgupta Professor, Dept. of Computer Sc & Engg INDIAN INSTITUTE OF TECHNOLOGY KHARAGPUR

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

Darshan Institute of Engineering & Technology for Diploma Studies Unit 5

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

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

Pointers. Pointer Variables. Chapter 11. Pointer Variables. Pointer Variables. Pointer Variables. Declaring Pointer Variables

MODULE V: POINTERS & PREPROCESSORS

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

Single Dimension Arrays

{C} Programming. Part 1/2 Basics Variables, Conditions, Loops, Arrays, Pointer basics

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

Prepared by: Shraddha Modi

A PROBLEM can be solved easily if it is decomposed into parts. Similarly a C program decomposes a program into its component functions.

Arrays, Pointers and Memory Management

PROGRAMMING IN C LAB MANUAL FOR DIPLOMA IN ECE/EEE

The C Programming Language Part 4. (with material from Dr. Bin Ren, William & Mary Computer Science, and

BSM540 Basics of C Language

Memory Allocation in C

ENEE150 Final Exam Review

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

CS16 Exam #1 7/17/ Minutes 100 Points total

Arrays and Pointers (part 1)

AE52/AC52/AT52 C & Data Structures JUNE 2014

MODULE 5: Pointers, Preprocessor Directives and Data Structures

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

C: How to Program. Week /Mar/05

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

Arrays and Pointers. CSE 2031 Fall November 11, 2013

UNIT-V. Structures. The general syntax of structure is given below: Struct <tagname> { datatype membername1; datatype membername2; };

POINTER AND ARRAY SUNU WIBIRAMA

CSE 124 Discussion (10/3) C/C++ Basics

3/22/2016. Pointer Basics. What is a pointer? C Language III. CMSC 313 Sections 01, 02. pointer = memory address + type

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

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

10/20/2015. Midterm Topic Review. Pointer Basics. C Language III. CMSC 313 Sections 01, 02. Adapted from Richard Chang, CMSC 313 Spring 2013

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

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

Programming in C Quick Start! Biostatistics 615 Lecture 4

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

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

Principles of C and Memory Management

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

SHARDA UNIVERSITY SCHOOL OF ENGINEERING & TECHNOLOGY Mid Term Examination, (Odd Term, ) SOLUTION

FUNCTIONS OMPAL SINGH

Sample Problems for Quiz # 3

Unit 3 Decision making, Looping and Arrays

Transcription:

Subject: Fundamental of Computer Programming 2068 1 Write an algorithm and flowchart to determine whether a given integer is odd or even and explain it. Algorithm Step 1: Start Step 2: Read a Step 3: Find modules of a by 2 (r = a % 2) Step 4: If r= 0 Print a is even Else Step 5: stop Flowchat Print a is odd start Read a R = a % 2; If No Print a is odd R = 0 C C 2 1

C 1 yes Print a is even start C 2 First of all, we have to read an integer a, then find the modules of a by 2 and if the value of modules is 0 then a is even else a is odd. 2. How can you declare the variable in C? Explain with example. Variable declaration in C: Every variable used in the program should be declared to the compiler. The decleration use two things a. Tells the compiler the variable name b. Specifies what type of data the variables will hold The general format of any declaration Data type v 1, v 2, v 3,.., v n ; Where v 1,v 2,v 3,.,v n are variables name variables are separated by commas. The decleration statement must end with a semi colon Example : Int sum; Int number, salary; Double average, mean; 2 Write a program to find the factorial of a given integer.

Program to find factorial #include<stdio.h> Int main() Int i = 1, f = 1, num ; Printf ( enter a number : ) Scanf( %d,&num) While (i <= num) F = f*i; i++; Printf ( factorial of %d is %d,num,f); Return 0; 3 Explain switch statement with example. Switch statement Switch statement allows a program to select one statement for execution out of a set of alternative. During the execution of the switch statement only one of the possible statement will be executed the remaining statement uses the simple and straight forward approach avoiding multiple uses that was in if.else statement. General format of switch statement is Switch (expression) Case case1; Case case2;..

Case default Example: #include<stdio.h> Void main() Int num1,num2,result; Char operator; Printf( enter two number ); Scanf( %d%d,&num1,&num2); Printf( enter an operator ); Scanf( %c,&operator); Switch (operator) Case + : Result = num1 + num2 Break; Case - : Result = num1 num2 Break; Case * : Result = num1 * num2 Break; Default: Printf ( unknown operator ); Result = 0 Break;

Printf ( %d, result) 4 Write a program to find the largest and smallest among the given element in an array. #include<sdtio.h> #include<conio.h> Void main() Clrscr(); Int a[10]; Int i, big, small; Printf ( enter 10 elements in array: ); For ( i=0 ;I <10 ; i++ ) Scanf( %d, a[i] ); Big = a[0]; For( i=0 ; i<10 ; i++ ) Printf( big < a[i] ) Big a[i]; Printf( largest element = %d, big ); Small = a[0]; For ( i=0 ; i<10 ; i++ )

If ( small > a[i] ) Small = a[i]; Printf ( \n smallest element = %d, small); 5 Explain the user-define function and its types with example. User-define function: The functions which are created by user for program are known as user defined functions. These type of functions are not defined in C- library and are created by the user himself. The types of user-defined functions are: a. Functions with no arguments and no return value. b. Functions with no arguments and a return value. c. Functions with arguments and return value. d. Functions with arguments and no return value. Example: Int fact (int); Void main() Int n, fac; Clrscr (); Printf( enter the value of n ); Scanf( %d, &n); Fac = fact(n); Printf( factorial of %d is %d, n, fac); Getch (); Int fact (int n)

If (n==1) Return(1); Else Return fact (n-1) * n; 6 Write a program to accept two number and sort them with using pointer. #include Void main () Int x, y, *a, *b, temp; Printf ( enter the value of x and y \n ); Scanf ( %d %d, &x, &y ); Printf ( before swapping \n n = %d \n y = %d \n,x, y); a = &x; b = &y; temp = *b; *b = *a; *a = temp; Printf ( after swapping \n x = %d \n y = %d \n, x, y); 7 Explain the passing structure to function with example. Passing structure to function: In case of structures having numeras structure elements passing these individual elements would be hard task. In such cases we may pass whole structure to a function as shown below: #include<stdio.h>

Structure employee Int id; Char name[25]; Float salary; ; Void main () Static struct employee emp1 = 12, nitesh,7500; Display(emp1); Display (emp1); Struct employee emp1 Printf ( %d %s %f, emp1, id, emp1.name, emp1.salary); 8 Write a program to accept any number and print the sum of that single digit through recursive function. #include <stdio.h> #include<conio.h> int sum(int); void main() int n; printf("enter the single digit number");scanf("%d",&n); printf("sum = %d\n", sum(n));

getch(); int sum(int n) if (n <= 1) else return 1; return (n + sum(n-1)); 9 Explain the pointer to structure with example. Pointer to structure: We know the name of array stands for the address of its zero th element the same concept applies for name of arrays of structures. Suppose item is an array variable of struct type, consider the following Struct products Char name[30]; Int manufac ; Float net; Item[2], ptr; This statement declares item as array of two element, each type struct product and ptr as a pointer data object of type struct products. The assignment ptr = item; Would assign the address of zero th element to product [0], its member can be accessed by using the following notation. Ptr = name

Ptr = manufac Ptr = net OR Write a short notes on: a. Dynamic memory allocation b. Opening and closing file a) Dymanic memory allocation: C provides the function calloc( ) and malloc( ) in the standard library and their function prototypes are in <stdlib.h>. The name calloc stands for contigeous allocation and the name malloc to dynamically create space for arrays, structures and unions. The function calloc takes to arguments where as the function malloc takes only are argument b) Opening and closing file: Before a program can write to a file or read from file. The program must open it, opening a file established a link between the program and the operating system, this provides the operating system, the name of the file and the mode in which the file is to be opened. The process of establishing a connection between the program and file is called opening the file. Same is the case of closing file.