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

Size: px
Start display at page:

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

Transcription

1 INTERNAL ASSESSMENT TEST 1 SOLUTION PART 1 1 a Define algorithm. Write an algorithm to find sum and average of three numbers. 4 An Algorithm is a step by step procedure to solve a given problem in finite number of steps by Accepting a set of inputs and Producing the desired output for the given problem. step 1: [start] Step2: [input the value of three numbers] read a,b,c Step3: [ calculate the value of average] Avg.= (a+b+c)/3. Step4: [display the calculated average]write Avg. Step 5: [finished] Stop b Draw a flowchart for printing the largest number among three numbers. 4

2 2 a Explain the basic structure of a C program. 4 Documentation section (Comments) Link section Definition section (Pre-processor directives) (Define symbolic Constant) Global declaration section main( ) function local declarations part execution part(statements) Sub program section (user defined functions) function 1 function 2 It is a program that processes our source program before it is passed to the compiler. Preprocessor commands (often known as directives). The preprocessor statement starts with symbol #. The normal preprocessor used in all programs is include. The #include directive instructs the preprocessor to include the specified file contents in the beginning of the program. main(): It is called the main function An entry point is where control enters a program or piece of code. Every program must have main ( ) since this is where the computer begins to execute the program. The main ( ) function is divided into two parts: 1) Declaration Section: The variables that are used within the function main () should be declared in the declaration section only. The variables declared inside a function are called as local variables.

3 2) Executable Section : This contains the instruction given to the compiler to perform a specific task. The task may be to (a) display message (b) read data (c) perform calculations. Comments are those portions of the code which is ignored by the compiler. The comment allow the user to make simple notes in the source code. // this is used for sinlge line comment. /* this is used for multiple line comment. */ b Define Identifiers, keywords and constant. 4 Identifier: As the name indicates, identifier is used to identify various entities of program such as variables, constants, functions etc. In other words, an identifier is a word consisting of sequence of LettersDigits or _ underscore Keywords: Keywords are those words, which have predefined meaning to the compiler. Each keyword has fixed meaning and that cannot be changed by user. Hence, they are also called reserved- words Keywords cannot be used as a variable or function. All keywords should be written in lower letters. Constant: Data items that do not change their values while the program executes, are called constants. The constant cannot be modified in the program. For example: 1, 3,2.55, z. Types of Constant: 1) Integer Constant: An integer is a whole number without any fractional part. 2) Real Constant: Real Constant is a fractional number. 3) Character Constant: A symbol enclosed within a pair of single quotes ( ) is called a character constant.

4 Each character is associated with a unique value called an ASCII (American Standard Code for Information Interchange) code. 4) String Constant: A sequence of characters enclosed within a pair of double quotes ( ) is called a string constant. The string always ends with NULL (denoted by \0) character. For example: 9, a, hello 5) Escape Sequence Characters: An escape sequence character begins with a backslash and is followed by one character. A backslash (\) along with some characters give rise to special print effects by changing the meaning of some characters. PART 2 3 a What is a Variable? Explain the rules for constructing variables in C language. Give examples for valid and invalid variables. A variable is an identifier whose value can be changed during execution of the program. Σ The memory location name where the data can be stored. Rules for defining a variable: 1) The first character in the variable name must be an alphabet or underscore. 2) No commas or blanks are allowed within a variable name. 3) No special symbol other than an underscore can be used in a variable name. 4) A variable name is any combination of alphabets, digits or underscores. Valid Variables: a_b, g1, rem2 Invalid Variables: 1a, h\$ b Two numbers are input through the keyboard into two locations a and b. WAP to interchange the contents of a and b using third variable. #include<stdio.h void main() int a,b,c; printf("\nenter the values of a and b"); scanf("%d%d",&a,&b); printf("\nbefore Swaping the values of a=%d and b=%d",a,b); 4 4

5 c=a; a=b; b=c; printf("\nafter Swaping the values of a=%d and b=%d",a,b); 4 a Explain the primary data types and their variants. Also mention the format specifiers for the same. Data Types: The data type defines the types of data stored in a memory location. Character Integer Float Void Character Data type: Keyword for character is char. It takes 1 byte in memory. Chars, signed and unsigned: Signed: When the variable is having signed like positive or negative. Unsigned: When the variable value is having no signed. A signed char is same as an ordinary char and has a range from -128 to 127; whereas, an unsigned char has a range from 0 to 255. Integer Data Type: Keyword for integer is int. Integer, long and short: Integer can also be classified as short int and long int. The intension of providing these variations is to provide integers with different ranges. Example: short int I; or short I; longint j; or long j; Integers, signed and unsigned: When the value stored in a given integer variable having positive or negative signed that comes under signed integer. Example: signed int I; When the variable is being used to only count things having no signed then it comes under unsigned integer. Example: unsigned int j; Floats and Doubles: A float occupies 4 btyes in memory. If this is insufficient, then C offers a double data type that occupies 8 bytes in memory. If this is insufficient, then C offers a longdouble data type that occupies 10 bytes in memory. 4

