0% found this document useful (0 votes)
260 views6 pages

Set A PDF

The document provides information about various types of operators in C programming language. It defines arithmetic, assignment, relational, logical, conditional/ternary, increment/decrement, bitwise and special operators. For each type of operator, it lists the operators, provides examples of their usage and describes their functions. It also gives examples of algorithms, pseudocode and flowcharts.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
260 views6 pages

Set A PDF

The document provides information about various types of operators in C programming language. It defines arithmetic, assignment, relational, logical, conditional/ternary, increment/decrement, bitwise and special operators. For each type of operator, it lists the operators, provides examples of their usage and describes their functions. It also gives examples of algorithms, pseudocode and flowcharts.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

SET A

14 MARK
QUESTION DESCRIPTION :

Vikram buys an old scooter for Rs. A and spends Rs. B on its repairs. If he sells the scooter for
Rs. C , what is his gain %?
Write a C program to compute the gain %.
Input Format:
The first input is an integer which corresponds to A. The second input is an integer which
corresponds to B. The third input is a float which corresponds to selling price

TEST CASE 1

INPUT

4700
800
5800

OUTPUT

The gain percentage is=5.45

EXPLANATION :

The code requires you to accept 3 integers from the user , which correspond to Cost
Price , Repair Price and Selling Price respectively and then find the gain/profit percentage for
the given input.

FORMULA :

Gain % = (( Selling Price - ( Cost Price + Repair Cost )) / (Cost Price + Repair Cost ) )*100

ALGORITHM :

 Accept 3 integers from the user ( a,b,c )


 Calculate the gain % by using the given formula ( ((c-a-b)*1.0/(a+b))*100 ) ( Multiplying by
1.0 converts it to float ( can be used instead of type casting ) )
 Print the result with the required message

SOLUTION : (Please use this as reference only)


SET A

2 MARKS
What is algorithm?
An algorithm is a procedure or step-by-step instruction for solving a problem. They form the
foundation of writing a program.
For writing any programs, the following has to be known:
• Input
• Tasks to be preformed
• Output expected
Pseudocode
It is an artificial and informal language that helps programmers develop algorithms.
Pseudocode is a "text-based" detail (algorithmic) design tool. The rules of Pseudocode are
reasonably straightforward. All statements showing "dependency" are to be indented. These
include while, do, for, if, switch.
Flowchart
It is a type of diagram that represents an algorithm, workflow or process. The flowchart
shows the steps as boxes of various kinds, and their order by connecting the boxes with

arows
SET A


2. Variable Declaration Rules in C
To Declare any variable in C language you need to follow rules and regulation of C
Language, which is given below;
• Every variable name should start with alphabets or underscore (_).
• No spaces are allowed in variable declaration.
• Except underscore (_) no other special symbol are allowed in the middle
of the variable declaration (not allowed -> roll-no, allowed -> roll_no).
• Maximum length of variable is 8 characters depend on compiler and
operation system.
• Every variable name always should exist in the left hand side of
assignment operator (invalid -> 10=a; valid -> a=10;).
• No keyword should access variable name (int for <- invalid because for
is keyword).

3. Program to Check Even or Odd


#include <stdio.h>
int main() {
int num;
printf("Enter an integer: ");
scanf("%d", &num);

// True if num is perfectly divisible by 2


if(num % 2 == 0)
printf("%d is even.", num);
else
printf("%d is odd.", num);

return 0;
}
Output
Enter an integer: -7
-7 is odd.

4.Difference btw entry and exit control loop


Entry controlled loop is a loop in which the test condition is checked first, and then loop body
will be executed.
Exit controlled loop is a loop in which the loop body is executed first and then the given
condition is checked afterwards. If the test condition is false, loop body will not be executed.

5.Input out put device


