26
[UNIT-I] 1. (a) What are the steps involved in program development process? Explain. The set of sequence of steps need to be follow to develop a program are collectively known as Program Development steps. The program development steps are 1. Define or understand the problem. 2. Outline the solution 3. Designing the algorithm. 4. Desk check or test the algorithm 5. Coding the program. 6. Run the program on computer system 7. Testing the program. 8. Documentation & Maintaining the program. Define or understand the problem In this step the user has to reads and re-reads the given problem until he/she understands the given problem. It involves recognizing the problem; identifying exactly what the problem is; determining the available inputs and desired output; deciding whether problem can be solved by using computer. Outline the solution In this step the solution method will be defined to solve the given problem. If more than one solution methods are available to solve the same problem then an efficient solution method will be chosen to solve the given problem. Designing the algorithm An algorithm is finite set of step-by-step instructions that solve a problem. In this step after defining the solution method, algorithm can designed. Desk check or testing the algorithm In this step the algorithm will be tested by providing required input data to check whether the algorithm is providing correct results or not. Through algorithm testing the logical errors will be detected easily. Coding/ implementing the program It involves actually writing the instructions in a particular programming language that tell the computer how to operate. In general the programming language will be chosen based on the complexity of the problem to be solved. Run the program on computer In this step we have to execute the program to get the result (output). While executing the program three types of errors or bugs can be found which are

nriit.ac.in mid-2018.docx  · Web viewThe process of organizing complete information about the program is called documentation of program

Embed Size (px)

Citation preview

Page 1: nriit.ac.in mid-2018.docx  · Web viewThe process of organizing complete information about the program is called documentation of program

[UNIT-I]

1. (a) What are the steps involved in program development process? Explain.

The set of sequence of steps need to be follow to develop a program are collectively known as Program Development steps. The program development steps are

1. Define or understand the problem. 2. Outline the solution3. Designing the algorithm.4. Desk check or test the algorithm 5. Coding the program. 6. Run the program on computer system7. Testing the program. 8. Documentation & Maintaining the program.

Define or understand the problemIn this step the user has to reads and re-reads the given problem until he/she understands the given problem. It involves recognizing the problem; identifying exactly what the problem is; determining the available inputs and desired output; deciding whether problem can be solved by using computer.

Outline the solutionIn this step the solution method will be defined to solve the given problem. If more than one solution methods are available to solve the same problem then an efficient solution method will be chosen to solve the given problem.

Designing the algorithmAn algorithm is finite set of step-by-step instructions that solve a problem. In this

step after defining the solution method, algorithm can designed.

Desk check or testing the algorithmIn this step the algorithm will be tested by providing required input data to check

whether the algorithm is providing correct results or not. Through algorithm testing the logical errors will be detected easily.

Coding/ implementing the programIt involves actually writing the instructions in a particular programming

language that tell the computer how to operate. In general the programming language will be chosen based on the complexity of the problem to be solved.

Run the program on computer In this step we have to execute the program to get the result (output). While

executing the program three types of errors or bugs can be found which are1. Syntax error 2. Logical error 3. Runtime error

Syntax ErrorSyntax is a set of rules by which a programming language is governed. Syntax

error occurs when these rules are violated while coding of the program.

Logical ErrorImproper coding of individual statements either or sequence of statements

causes this type of computer program. It does not stop the program execution but gives wrong results.

Runtime ErrorThis error in a computer program stops its execution. It may be caused by an

entry of invalid data.

Testing the program

Page 2: nriit.ac.in mid-2018.docx  · Web viewThe process of organizing complete information about the program is called documentation of program

This step involves testing of program to check whether the program is producing acceptable output or not.

Documentation and Maintaining the ProgramThe process of organizing complete information about the program is called

documentation of program.The process of editing the program according to the requirements of the

customer is called maintenance or upgrading of the program.In this step programmer has to write the programs using proper coding styles

and comment lines.

(b) What is Central Processing unit (CPU) in a computer? Explain about various components and their functions of CPU.

Processor (CPU)It is also called as CPU(Central Processing

Unit). It is the brain of the computer that is responsible for controlling and executing program instructions entered through the input devices like keyboard and mouse.

If the computer consisting of only one processor then it is known as Central Processing Unit. Multi Processor System means the computer consists more than one processor.

The CPU consisting of three internal components. 1. Internal Registers

2. Control Unit3. ALU (Arithmetic and Logic Unit)