6 b Example: float I; double j; long double f; Type Code Example Char: %c Short int : %hd Int : %d Long int: %ld Long long int : %lld Float : %f double : %f Long double : %Lf Write a C program to read a year as an input and find whether it is a leap year or not. Also consider end of the centuries. #include<stdio.h> void main() int year: printf( enter the year ); scanf( %d,&year); if (year%100==0) if( year%400==0) printf( year is leap year ); printf( year is not a leap year ); if (year%4==0) printf( year is leap year ); printf( year is not a leap year ); 4 PART 3 5 a What do you mean by unary, binary and ternary operator explain briefly? 4 1) Unary Operators: Unary operations operate on a single operand, therefore the number 5 when operated by unary will have the value 5. a) Addition or Unary plus ( +). example: a = +5 b) Subtraction or Unary Minus (-). Example: a= -7

7 b c) Increment or Decrement operator (++, --). Example: If a=5 then ++a will be a=6, b=4 then b will be b=3. d) Logical Not (!). Example: A=1 then (! A) will be A=0 e) Bitwise Complement (~). Example: A=1001 then (~A) will be A=0110 f) Address of (&). Example: printf( %d,&a) will print the address of A g) Pointer dereference (*). Example: printf( %d,*a) will print the value at that address 2) Binary operators: A binary operator is an operator that operates on two operands and manipulates them to return a result. Operators are represented by special characters or by keywords and provide an easy way to compare numerical values or character strings. Binary operators are presented in the form: Operand1 Operator Operand2. (a) Arithmetic Operators ( +,-,*,/,%) (b) Relational Operators (<,<=,>,>=,==,!=) (c) Logical Operators (&&, ) (d) Assignment Operators and shorthand assignment operators ( =,+=,-=,etc.) (e) Bitwise Operators (&,,^,<<,>>) 3) Ternary Operators: a ternary operator is an operator that takes three arguments. The arguments and result can be of different types. Many programming languages that use C-like syntax feature a ternary operator,?:, which defines a conditional expression. Exp1?Exp2:Exp3 If exp1 is true ans will be exp 2 otherwise ans will be exp3. A cashier has currency notes of denominations 10,50 and 100. If the amount to be withdrawn is input through the keyboard, write a program to find the total number of currency notes of each denomination the cashier will have to give to the withdrawer. #include<stdio.h> void main() int amount, nohun, nofifty, noten; printf( Enter amount to be withdrawn ); scanf( %d,&amount); nohun=amount/100; amount=amount%100; nofifty=amount/50; 4

8 amount=amount%50; noten=amount/10; printf( No of hundred notes=%d,nohun); printf( No of fifty notes=%d,nofifty); printf( No of ten notes=%d,noten); 6 a Explain Precedence and Associativity with examples. 4 Precedence : An arithmetic expression without parenthesis will be evaluated from left to right using the rules of precedence of operators. There are two distinct priority levels of arithmetic operators in C. High priority * / % Low priority + - Rules for evaluation of expression Σ First parenthesized sub expression left to right are evaluated. Σ If parentheses are nested, the evaluation begins with the innermost sub expression. Σ The precedence rule is applied in determining the order of application of operators in evaluating sub expressions. Σ The associability rule is applied when two or more operators of the same precedence level appear in the sub expression. Σ Arithmetic expressions are evaluated from left to right using the rules of precedence. Σ When Parenthesis is used, the expressions within parenthesis assume highest priority. Associativity Each operator in c has a precedence associated with it. This precedence is used to determine how an expression involving more than one operator is evaluated. There are distinct levels of precedence and an operator may belong to one of these levels. The operators at the higher level of precedence are evaluated first. The operators of the same precedence are evaluated either from left to right or from right to left depending on the level. This is known as associativity property of an operator.

9 b Any integer is input through the keyboard. Write a program to find out whether it is an odd number or even number using bitwise operator. #include<stdio.h> void main() int a; printf( Enter the no ); scanf( %d,&a); if(a&1==0) printf( the number is even ); printf( the number is odd ); PART 4 7 a What do you mean type Conversion? Explain the two types of conversion with examples. 4 4 Type conversion is used to convert data of one type to data of another type. Type conversion is of 2 types as shown in below figure: Data Type Hierarchy: int->unsigned int -> long-> unsigned long->float-> double-> long double Implicit Conversion Σ If a compiler converts one type of data into another type of data automatically, it is known as implicit conversion.

10 There is no data loss in implicit conversion. The conversion always takes place from lower rank to higher rank. For ex: int a =22, b=11; Float c= a; //c becomes Explicit Conversion When the data of one type is converted explicitly to another type with the help of some pre defend functions, it is called as explicit conversion. There may be data loss in this process. Syntax : data_ type1 v1; data_type2 v2=(data_type2) v1; b What will be the output for the following code? 4 void main( ) int a =5, b=2, res1; float f1= 5.0, f2=2.0, res2; res1= 5/2.0 + a/2 + a/b; res2= f1/2 * f1 f2; printf( res 1= %d res2=%f, res1,res2); res 1=6,res2= m=12 n=12 void main() int i=5,j=6,m,n; m=++i + j++; n= --i + j-- ; printf( m=%d n=%d,m,n); 8 a Write a program to implement a simple calculator using switch statement. The program should display the following menu and work according to the user choice. 1: Addition 2: Subtraction 3: Multiplication 4: Division 5: Modulus. Enter your choice #include<stdio.h> void main() int num1,num2,result; char operator; printf( enter the value of num1,operator, num2, \n"); scanf("%d%c%d",&num1,&operator,&num2); switch(operator) case + : result=num1+num2; break; case - : result=num1-num2; break; case * : result=num1*num2; 8

