CinOneShotPart1 Invert
CinOneShotPart1 Invert
Part - 1
Flow - 1
1) Basic Printing, \n wali cheez, printing numbers also with + and -.
2) Variables, printing variables, int, float, and +,-,*,/ of integers.
3) Variables naming rules.
4) Comments
5) Taking Input
6) Modulus Operator
7) Float to int, int to float
8) Hierarchy
9) Char and ASCII
Basic program in C
#include<stdio.h>
int main(){
printf(“hello world”);
return 0;
}
How to move in next line?
Example :
printf(“Hello PW”);
printf(“Hello CW”);
Output will be :
Hello PWHello CW
Example :
printf(“Hello PW”);
printf(“\n”);
printf(“Hello CW”);
Output will be :
Hello PW
Hello CW
f
•
n n
main(){ •
printf("nn\n\nnn\n"); • n n
printf("nn/n/nnn/n");
• nn / n / /
nnn n
} # in .ua , . n,
.
int main C) {
return 0
;
3
Variables and their Declaration
Let us focus on int data type as of now. Variables Literals
1) Variables as containers : t
'
In
'
my
'
< station >
'
# include %d
printfl "n
"
int main / I );
4
" text
"
Hello )
printf ( ;
pnintfl "%d
"
intro ; - ,n );
n =3;
n = 5;
printfl "%d
"
w
,n )
I
int x = 5; n=S ;
5713-7
printf(“%d”,x); -
x = 7;
printf(“%d”,x);
x = x + 6;
printf(“%d”,x);
x = x - 20; → n = 13-20
-7
printf(“%d”,x); n =
+
int x = 5;
-
% d int
int y = 2; →
2f§-
printf(“%d”,x+y);
5/2 = 2
printf(“%d”,x-y);
printf(“%d”,x*y); int n = 4
;
n
int 2
printf(“%d”,x/y); y =
;
w
int z =
n+y ;
y
u
:
5/2 2.5
;]
→
int n = 512
5/2 → 2
float y = 2; 512 2
→
integer →
printf(“%f”,x+y); → 7
float 2 =
5/2 ;
printf(“%f”,x-y); 3
float 2 = 2 ;
printf(“%f”,x*y); 10
5.0/2 → 2^5
printf(“%f”,x/y); 2. 5
512.0 → 2.5
float n
;
5
n=
; n
V
4-311-83
=
/3
* * *
✓ = 4 3.14 r
*
r r
int r = 5
±
4*3.14*5 /
*
s 5 3
float v =
ttw / c. w WAP to
display area
of circle with given
-
. .
radius .
4 where
t.IN
.
Print percentage of Subjects marks are out of 40 .
Example : Calculating Area of a Circle Flow .
float pi = 3.1415;
int n int y int z
printf(“%f”,area); int a
float Macbook ;
int Mac
;
1524601¥ 3% 30-4
t = 2;
=
si = (p*r*t)/100;
printf(“%f”,si);
int x;
printf(”Enter a number\n”);
int y = x*x;
Run
10
circle 314 IS
The area
of is :
-
y
DryRu pitta
f
radius
µ The area
of circle is : 314.1s
pi area
Output :
Enter Rate : 20
Enter Time : 3
60
simple interest is :
Your
"
scanfl "%d ,
& a)
③ ④
principal rate time Si
El y
4ns address of n
int
scan
n
;
fl "%d
"
,
en ) ;
µ
int x; by output
[
printf(”Enter first number\n”); "" " ""
int y;
printf(”Enter second number\n”);
scanf(“%d”,&y); // user will give ‘y’ a value.
int sum = x+y;
printf(”sum of the numbers that you gave is %d”,sum);
au
sum
Taking Input
Output
③ & ""
¥
"""
Predict the output :
"
30 40
main(){ 2
p 30 40
q=
=
int p,q;
printf("Enter values of p and q");
scanf(" %d %d ",&p,&q);
printf ("p = %d q =%d", p, q);
}
'
Run
'
Dry
Example : Take two integers input, a and b : a>b, and find the
remainder when a is divided by b. & print the remainder .
main C) E
int a
,
b
;
1st No
"
)
713% 7×5+4 39
pnintfl Enter
" =
3⑧
.
;
"
f ( % d & a) ;
"
scan ,
" "
& b) i int a = 39 ;
scant ( Yod ,
int b = 7;
int
q % ;
=
int
q = a / b;
Hq = 5
int r = a -
( b*q ) ;
8 = a -
( bxql
0b¥ :
+
,
-
,
/ ,
*
%
3- = 0
%
MMr→
38%8=6
r= a % b
a=2 ;
b = 6;
y
813T
]
[
3%
2
2 % n = 2 n >
www.tab-a [a <
b)
float to int and int to float :
1, 2, 3, 4, 5, 6
13.14" 0.14
C2 ]= =
=
is line No.
float a;
out
W
-
I
scant ("%of", On); 07
int
;
y
=
ch;
W
floats-as;
a
float bint W
z
Homework:
-
Code it yourself
~
B,0,01M, Als
int i = 2 * 3 / 4 + 4 / 4 + 8 - 2 + 5 / 8 ;
A
printf(“%d”,i);
I' s I a
MATHS
12 43) 1x 619: 1
= >
PROG
=
(2x33K =
619= 105
*
<2 3) 1= 614 = 2
2x131) =
2 x 0.73= 1.5
1 1
=
+ 1 +8-2 + 0 =
8
⑧
Try This!
I
W
West
int main(){
No
too.
- int i = 2, j = 3, k, l;
2 o.000000
float a, b; a
k =*
aO 1
i /213)
j * j ; 30*3 =
=
O
⑧ l = Cj
⑧ / iI * i; B/2) *2=
=
12 = 2
28 O
a = (i / jS * j ; (213) 3= 0
*
3 = O
db = Cj / i I * i; = 2
0.000
printf("%d %d %f %f", k, l, a, b);
-
}
Mea
↑
&
A
I
Groc
a 5.000000
o
=
int main(){
float a = 5, b = 2;
W
a
int c;
2X
c = a % b;
printf("%d", c);
}
out =>
+, -, *, 1,%
float ++, -, ,
C finteger
-> % a real number/decimal
char ch = ‘a’;
- variable d
lot
⑭ dod -> a
format specifies
An
charch= '#'
char a=
'a";
->
*
65 ⑳
az # - 33
B b 98 ! 33
S
-> 6 f = -
c -> 67 c = 99 f f
- 68
* ·
d = 100
E-69 -
F
- 7O
G + 7 I 2 = 12] ⑧ - OU
* - 42
= 90 I
z
-
3 36
*
Else
MCQ Time !
MCQ 1
character ->
single digit
a b"It'
charch='a+;
Which of the following is NOT a character constant
(1) ‘Thank You’ WRONG
-
(4) All the above
MCQ 2
In (b = 6.6 / a + 2 * n ;Iwhich operation will be performed first?
(1) 6.6 / a
-
(2) a + 2
(3) 2 * n
(4) Depends upon compiler
MCQ 3
Which of the following statements is false
-
(1) Each new C instruction has to be written on a separate line
int n = 4;
22 = 1 + 7 ;
MCQ 4
IfO
a is an integer variable, a = 5 / 2 ; will return a value
(1) 2.5
(2) 3
int
a =
5/2;
-
(3) 2
(4) 0
MCQ 5 O,DM AS
3
(2) 6.28
2 122 5.14 *3/S
-
(4) 0 ⑧*3/S
8 IS
MCQ 6
int
↑
The expression, a = 30 * 1000 + 2768 ; evaluates to
-
(1) 32768 30000 + 2768
(3) 113040
-
3276 8
G
2 2102
=
Types
*
1824 > 64
-
Chhote dabba
But vs Short
=
r
iut z = 3,
d
float y =
3.M;
Charch: 'Al
-
mom
3ES7, 8 to
long n =
32768; 8 Bits-I byte
bits 2"numbers
long long n -
z =
b R6 Mb Gb Th d
I6
v a v 2 = 85536
1000 1000 1000 1000
+32 bits
int data type -><
bytes
->
232 numbers
d
long> 8 bytes -> 64 bits
23" numbers
MCQ 7
*
BODMAS ->% I, +,
-
(2) 6 2% 8= 2
2
W
(3) 4 2T5
I
(4) None of the above 8 TE I
2 0-8 = 208 = 2
MCQ 8
What will be the value of d if d is a float after the operation
d = 2 / 7.0?
float d =
217.0 j
(1) 0
stressin
(2) 0.2857
4 O
3
o
u