Set A PDF
Set A PDF
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
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 :
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).
return 0;
}
Output
Enter an integer: -7
-7 is odd.
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.
+ (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 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
(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
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 : – –
Operators Description