The Internal Registers like MAR, MBR, I/OAR, I/OBR, PC & IR used to store the data temporarily while executing a program.The Control Unit is responsible for controlling the hardware components and all the activities of the computer.

The ALU is used to perform arithmetic and logical operations. Logical operations can be used to form complex conditional statements.

2. (a) What are the differences between Procedural Languages and Object Oriented Languages (OOPS)?

Procedural Languages Object Oriented languages

In procedural language a program is collection of procedures or functions

In object oriented languages a program is collection of objects

Procedural Languages focuses on functions Object Oriented languages focuses on objects

Data reusability is not possibleData reusability is one of the important feature of Object Oriented language

Page 3: nriit.ac.in mid-2018.docx  · Web viewThe process of organizing complete information about the program is called documentation of program

Data hiding is not possibleData hiding will be done with the help of private members

Procedural Languages follows top-down approachObject oriented languages follows bottom-up approach

Procedural Languages are easy to implement Object oriented languages are complex to implement

(b) Differentiate different Computer Languages?There are three levels of programming languages are available. They are:

1. Machine languages (a.k.a Low-level Languages) 2. Assembly languages (a.k.a Symbolic Languages) 3. High level languages

Machine LanguagesA language that is directly understood by the computer without any translation

is called machine languages. A machine language is string of 0s and 1s. Machine languages are usually referred to as the first generation languages. It is also referred to as machine code or object code. Therefore, all instructions and data should be written using binary codes i.e., 0’s and 1’s.Each instruction performs a specific task, such as a load, a jump, or an ALU operation on a unit of data in a CPU register or memory.

Machine language is the lowest-level programming language. Programs and applications written in low-level language are directly executable on the computing hardware without any interpretation or translation. Machine language and assembly language are popular examples of low level languages.An instruction written in any machine language has two parts:

i. Operation code (Opcode) ii. Operand address or location

Advantages: Execution speed is very fast

Efficient use of primary memory It does not require any translation because machine code is directly understood by the computer.

Disadvantages

Machine dependent: The machine language is different for different types of computers.

Difficult to write program: because it requires memorizing dozens of opcodes for different commands. Error prone:

Difficult to modify

Assembly Languages: Assembly languages are usually referred to as the second-generation languages. It is also lowest-level programming language. These are introduced in 1950’s. Assembly languages are just one level higher than machine language.

Assembly language consists of special codes called mnemonics to represent the language instructions instead of 0’s and 1’s. The mnemonic code is also called as operation code or opcode.

For example, ADD, SUB, MUL, JMP, LOAD

Advantages

Easier to memorize and use:Assembly language program is easy to use, understand and memorize because it uses mnemonic codes in place of binary codes

Easy to write input data: In assembly language programs the input data can be written in decimal number system, later they are converted into binary.

Page 4: nriit.ac.in mid-2018.docx  · Web viewThe process of organizing complete information about the program is called documentation of program

It is easier to correct errors and modify program instructions.

The Assembly Language has the same efficiency of execution as the machine level language. Because this is one-to-one translator between assembly language program and its corresponding machine language program.

Easy print out.

Good library facility.

Disadvantages

Machine dependent. A program written for one computer might not run in other computers with different hardware configuration.

Knowledge of hardware is required.

Time consuming

Translators required (i.e. Assembler)

Assembler: The software used to convert an assembly language programs into machines codes is called an assembler.

High Level Languages: Sometimes abbreviated as HLL, a high-level language is a computer programming language that isn't limited by the computer, designed for a specific job, and is easier to understand. It is more like human language and less like machine language. However, for a computer to understand and run a program created with a high-level language, it must be compiled into machine language.

The first high-level languages were introduced in the 1950's. Today, there are many high-level languages in use, including BASIC, C, C++, COBOL, FORTRAN, Java, Pascal, Perl, PHP, Python, Ruby and Visual Basic.

3. (a) Discuss the features characteristics of Application software and System Software.

Software means a set of computer instructions or programs. Basically computer software divided into two types.

1. System software 2. Application software

1. System software: It is a collection of programs that directly interfaces with the hardware that provides the basic non-task-specific functions of the computer. Some common categories of system software are as follows

Language translators: It is system software that transforms a computer program written by programmer into a form that can be understood by the machine.

Operating System: The Operating System (OS) is an interface between the computer software and hardware. The most popular and latest operating systems include UNIX, Linux, Windows 10, Mac, Sun Solaris etc.

Utilities: Utility programs are those that may be requested by application programs many times during the execution phase. Some examples are as follows: sort/merge techniques and Transfer programs for transforming data content from one medium to another. Ex: disk to tape, tape to disk, etc.