11 break; case / : result=num1/num2; break; case % : result=num1/num2; break; default: printf( Invalid operator"); printf( \nresult: %d %c%d= %d", num1,operator,num2,result); PART 5 9 a What are two-way selection statements? Explain if, if, and cascaded if with examples. Two Way Selection Statement: Decision of choosing one of the 2 alternatives. There are various types of two selection statements are as follows: 8 Decision Statements: A decision control instruction can be implemented in C using: (A) The if statement. (B) The if statement. (C) Nested if statement. (D) Cascaded or Ladder if statement. f statement: The keyword if tells the compiler that what follows is a decision control nstruction. If the condition whatever it is, is true, then the statement is executed. If the condition is not true, then the statement is not executed; instead the program skips past it. Syntax of if: if(this condition is true) execute this statement; Example: #include<stdio.h> void main( ) int num; printf( Enter a number less than 10 ); scanf( %d,&num); if(num<10) printf( XYZ );

12 The if statement: The keyword if tells the compiler that what follows is a decision control instruction. If the condition whatever it is, is true, then the statement is executed. If he condition is not true, then the statement is executed. In both the cases only one portion will be executed according to the if condition. Example: #include<stdio.h> void main() int a; clrscr(); printf( Enter the no ); scanf( %d,&a); if(a%2==0) printf( the number is even ); printf( the number is odd ); Nested if statement: A series of decisions to be made in an order General form if(test exp1) if(test exp2) stat-1; stat-2;

13 Stat-x; stat-3; Example: int a,b,c; if(a<b) if(a<c) printf( a is smallest\n ); printf( c is smallest\n ); if(b<c) printf( b is smallest\n ); printf( c is smallest\n ); Cascaded or Ladder if statement. When multi path decision has to be taken i.e a group of alternatives is available and one alternative has to be chosen Another way of putting if.. together

14 General form if(test exp1) stat-1; if(test exp2) stat-2; if(test exp3) stat-3; default-stat; Example: : #include<stdio.h> void main() int a,b,c; printf( enter the numbers); scanf( %d%d%d,&a,&b,&c); if(a>b&&a>c) printf( A is largest ); if (b>a&&b>c) printf( B is largest ); printf( C is largest );

15 10 a Design and develop a flowchart that takes three coefficients (a, b, and c) of a Quadratic equation (ax 2 +bx+c=0) as input and compute all possible roots. Implement a C program for the developed flowchart and execute the same to output the possible roots for a given set of coefficients with appropriate messages. #include<stdio.h> #include<math.h> void main() 8 float r1,r2,p1,p2,a,b,c,disc; printf("enter the co-efficients\n"); scanf("%f%f%f",&a,&b,&c); if(a==0) printf("the coefficients are zero\n"); disc=b*b-4*a*c; if(disc>0) r1=(-b+sqrt(disc))/(2*a); r2=(-b-sqrt(disc))/(2*a); printf("roots are distinct\n r1=%f\t r2=%f\n",r1,r2); if(disc==0) r1=r2=-b/(2*a); printf("roots are equal \n r1=%f \t r2=%f \n",r1,r2); p1=-b/(2*a); p2=(sqrt(-1*disc))/(2*a); printf("roots are complex\n r1=%f+i%f\t r2=%f-i%f\n",p1,p2,p1,p2);

16

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

FACULTY: Ms. Saritha P.E.S. INSTITUTE OF TECHNOLOGY BANGALORE SOUTH CAMPUS 1 ST INTERNAL ASSESMENT TEST (SCEME AND SOLUTIONS) SUBJECT / CODE: Programming in C and Data Structures- 15PCD13 What is token?

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

SOLUTION OF CONTINUOUS INTERNAL EVALUATION TEST -1 Date : 27-02 2018 Marks:60 Subject & Code : Programming in C and Data Structures- 17PCD23 Name of faculty : Dr. J Surya Prasad/Mr. Naushad Basha Saudagar

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

P.E.S. INSTITUTE OF TECHNOLOGY BANGALORE SOUTH CAMPUS DEPARTMENT OF SCIENCE AND HUMANITIES ST INTERNAL ASSESMENT TEST (SCEME AND SOLUTIONS) EVEN SEMESTER FEB 07 FACULTY: Dr.J Surya Prasad/Ms. Saritha/Mr.

### Basics of Programming

Unit 2 Basics of Programming Problem Analysis When we are going to develop any solution to the problem, we must fully understand the nature of the problem and what we want the program to do. Without the

### Operators and Expressions:

Operators and Expressions: Operators and expression using numeric and relational operators, mixed operands, type conversion, logical operators, bit operations, assignment operator, operator precedence

### UNIT- 3 Introduction to C++

UNIT- 3 Introduction to C++ C++ Character Sets: Letters A-Z, a-z Digits 0-9 Special Symbols Space + - * / ^ \ ( ) [ ] =!= . \$, ; : %! &? _ # = @ White Spaces Blank spaces, horizontal tab, carriage

### Data Types and Variables in C language

Data Types and Variables in C language Disclaimer The slides are prepared from various sources. The purpose of the slides is for academic use only Operators in C C supports a rich set of operators. Operators

### Reserved Words and Identifiers

1 Programming in C Reserved Words and Identifiers Reserved word Word that has a specific meaning in C Ex: int, return Identifier Word used to name and refer to a data element or object manipulated by the

### DEPARTMENT OF MATHS, MJ COLLEGE

T. Y. B.Sc. Mathematics MTH- 356 (A) : Programming in C Unit 1 : Basic Concepts Syllabus : Introduction, Character set, C token, Keywords, Constants, Variables, Data types, Symbolic constants, Over flow,

### Character Set. The character set of C represents alphabet, digit or any symbol used to represent information. Digits 0, 1, 2, 3, 9

Character Set The character set of C represents alphabet, digit or any symbol used to represent information. Types Uppercase Alphabets Lowercase Alphabets Character Set A, B, C, Y, Z a, b, c, y, z Digits

### Features of C. Portable Procedural / Modular Structured Language Statically typed Middle level language

1 History C is a general-purpose, high-level language that was originally developed by Dennis M. Ritchie to develop the UNIX operating system at Bell Labs. C was originally first implemented on the DEC

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

UNIT - I Introduction to C Programming Introduction to C C was originally developed in the year 1970s by Dennis Ritchie at Bell Laboratories, Inc. C is a general-purpose programming language. It has been

### C - Basic Introduction

C - Basic Introduction C is a general-purpose high level language that was originally developed by Dennis Ritchie for the UNIX operating system. It was first implemented on the Digital Equipment Corporation

### Programming in C and Data Structures [15PCD13/23] 1. PROGRAMMING IN C AND DATA STRUCTURES [As per Choice Based Credit System (CBCS) scheme]

Programming in C and Data Structures [15PCD13/23] 1 PROGRAMMING IN C AND DATA STRUCTURES [As per Choice Based Credit System (CBCS) scheme] Course objectives: The objectives of this course is to make students

### Programming and Data Structures

Programming and Data Structures Teacher: Sudeshna Sarkar sudeshna@cse.iitkgp.ernet.in Department of Computer Science and Engineering Indian Institute of Technology Kharagpur #include int main()

### Department of Computer Applications

Sheikh Ul Alam Memorial Degree College Mr. Ovass Shafi. (Assistant Professor) C Language An Overview (History of C) C programming languages is the only programming language which falls under the category

### MODULE 2: Branching and Looping

MODULE 2: Branching and Looping I. Statements in C are of following types: 1. Simple statements: Statements that ends with semicolon 2. Compound statements: are also called as block. Statements written

### UNIT IV INTRODUCTION TO C

UNIT IV INTRODUCTION TO C 1. OVERVIEW OF C C is portable, structured programming language. It is robust, fast.extensible. It is used for complex programs. The root of all modern language is ALGOL (1960).

### Operators and Expressions in C & C++ Mahesh Jangid Assistant Professor Manipal University, Jaipur

Operators and Expressions in C & C++ Mahesh Jangid Assistant Professor Manipal University, Jaipur Operators and Expressions 8/24/2012 Dept of CS&E 2 Arithmetic operators Relational operators Logical operators

### Advantages of writing algorithm

Advantages of writing algorithm Effective communication: Algorithm is written using English like language,algorithm is better way of communicating the logic to the concerned people Effective Analysis:

### Intro to Computer Programming (ICP) Rab Nawaz Jadoon

Intro to Computer Programming (ICP) Rab Nawaz Jadoon DCS COMSATS Institute of Information Technology Assistant Professor COMSATS IIT, Abbottabad Pakistan Introduction to Computer Programming (ICP) What

### I Internal Examination Sept Class: - BCA I Subject: - Principles of Programming Lang. (BCA 104) MM: 40 Set: A Time: 1 ½ Hrs.

I Internal Examination Sept. 2018 Class: - BCA I Subject: - Principles of Programming Lang. (BCA 104) MM: 40 Set: A Time: 1 ½ Hrs. [I]Very short answer questions (Max 40 words). (5 * 2 = 10) 1. What is

### Informatics Ingeniería en Electrónica y Automática Industrial

Informatics Ingeniería en Electrónica y Automática Industrial Operators and expressions in C Operators and expressions in C Numerical expressions and operators Arithmetical operators Relational and logical

### CSc 10200! Introduction to Computing. Lecture 2-3 Edgardo Molina Fall 2013 City College of New York