Input Devices: Computer related input devices are Keyboard, Mouse, Touchpad, TrackPoint,
Scanner, Microphone, Digital Cameras, Barcode reader, Joystick, Webcam, etc.
Output Devices: Few examples of output devices are Printers, Projector, Plotters, Monitor,
Speakers, Head Phone, etc.
SET A

13 MARKS
1.TYPES OF C OPERATORS:
C language offers many types of operators. They are,
1. Arithmetic operators
2. Assignment operators
3. Relational operators
4. Logical operators
5. Bit wise operators
6. Conditional operators (ternary operators)
7. Increment/decrement operators
8. Special operators

ARITHMETIC OPERATORS IN C:
C Arithmetic operators are used to perform mathematical calculations like addition, subtraction, multiplication,
division and modulus in C programs.

Arithmetic Operators/Operation Example

+ (Addition) A+B

– (Subtraction) A-B

* (multiplication) A*B

/ (Division) A/B

% (Modulus) A%B

ASSIGNMENT OPERATORS IN C:
 In C programs, values for the variables are assigned using assignment operators.
 For example, if the value “10” is to be assigned for the variable “sum”, it can be assigned as “sum = 10;”
 There are 2 categories of assignment operators in C language. They are,
1. Simple assignment operator ( Example: = )
2. Compound assignment operators ( Example: +=, -=, *=, /=, %=, &=, ^= )
Operators Example/Description

sum = 10;
= 10 is assigned to variable sum

sum += 10;
+= This is same as sum = sum + 10

sum -= 10;
-= This is same as sum = sum – 10

sum *= 10;
*= This is same as sum = sum * 10

sum /= 10;
/= This is same as sum = sum / 10
SET A

sum %= 10;
%= This is same as sum = sum % 10

sum&=10;
&= This is same as sum = sum & 10

sum ^= 10;
^= This is same as sum = sum ^ 10

RELATIONAL OPERATORS IN C:
Relational operators are used to find the relation between two variables. i.e. to compare the values of two
variables in a C program.

Operators Example/Description

> x > y (x is greater than y)

< x < y (x is less than y)

>= x >= y (x is greater than or equal to y)

<= x <= y (x is less than or equal to y)

== x == y (x is equal to y)

!= x != y (x is not equal to y)

LOGICAL OPERATORS IN C:
 These operators are used to perform logical operations on the given expressions.
 There are 3 logical operators in C language. They are, logical AND (&&), logical OR (||) and logical NOT
(!).
Operators Example/Description

&& (logical (x>5)&&(y<5)


AND) It returns true when both conditions are true

(x>=10)||(y>=10)
|| (logical OR) It returns true when at-least one of the condition is true

!((x>5)&&(y<5))
It reverses the state of the operand “((x>5) && (y<5))”
! (logical NOT) If “((x>5) && (y<5))” is true, logical NOT operator makes it false
SET A

CONDITIONAL OR TERNARY OPERATORS IN C:


 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.
Syntax : (Condition? true_value: false_value);
Example : (A > 100 ? 0 : 1);
 In above example, if A is greater than 100, 0 is returned else 1 is returned. This is equal to if else
conditional statements.

Increment/decrement Operators
 Increment operators are used to increase the value of the variable by one and decrement operators are used
to decrease the value of the variable by one in C programs.
 Example:
Increment operator : ++
 Decrement operator : – –

BIT WISE OPERATORS IN C:


 These operators are used to perform bit operations. Decimal values are converted into binary values which
are the sequence of bits and bit wise operators work on these bits.
 Bit wise operators in C language are & (bitwise AND), | (bitwise OR), ~ (bitwise NOT), ^ (XOR), << (left
shift) and >> (right shift).
SPECIAL OPERATORS IN C:
Below are some of the special operators that the C programming language offers.

Operators Description

This is used to get the address of the variable.

& Example : &a will give address of a.

This is used as pointer to a variable.

* Example : * a where, * is pointer to the variable a.

This gives the size of the variable.

Sizeof () Example : size of (char) will give us 1.

You might also like