Special purpose software: It extends the capability of operating systems to provide specialized services to application programs. Ex: Loader, linker etc.

Features of system software are as follows: Close to system Fast in speed Difficult to design Difficult to understand Less interactive Smaller in size Difficult to manipulate Generally written in low-level language

Page 5: nriit.ac.in mid-2018.docx  · Web viewThe process of organizing complete information about the program is called documentation of program

2. Application software: Application software which is used by users to accomplish specific tasks. The application software includes printing documents, and permitting access to internet for web and video conferencing activities. Ex: MS-word, Excel, power point etc. Examples of Application software are following

Payroll Software Student Record Software Inventory Management Software Income Tax Software Railways Reservation Software Microsoft Office Suite Software Microsoft Word Microsoft Excel Microsoft Power point

Features of application software are as follows Close to user Easy to design More interactive Slow in speed Generally written in high-level language Easy to understand Easy to manipulate and use

Bigger in size and requires large storage space(b) Write an algorithm for finding the sum of first ‘N’ natural numbers. (Hint: sum of first ‘N’ natural numbers=N(N+1)/2Step 1: StartStep 2: Read an integer say N.Step 3: sum= N(N+1) / 2 Step 4: Display sumStep 5: Stop

4.(a) Explain the basic organization of a computer with neat diagramA computer system is made up of two basic elements

1. Hardware 2. Software

HardwareThe physical parts of computer system are referred to as hardware. All electronic

and mechanical items that constitute computer system fall into the category of hardware. For example, keyboard, mouse, monitor, printer, processor etc. are hardware.Input devices

An input device sends information to a computer system for processing. An input device can send data to another device, but it cannot receive data from another device. Examples of an input device include:

Keyboard mouse Scanner Joystick light pen and track ball

Which can send data (input) to the computer, but they cannot receive or reproduce information (output) from the computer.

Output devicesAn output device reproduces or displays the results of that processing. An output device can receive data from another device, but it cannot send data to another device. Examples of an output device include a

Monitor Speakers Printer and Projector

Page 6: nriit.ac.in mid-2018.docx  · Web viewThe process of organizing complete information about the program is called documentation of program

Which can receive data (output) from the computer, but they cannot send information (input) to the computer.

ProcessorIt is also called as CPU(Central Processing Unit). It is the brain of the computer

that is responsible for controlling and executing program instructions entered through the input devices like keyboard and mouse.

MemoryThe computer memory is a temporary storage area in a computer system. It is used to store data and instructions. The memory is divided into large number of small parts called cells.Computer Memory can be divided into mainly two types.

1) Primary memories which includes RAM and ROM 2) Secondary memories which includes hard disks, floppy discs, USB storages and

CD-ROM, Magnetic tapes and drives. Communication Devices:

Communication devices can be used to provide communication among internal parts of computer system, among different computers and a computer with external sources like Internet. System Bus, LAN switch, Router . . . . . are examples for communication devices.

(b) What is flow chart? Explain different symbols used to draw flow charts.Flowchart:

Flowchart is a pictorial or symbolic representation of an algorithm.It indicates process of solution. They are constructed by using special geometrical symbols. Each symbol represents an activity.

Symbols used to draw flowcharts:

Page 7: nriit.ac.in mid-2018.docx  · Web viewThe process of organizing complete information about the program is called documentation of program

[UNIT-II]5.(a) List the basic data types, their sizes and range of values supported by C Language.The list of data types , , their sizes and range of values supported by C Language based on 16-bit machine are

Data Type Size (in Bytes) Range

unsigned char 1 0 to 28-1

signed char 1 -27 to 27-1

unsigned short 1 0 to 28-1

short 1 -27 to 27-1

unsigned int 2 0 to 216-1

int 2 -215 to 215-1

Page 8: nriit.ac.in mid-2018.docx  · Web viewThe process of organizing complete information about the program is called documentation of program

NRI Institute of Technology: GunturC-Programming Mid-1 Questions

unsigned long 4 0 to 232-1

long 4 -231 to 231-1

float 4 3.4E-38 to 3.4E +38

double 8 1.7E-308 to 1.7E+308

long double 10 3.4E-4932 to 1.1E+4932

(b) Write a C program to swap the values of two variables without using temporary variable.

#include<stdio.h>void main( ){int a,b;printf(“Enter any two integer values:”);scanf(“%d%d”,&a,&b);printf(“Before swap a=%d \t b=%d”,a,b);a=a+b;b=a-b;a=a-b;printf(“After swap a=%d \t b=%d”,a,b);}