CSc 10200! Introduction to Computing Lecture 2-3 Edgardo Molina Fall 2013 City College of New York 1 C++ for Engineers and Scientists Third Edition Chapter 2 Problem Solving Using C++ 2 Objectives In this

### LESSON 1. A C program is constructed as a sequence of characters. Among the characters that can be used in a program are:

LESSON 1 FUNDAMENTALS OF C The purpose of this lesson is to explain the fundamental elements of the C programming language. C like other languages has all alphabet and rules for putting together words

### C: How to Program. Week /Mar/05

1 C: How to Program Week 2 2007/Mar/05 Chapter 2 - Introduction to C Programming 2 Outline 2.1 Introduction 2.2 A Simple C Program: Printing a Line of Text 2.3 Another Simple C Program: Adding Two Integers

### Prepared by: Shraddha Modi

Prepared by: Shraddha Modi Introduction Operator: An operator is a symbol that tells the Computer to perform certain mathematical or logical manipulations. Expression: An expression is a sequence of operands

### Fundamental of C programming. - Ompal Singh

Fundamental of C programming - Ompal Singh HISTORY OF C LANGUAGE IN 1960 ALGOL BY INTERNATIONAL COMMITTEE. IT WAS TOO GENERAL AND ABSTRUCT. IN 1963 CPL(COMBINED PROGRAMMING LANGUAGE) WAS DEVELOPED AT CAMBRIDGE

### These are reserved words of the C language. For example int, float, if, else, for, while etc.

Tokens in C Keywords These are reserved words of the C language. For example int, float, if, else, for, while etc. Identifiers An Identifier is a sequence of letters and digits, but must start with a letter.

### Guide for The C Programming Language Chapter 1. Q1. Explain the structure of a C program Answer: Structure of the C program is shown below:

Q1. Explain the structure of a C program Structure of the C program is shown below: Preprocessor Directives Global Declarations Int main (void) Local Declarations Statements Other functions as required

### Java Notes. 10th ICSE. Saravanan Ganesh

Java Notes 10th ICSE Saravanan Ganesh 13 Java Character Set Character set is a set of valid characters that a language can recognise A character represents any letter, digit or any other sign Java uses

### C++ Programming: From Problem Analysis to Program Design, Third Edition

C++ Programming: From Problem Analysis to Program Design, Third Edition Chapter 2: Basic Elements of C++ Objectives (continued) Become familiar with the use of increment and decrement operators Examine

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

C Language Part 1 (Minor modifications by the instructor) References C for Python Programmers, by Carl Burch, 2011. http://www.toves.org/books/cpy/ The C Programming Language. 2nd ed., Kernighan, Brian,

### Expressions and Data Types CSC 121 Spring 2015 Howard Rosenthal

Expressions and Data Types CSC 121 Spring 2015 Howard Rosenthal Lesson Goals Understand the basic constructs of a Java Program Understand how to use basic identifiers Understand simple Java data types

### BCA-105 C Language What is C? History of C

C Language What is C? C is a programming language developed at AT & T s Bell Laboratories of USA in 1972. It was designed and written by a man named Dennis Ritchie. C seems so popular is because it is

### Department of Computer Science

Department of Computer Science Definition An operator is a symbol (+,-,*,/) that directs the computer to perform certain mathematical or logical manipulations and is usually used to manipulate data and

### Differentiate Between Keywords and Identifiers

History of C? Why we use C programming language Martin Richards developed a high-level computer language called BCPL in the year 1967. The intention was to develop a language for writing an operating system(os)

### Computer System and programming in C

1 Basic Data Types Integral Types Integers are stored in various sizes. They can be signed or unsigned. Example Suppose an integer is represented by a byte (8 bits). Leftmost bit is sign bit. If the sign

### C Programming Multiple. Choice

C Programming Multiple Choice Questions 1.) Developer of C language is. a.) Dennis Richie c.) Bill Gates b.) Ken Thompson d.) Peter Norton 2.) C language developed in. a.) 1970 c.) 1976 b.) 1972 d.) 1980

### Objectives. Chapter 2: Basic Elements of C++ Introduction. Objectives (cont d.) A C++ Program (cont d.) A C++ Program

Objectives Chapter 2: Basic Elements of C++ In this chapter, you will: Become familiar with functions, special symbols, and identifiers in C++ Explore simple data types Discover how a program evaluates

### Chapter 2: Basic Elements of C++

Chapter 2: Basic Elements of C++ Objectives In this chapter, you will: Become familiar with functions, special symbols, and identifiers in C++ Explore simple data types Discover how a program evaluates

### Chapter 2: Basic Elements of C++ Objectives. Objectives (cont d.) A C++ Program. Introduction

Chapter 2: Basic Elements of C++ C++ Programming: From Problem Analysis to Program Design, Fifth Edition 1 Objectives In this chapter, you will: Become familiar with functions, special symbols, and identifiers

### PART I. Part II Answer to all the questions 1. What is meant by a token? Name the token available in C++.

Unit - III CHAPTER - 9 INTRODUCTION TO C++ Choose the correct answer. PART I 1. Who developed C++? (a) Charles Babbage (b) Bjarne Stroustrup (c) Bill Gates (d) Sundar Pichai 2. What was the original name