6. (a) Explain about different special relational operators available in C language with example?

Relational operators

A relational operator, also known as a comparison operator, is an operator that compares two operands. The operands can be variables, constants or expressions. Relational operators always return either true or false

C has six relational operators. The following table shows these operators along with their meanings

Operator Meaning Example Result

< Less than 3<5 Non-zero (1)

> Greater than 7<9 Zero (0)

<= Less than or equal to 100<=100 Non-zero

>= Greater than or equal to 50>=100 Zero

Page 9: nriit.ac.in mid-2018.docx  · Web viewThe process of organizing complete information about the program is called documentation of program

NRI Institute of Technology: GunturC-Programming Mid-1 Questions

== Equal to 10==9 Zero

!= Not equal to 10!=9 Non-zero

(b) Explain pre- and post- decrement and increment operation on a variable with an example.

Increment (++) and decrement (− −) operators

The increment operator is unary operator that increases value of its operand by 1. Similarly, the decrement operator decreases value of its operand by 1. These operators are unique in that they work only on variables not on constants. These are used in loops like while, do-while and for statements.

There are two ways to use increment or decrement operators in expressions.

Pre-increment(++operand): If the increment operator is placed before (pre-fixed) the operand then it is known as pre-increment.

Ex: x=++y; (In pre-increment first the value of y will be incremented then the updated value of y will be assigned to x.)

Post-increment(operand++): If the increment operator is placed after (post-fixed) the operand then it is known as post-increment.

Ex: x=y++; (In post-increment first the value of y will be assigned to x then the value of y will be incremented)

Pre-decrement(- -operand): If the decrement operator is placed before (pre-fixed) the operand then it is known as pre-decrement.

Ex: x=--y; (In pre-decrement first the value of y will be decremented then the updated value of y will be assigned to x.)

Post-decrement(operand- -): If the decrement operator is placed after (post-fixed) the operand then it is known as post-decrement.

Ex: x=y- -; (In post-decrement first the value of y will be assigned to x then the value of y will be decremented)

Operator Name Example Result

x++ Post-increment

Assume A=20

X=A++

First assignment then increment

X=20

A=21

Page 10: nriit.ac.in mid-2018.docx  · Web viewThe process of organizing complete information about the program is called documentation of program

NRI Institute of Technology: GunturC-Programming Mid-1 Questions

++x Pre-increment

Assume A=20

X=++A

First increment then assignment

X=21

A=21

x− − Post-decrement

Assume A=20

X=A--

First assignment then decrement

X=20

A=19

− −x Pre-decrement

Assume A=20

X=--A

First decrement then assignment

X=19

A=19

7. (a) Explain different bitwise operators available in C with example?

As the name suggests, the bitwise operators operate on bits. These operations include:

1. bitwise AND(&)2. bitwise OR(|)3. bitwise X-OR(^)4. bitwise NOT(~)5. shift left(<<)6. shift right(>>)

Bitwise AND (&)

When we use the bitwise AND operator, the bit in the first operand is ANDed with the corresponding bit in the second operand. If both bits are 1, the corresponding bit in the result is 1 and 0 otherwise.

Bitwise OR (|)

When we use the bitwise OR operator, the bit in the first operand is ORed with the corresponding bit in the second operand. If one or both bits are 1, the corresponding bit in the result is 1 and 0 otherwise.

Bitwise XOR (^)

Page 11: nriit.ac.in mid-2018.docx  · Web viewThe process of organizing complete information about the program is called documentation of program

NRI Institute of Technology: GunturC-Programming Mid-1 Questions

When we use the bitwise XOR operator, the bit in the first operand is XORed with the corresponding bit in the second operand. If both bits are different, the corresponding bit in the result is 1 and 0 otherwise. The truth table operator is shown below:

A B A^B0 0 00 1 11 0 11 1 0

Bitwise NOT / Complement(~)

One’s complement operator (Bitwise NOT) is used to convert each 1 to 0 and 0 to 1, in the given binary pattern. It is a unary operator i.e. it takes only one operand.

Shift operators

C supports two bitwise shift operators. They are shift-left (<<) and shift-right (>>).

These operations are simple and are responsible for shifting bits either to left or to the right.

The syntax for shift operation can be given as:

operand operator num

where the bits in operand are shifted left or right depending on the operator (<<, >>) by the number of places denoted by num.

Left shift operator

When we apply left-shift, every bit in x is shifted to left by one place. So, the MSB (Most Significant Bit) of x is lost, the LSB (Least Significant Bit) of x is set to 0.

Left-shift is equals to multiplication by 2.

Right shift operator

When we apply right-shift, every bit in x is shifted to right by one place. So, the LSB (Least Significant Bit) of x is lost, the MSB (Most Significant Bit) of x is set to 0. Let us consider int x=4;

Right-shift is equals to division by 2.

Page 12: nriit.ac.in mid-2018.docx  · Web viewThe process of organizing complete information about the program is called documentation of program

NRI Institute of Technology: GunturC-Programming Mid-1 Questions

Operator Meaning Example Result

& bitwise AND 4&2 0

| bitwise OR 4|2 6

^ bitwise X-OR 4^2 6

~ bitwise NOT ~4 -5

<< shift left 4<<1 8

>> shift right 4>>1 2

(b) Explain different arithmetic operators available in c language with Example?Arithmetic operators

These are used to perform mathematical operations.

These are binary operators since they operate on two operands at a time.

They can be applied to any integers, floating-point number or characters.

C supports 5 arithmetic operators. They are +, -, *, /, %.

The modulo (%) operator can only be applied to integer operands and cannot be used on float or double values. The table shows the arithmetic operators, their syntax, and usage in C language.

Operation

Operato

r Syntax Statement Result

Addition + a+b result=a+b 12

Subtraction - a-b result=a-b 6

Multiply * a*b result=a*b 27

Divide / a/b result=a/b 3

Modulo % a%b result=a%b 0

7. (a) What is the difference between assignment and equality operation?Assignment operator (=)8.In C, the assignment operator (=) is responsible for assigning values to variables. When equal sign is encountered in an expression, the compiler processes the statement on the right side of the sign and assigns the result to variable on the left side. For example,

int x;9.x=10;

Page 13: nriit.ac.in mid-2018.docx  · Web viewThe process of organizing complete information about the program is called documentation of program

NRI Institute of Technology: GunturC-Programming Mid-1 Questions

Assigns the value 10 to variable x.

Comparison operator (==)10.In C, the Comparison operator (==) is responsible to compare two values. When comparison sign is encountered in an expression, the compiler compare the value on the right side of the sign with the value on the left side and it return either 0(zero) or 1(non zero) as result. For example,

int x=20;11.x==10 compare the value of x with 10 and returns 0 as result since the left side value (x value) is not equal to right side value (10).

(b) List and explain the execution of Short-Circuit operators in C programming.

Short-circuit operation mean that if the outcome of the expression can be determined by the left operand only then the right operand won't be evaluated.In C-Language there two short-circuit operators. They are1. Logical AND (&&)2. Logical OR (||)

Logical AND (&&): In logical AND operation if first (left) operand is ‘False’ then the result of total expression is ‘False’ and no need to evaluate the second (right) operand.

suppose we have an expression as 'operand1 && operand2' and 'operand1' is evaluated to be 'false', then there is no point evaluating the right operand 'operand2' as irrespective of whether that operand is 'true' or 'false' the expression will always be 'false' only.Ex: (10>20) &&(10<20) here the first expression is ‘false’ so the result of total expression is

‘false’ and no need to evaluate the second expression.Logical OR (||): In logical OR operation if first (left) operand is ‘True’ then the result of total expression is ‘True’ and no need to evaluate the second (right) operand.

suppose we have an expression as 'operand1 || operand2' and 'operand1' is evaluated to be 'treu', then there is no point evaluating the right operand 'operand2' as irrespective of whether that operand is 'true' or 'false' the expression will always be 'true' only.Ex: (10<20) ||(10>20) here the first expression is ‘true’ so the result of total expression is

‘true’ and no need to evaluate the second expression.

[UNIT-III]9. (a) Explain various iterative statements available in C language with examples.

The control statements which are used to repeat an instruction or set of instructions a number of times are called iterative statements are loops.The list of iterative statements supported by C-Language are1. While2. Do while3. For

The While Loop:

Page 14: nriit.ac.in mid-2018.docx  · Web viewThe process of organizing complete information about the program is called documentation of program

NRI Institute of Technology: GunturC-Programming Mid-1 Questions

The while loop is a pre-test or entry-controlled loop. It uses test expression to control the loop. The while loop evaluates (checking) the test expression before every iteration of the loop, so it can execute zero times if the condition is initially false. The body of the loop will be executed repeatedly till the value of test expression becomes false (0). The initialization of a loop control variable is generally done before the loop separately. syntax: while (test expression)