### Operators in C. Staff Incharge: S.Sasirekha

Operators in C Staff Incharge: S.Sasirekha Operators An operator is a symbol which helps the user to command the computer to do a certain mathematical or logical manipulations. Operators are used in C

### Computers Programming Course 5. Iulian Năstac

Computers Programming Course 5 Iulian Năstac Recap from previous course Classification of the programming languages High level (Ada, Pascal, Fortran, etc.) programming languages with strong abstraction

### By the end of this section you should: Understand what the variables are and why they are used. Use C++ built in data types to create program

1 By the end of this section you should: Understand what the variables are and why they are used. Use C++ built in data types to create program variables. Apply C++ syntax rules to declare variables, initialize

### ANSI C Programming Simple Programs

ANSI C Programming Simple Programs /* This program computes the distance between two points */ #include #include #include main() { /* Declare and initialize variables */ double

### Chapter 2 - Introduction to C Programming

Chapter 2 - Introduction to C Programming 2 Outline 2.1 Introduction 2.2 A Simple C Program: Printing a Line of Text 2.3 Another Simple C Program: Adding Two Integers 2.4 Memory Concepts 2.5 Arithmetic

### JAVA Programming Fundamentals

Chapter 4 JAVA Programming Fundamentals By: Deepak Bhinde PGT Comp.Sc. JAVA character set Character set is a set of valid characters that a language can recognize. It may be any letter, digit or any symbol

### Fundamental of Programming (C)

Borrowed from lecturer notes by Omid Jafarinezhad Fundamental of Programming (C) Lecturer: Vahid Khodabakhshi Lecture 3 Constants, Variables, Data Types, And Operations Department of Computer Engineering

### UNIT 3 OPERATORS. [Marks- 12]

1 UNIT 3 OPERATORS [Marks- 12] SYLLABUS 2 INTRODUCTION C supports a rich set of operators such as +, -, *,,

### CHAPTER 3 BASIC INSTRUCTION OF C++

CHAPTER 3 BASIC INSTRUCTION OF C++ MOHD HATTA BIN HJ MOHAMED ALI Computer programming (BFC 20802) Subtopics 2 Parts of a C++ Program Classes and Objects The #include Directive Variables and Literals Identifiers

### Fundamentals of Programming

Fundamentals of Programming Lecture 3 - Constants, Variables, Data Types, And Operations Lecturer : Ebrahim Jahandar Borrowed from lecturer notes by Omid Jafarinezhad Outline C Program Data types Variables

### C Programming Class I

C Programming Class I Generation of C Language Introduction to C 1. In 1967, Martin Richards developed a language called BCPL (Basic Combined Programming Language) 2. In 1970, Ken Thompson created a language

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

M4.1-R3: PROGRAMMING AND PROBLEM SOLVING THROUGH C LANGUAGE NOTE: 1. There are TWO PARTS in this Module/Paper. PART ONE contains FOUR questions and PART TWO contains FIVE questions. 2. PART ONE is to be

### Chapter 2: Introduction to C++

Chapter 2: Introduction to C++ Copyright 2010 Pearson Education, Inc. Copyright Publishing as 2010 Pearson Pearson Addison-Wesley Education, Inc. Publishing as Pearson Addison-Wesley 2.1 Parts of a C++

### Chapter 2: Special Characters. Parts of a C++ Program. Introduction to C++ Displays output on the computer screen

Chapter 2: Introduction to C++ 2.1 Parts of a C++ Program Copyright 2009 Pearson Education, Inc. Copyright 2009 Publishing Pearson as Pearson Education, Addison-Wesley Inc. Publishing as Pearson Addison-Wesley

### Unit-2 (Operators) ANAND KR.SRIVASTAVA

Unit-2 (Operators) ANAND KR.SRIVASTAVA 1 Operators in C ( use of operators in C ) Operators are the symbol, to perform some operation ( calculation, manipulation). Set of Operations are used in completion

### c) Comments do not cause any machine language object code to be generated. d) Lengthy comments can cause poor execution-time performance.

2.1 Introduction (No questions.) 2.2 A Simple Program: Printing a Line of Text 2.1 Which of the following must every C program have? (a) main (b) #include (c) /* (d) 2.2 Every statement in C

### Full file at C How to Program, 6/e Multiple Choice Test Bank