{body of the loop;

}statement-x (Statement just below the while loop);

Flowchart

Ex:

i=1;while (i<=n){

fact = fact*i;i++;

}

Do-while loop:Do-while loop is a post-test or exit-controlled loop.

do-while loop is similar to while loop, however there is one basic difference between them. do-while runs at least once even if the test condition is false at first time. Syntax of do while loop is:

do{

body of the loop;}

Page 15: nriit.ac.in mid-2018.docx  · Web viewThe process of organizing complete information about the program is called documentation of program

NRI Institute of Technology: GunturC-Programming Mid-1 Questions

while (expression);statement -x;

Flow chart

Ex:i=1;

do{

fact = fact*i;i++;

}While(i<=n);For Loop:

for loop is a pre-test or entry-controlled loop.

It most general looping construct in C. The for loop is commonly used when the number of iterations are exactly known. The syntax of a for loop is

for(initialization; test expression; increment /decrement/ update)

{

body of the loop;

}

Page 16: nriit.ac.in mid-2018.docx  · Web viewThe process of organizing complete information about the program is called documentation of program

NRI Institute of Technology: GunturC-Programming Mid-1 Questions

Ex: for (i=1;i<=n;i++){

fact = fact*i;}

(b) Explain various selection statements available in C language with examples.

Selection/ Branching statements (also called Decision making statements), Branching is deciding what actions to take.The list of selection statements available in C-Language1. Conditional operator statement2. If statement3. Switch statement

If Statement:This is a powerful decision-making statement and is used to control the flow of execution of statements. It is basically a two-way decision statement. In C-language we have different forms of if statements. They area. Simple if - two-way decision statementb. If-else - two-way decision statementc. Nested if-else - Multy-way decision statementd. Else-if ladder - Multy-way decision statement

The simple if:

It is basically a two-way decision statement and is used in conjunction with an expression. It takes the following form:

Syntax:

if(test expression ){

statement-block;}statement - x;

Page 17: nriit.ac.in mid-2018.docx  · Web viewThe process of organizing complete information about the program is called documentation of program

NRI Institute of Technology: GunturC-Programming Mid-1 Questions

Flow Chart:

Ex: if(num>0)

printf(“%d is a positive number\n”, num);}

The if..else statement

The if..else statement is an extension of the simple if statement. The general form is:

Syntax:if(test expression ){

statement block - 1;}else{

statement block - 2;}statement-x;

Flowchart:

Page 18: nriit.ac.in mid-2018.docx  · Web viewThe process of organizing complete information about the program is called documentation of program

NRI Institute of Technology: GunturC-Programming Mid-1 Questions

Ex: if(num%2==0){

printf("%d is even number\n",num);}Else{

printf("%d is odd number\n",num);}

The switch statement

A switch statement is also a multi-way decision making statement that is a simplified version of if..else..if block that evaluates a single variable. The syntax of switch statement is:

switch(variable){

case constant 1:statements;break;

case constant 2:statements;break;

case constant N:statements;break;

default:default statement;

}Flow chart:

Page 19: nriit.ac.in mid-2018.docx  · Web viewThe process of organizing complete information about the program is called documentation of program

NRI Institute of Technology: GunturC-Programming Mid-1 Questions

Ex:printf("1.Addition\n2.Subtraction\n3.Multiplication\n4.Division\n");printf("Enter your choice(1..4):");scanf("%d",&choice);printf("Enter a,b values:");scanf("%d%d",&a,&b);switch(choice){

case 1:printf("%d+%d=%d\n",a,b,a+b);break;

case 2:printf("%d-%d=%d\n",a,b,a-b);break;

case 3:printf("%d*%d=%d\n",a,b,a*b);break;

case 4:printf("%d/%d=%d\n",a,b,a/b);break;

default:printf("Invalid choice....!");

}Conditional operator statement:It is basically a two-way decision statement. It simulate the functionality of if-else statementSyntax:(expression1)?( expression2):(expression1);statement-x;

Page 20: nriit.ac.in mid-2018.docx  · Web viewThe process of organizing complete information about the program is called documentation of program

NRI Institute of Technology: GunturC-Programming Mid-1 Questions

Here the expression1 must me some conditional expression. Expression2 and expression3 are may be statements, variables, constants or expressions.Here if expression1 is true then expression2 will be executed. If expression1 is false then expression3 will be executed.

Flow chart:

Ex: (num%2==0)? printf("%d is even number\n",num):printf("%d is odd number\n",num);