2.1 Introduction 2.2 A Simple Program: Printing a Line of Text 2.1 Lines beginning with let the computer know that the rest of the line is a comment. (a) /* (b) ** (c) REM (d)

### UNIT IV 2 MARKS. ( Word to PDF Converter - Unregistered ) FUNDAMENTALS OF COMPUTING & COMPUTER PROGRAMMING

( Word to PDF Converter - Unregistered ) http://www.word-to-pdf-converter.net FUNDAMENTALS OF COMPUTING & COMPUTER PROGRAMMING INTRODUCTION TO C UNIT IV Overview of C Constants, Variables and Data Types

### A complex expression to evaluate we need to reduce it to a series of simple expressions. E.g * 7 =>2+ 35 => 37. E.g.

1.3a Expressions Expressions An Expression is a sequence of operands and operators that reduces to a single value. An operator is a syntactical token that requires an action be taken An operand is an object

### Unit-II Programming and Problem Solving (BE1/4 CSE-2)

Unit-II Programming and Problem Solving (BE1/4 CSE-2) Problem Solving: Algorithm: It is a part of the plan for the computer program. An algorithm is an effective procedure for solving a problem in a finite

### BASIC ELEMENTS OF A COMPUTER PROGRAM

BASIC ELEMENTS OF A COMPUTER PROGRAM CSC128 FUNDAMENTALS OF COMPUTER PROBLEM SOLVING LOGO Contents 1 Identifier 2 3 Rules for naming and declaring data variables Basic data types 4 Arithmetic operators

### Programming for Engineers Introduction to C

Programming for Engineers Introduction to C ICEN 200 Spring 2018 Prof. Dola Saha 1 Simple Program 2 Comments // Fig. 2.1: fig02_01.c // A first program in C begin with //, indicating that these two lines

### Work relative to other classes

Work relative to other classes 1 Hours/week on projects 2 C BOOTCAMP DAY 1 CS3600, Northeastern University Slides adapted from Anandha Gopalan s CS132 course at Univ. of Pittsburgh Overview C: A language

### Assignment: 1. (Unit-1 Flowchart and Algorithm)

Assignment: 1 (Unit-1 Flowchart and Algorithm) 1. Explain: Flowchart with its symbols. 2. Explain: Types of flowchart with example. 3. Explain: Algorithm with example. 4. Draw a flowchart to find the area

### CS102: Variables and Expressions

CS102: Variables and Expressions The topic of variables is one of the most important in C or any other high-level programming language. We will start with a simple example: int x; printf("the value of

### Data Types and Variables in C language

Data Types and Variables in C language Basic structure of C programming To write a C program, we first create functions and then put them together. A C program may contain one or more sections. They are

### Computer Programming CS F111

Computer Programming CS F111 BITS Pilani Dubai Campus NAND KUMAR Basics of C Programming BITS Pilani Dubai Campus Write a program that 1. Asks 5 marks from the user, find the average of the marks and print

### Java Programming Fundamentals. Visit for more.

Chapter 4: Java Programming Fundamentals Informatics Practices Class XI (CBSE Board) Revised as per CBSE Curriculum 2015 Visit www.ip4you.blogspot.com for more. Authored By:- Rajesh Kumar Mishra, PGT (Comp.Sc.)

### 3. EXPRESSIONS. It is a sequence of operands and operators that reduce to a single value.

3. EXPRESSIONS It is a sequence of operands and operators that reduce to a single value. Operator : It is a symbolic token that represents an action to be taken. Ex: * is an multiplication operator. Operand:

### Unit 3. Operators. School of Science and Technology INTRODUCTION

INTRODUCTION Operators Unit 3 In the previous units (unit 1 and 2) you have learned about the basics of computer programming, different data types, constants, keywords and basic structure of a C program.

### Introduction to C Programming. Chih-Wei Tang ( 唐之瑋 ) Department of Communication Engineering National Central University JhongLi, Taiwan

Introduction to C Programming Chih-Wei Tang ( 唐之瑋 ) Department of Communication Engineering National Central University JhongLi, Taiwan Outline Printing texts Adding 2 integers Comparing 2 integers C.E.,

### Expressions and Data Types CSC 121 Fall 2015 Howard Rosenthal

Expressions and Data Types CSC 121 Fall 2015 Howard Rosenthal Lesson Goals Understand the basic constructs of a Java Program Understand how to use basic identifiers Understand simple Java data types and

### Q 1. Attempt any TEN of the following:

Subject Code: 17212 Model Answer Page No: 1 / 26 Important Instructions to examiners: 1) The answers should be examined by key words and not as word-to-word as given in the model answer scheme. 2) The

### Lecture 02 C FUNDAMENTALS

Lecture 02 C FUNDAMENTALS 1 Keywords C Fundamentals auto double int struct break else long switch case enum register typedef char extern return union const float short unsigned continue for signed void

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

Unit 1 Programming Language and Overview of C 1. State whether the following statements are true or false. a. Every line in a C program should end with a semicolon. b. In C language lowercase letters are

### CS5000: Foundations of Programming. Mingon Kang, PhD Computer Science, Kennesaw State University

CS5000: Foundations of Programming Mingon Kang, PhD Computer Science, Kennesaw State University Overview of Source Code Components Comments Library declaration Classes Functions Variables Comments Can

### Module 2 - Part 2 DATA TYPES AND EXPRESSIONS 1/15/19 CSE 1321 MODULE 2 1

Module 2 - Part 2 DATA TYPES AND EXPRESSIONS 1/15/19 CSE 1321 MODULE 2 1 Topics 1. Expressions 2. Operator precedence 3. Shorthand operators 4. Data/Type Conversion 1/15/19 CSE 1321 MODULE 2 2 Expressions

### Information Science 1

Information Science 1 Simple Calcula,ons Week 09 College of Information Science and Engineering Ritsumeikan University Topics covered l Terms and concepts from Week 8 l Simple calculations Documenting

### ADARSH VIDYA KENDRA NAGERCOIL COMPUTER SCIENCE. Grade: IX C++ PROGRAMMING. Department of Computer Science 1

NAGERCOIL COMPUTER SCIENCE Grade: IX C++ PROGRAMMING 1 C++ 1. Object Oriented Programming OOP is Object Oriented Programming. It was developed to overcome the flaws of the procedural approach to programming.

### CMSC 104 -Lecture 6 John Y. Park, adapted by C Grasso

CMSC 104 -Lecture 6 John Y. Park, adapted by C Grasso 1 Topics #define Arithmetic Operators Assignment Operators Operator Precedence Evaluating Arithmetic Expressions Incremental Programming 2 Preprocessor

### CSE 1001 Fundamentals of Software Development 1. Identifiers, Variables, and Data Types Dr. H. Crawford Fall 2018

CSE 1001 Fundamentals of Software Development 1 Identifiers, Variables, and Data Types Dr. H. Crawford Fall 2018 Identifiers, Variables and Data Types Reserved Words Identifiers in C Variables and Values

### Basics of Java Programming

Basics of Java Programming Lecture 2 COP 3252 Summer 2017 May 16, 2017 Components of a Java Program statements - A statement is some action or sequence of actions, given as a command in code. A statement

### 2/29/2016. Definition: Computer Program. A simple model of the computer. Example: Computer Program. Data types, variables, constants

Data types, variables, constants Outline.1 Introduction. Text.3 Memory Concepts.4 Naming Convention of Variables.5 Arithmetic in C.6 Type Conversion Definition: Computer Program A Computer program is a

### C OVERVIEW. C Overview. Goals speed portability allow access to features of the architecture speed

C Overview C OVERVIEW Goals speed portability allow access to features of the architecture speed C fast executables allows high-level structure without losing access to machine features many popular languages

### 4.1. Structured program development Overview of C language

4.1. Structured program development 4.2. Data types 4.3. Operators 4.4. Expressions 4.5. Control flow 4.6. Arrays and Pointers 4.7. Functions 4.8. Input output statements 4.9. storage classes. UNIT IV

### CS113: Lecture 3. Topics: Variables. Data types. Arithmetic and Bitwise Operators. Order of Evaluation

CS113: Lecture 3 Topics: Variables Data types Arithmetic and Bitwise Operators Order of Evaluation 1 Variables Names of variables: Composed of letters, digits, and the underscore ( ) character. (NO spaces;

### 2.1. Chapter 2: Parts of a C++ Program. Parts of a C++ Program. Introduction to C++ Parts of a C++ Program

Chapter 2: Introduction to C++ 2.1 Parts of a C++ Program Copyright 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 2-1 Parts of a C++ Program Parts of a C++ Program // sample C++ program

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

COMPUTER SCIENCE HIGHER SECONDARY FIRST YEAR VOLUME II - CHAPTER 10 PROBLEM SOLVING TECHNIQUES AND C PROGRAMMING 1,2,3 & 5 MARKS S.LAWRENCE CHRISTOPHER, M.C.A., B.Ed., LECTURER IN COMPUTER SCIENCE PONDICHERRY

### Introduction to C programming. By Avani M. Sakhapara Asst Professor, IT Dept, KJSCE

Introduction to C programming By Avani M. Sakhapara Asst Professor, IT Dept, KJSCE Classification of Software Computer Software System Software Application Software Growth of Programming Languages History

### A First Program - Greeting.cpp

C++ Basics A First Program - Greeting.cpp Preprocessor directives Function named main() indicates start of program // Program: Display greetings #include using namespace std; int main() { cout

### 3. Java - Language Constructs I

Educational Objectives 3. Java - Language Constructs I Names and Identifiers, Variables, Assignments, Constants, Datatypes, Operations, Evaluation of Expressions, Type Conversions You know the basic blocks

### LESSON 5 FUNDAMENTAL DATA TYPES. char short int long unsigned char unsigned short unsigned unsigned long

LESSON 5 ARITHMETIC DATA PROCESSING The arithmetic data types are the fundamental data types of the C language. They are called "arithmetic" because operations such as addition and multiplication can be

### C OVERVIEW BASIC C PROGRAM STRUCTURE. C Overview. Basic C Program Structure

C Overview Basic C Program Structure C OVERVIEW BASIC C PROGRAM STRUCTURE Goals The function main( )is found in every C program and is where every C program begins speed execution portability C uses braces

### 2. Numbers In, Numbers Out

REGZ9280: Global Education Short Course - Engineering 2. Numbers In, Numbers Out Reading: Moffat, Chapter 2. REGZ9280 14s2 2. Numbers In, Numbers Out 1 The Art of Programming Think about the problem Write

### Objectives. In this chapter, you will:

Objectives In this chapter, you will: Become familiar with functions, special symbols, and identifiers in C++ Explore simple data types Discover how a program evaluates arithmetic expressions Learn about