Professional Documents
Culture Documents
Mid 2
Mid 2
Mid 2
(Common for CSE, CSC, CSD, CSM & CSO) Date: 24-0
Mid-2 Exam: B.Tech I Year I Sem
Time: 90 min Max. Mar
Subject: PPSC
CO PO PSO
Answer the following questions. 3 3 2
in an array?
1 a Write a program in c to print all unique elements
3
dimensional array with suitable
b Explain how to declare and initialize a two
examples.
2 a Build a C program to check whether the given number is prime or not
using function. 4
(ounten0
or lj 0; 0<njjtt)
RAGHU EDUCATIONAL SOCIETY
Date
av DiJ-an Ll)
Counter-t+}
CLentey 0)
printf"d ", an
);
reknrn 0j
Output
npudb he number dheemvU o be torecl in he aray ID
3npt 10 damon in +he aYYA y
emet 0:1
omeet-1/
ment :
Negent - 3.3
Lment : 3
Qument - 6:
Aemet :1
Aument1:
Amevt 3:5
ement9:6
The wniqe gAement und n the ayruy ane 45
RAGHU EDUCATIONAL SOCIETY
ADw
2DArays
AW wvna h 2 Aubauupty kunmud as 1b
D ama
auya one MALd m a Atmatipn
V awu whow A kablu of
hed to lat ud n an awlay
AuinLd m the Aame Jashien h Com b
m in D
b Ara upt
Apenatu paù L Array upt
D
Muquud \n tauh wbAuipt
U1an wN
Atud n a now- Coumn
ndU mdi catu +he maiL ,
Colum 1ou and ight induta *e
la0 L5
Initializatim o 2D Aray s
ntialiuoti on Can be dlone An two way Compill ime
And run tivme
example Vallen
int ala]H 10,20, d0,40, 50, 60, 70, 80
1 0 20 30 40
50 6D 10
t
al7La 1a,3, y,5,4
int
a3]u] =f i,2) 3, 43 ,
L Et=E
5,t,7,8
9,10, 1,13r
Run timu intialin ation-
t can be done by
aing ACAn f ) A bw
int ao SIzEJ [ol-Siz
int [ 5] D5T;
1-0 i<5,)+)
or (-0,)L5,jt )
6CAn4[Y.d", 4 a LiJI)
ACCessinq 2D Aays
t Can he done ming puntf¬) aM follrud
M5
pnnt("7.d", alo]U);
o/p
pnntt ( %d', alJ13JJ,
o/p
)or (i20; is5;it1)
Fo (-0, J <5,jt
prnk d ' , a[iJ aJ),
ivt auJ31,n,i,j)m
pnntf (" enter row s1e")
SConf (". d", 4 m)
Pmnef[" onter coumn size")
SCanf(d", tn)
or1-0 i4m;it) e /vitialatav
pin Eox a
nuumber,
SEaM+[y6", An
ag pine (n); 1 unkipn eall
i (Haq- 1)
Pni'nttThe umWaer .d u a prim Nulcor n' n);
pintt"The uvoer Y.d v a pi unaar In", n)
YUunnD
RAGHU FnucoTIO
unctin detintion
int prime int n
+
YUum
Dutput 4
Dutpur )
do a rwwbey 18
he mber 13 not a pime umber
PoINTERS
vauiabu which is used to
x Fointou is a
vauabu.
the addveseanothui
afoe
vouabu,
duclare'a it
Fo 9 SF yeu
Cempiw thva hings tbwb
int a2 y n ) do Voruabl. nam
vaue
6540 addres
Jecatien. ir
) Stove ha valut ot this oatien
oi viae
Declorafion Poindtn Pointu vaniablu
Sgntax0atatybe *Vouabu name,
"vau at addver
opetaten (1) indivc
opeta
int *P
Sb Stovesinttguy
vauus ony.
vauuts co
+eat P, SF 8toves a t
cha *C, S t Stores chatactou ony
int a2 - addved
JGDD654D
256D
ns tlou
o p
ll Snitiaisatien
P *(Ra)ha
h b o pir
# incudu <stdío-h>
rintf (h addvevs a i s u Ba
pvintf CTha valu a ts d n
p)
Prvint(Iha vabuu c a is 7d m' a,
3. Explain how to define and initialize a union with suitable examples?
Ans: Union can be defined as a user-defined data type which is a collection ofdifferent variables
of different data types in the same memory location. The union can also be defined as many
members, but only one member can contain a value at a particular point in time.
Union is a user-defined data type, but unlike structures, they share the same memory location.
When we define the union, then we found that union is defined in the same way as the structure
is defined but the difference is that union keyword is used for defining the union data type,
whereas the struct keyword is used for defining the structure. The union contains the data
members, i.e., 'a' and b, when we check the addresses of both the variables then we found that
both have the same addresses. It means that the union members share the same memory location.
Example:
#include <stdio.h>
union Employee{
char name|32]:
int age
float salary;
int main){
union Employee employee;
return 0;
Output:
Ans:
#include stdio.h>
#include<conio.h>
struct.hi
int reall,real2;
int comp1,comp2
arith;
main)
nt a,
scanf("%d",&arith.real1);
scanf("%d",&arith.comp1);
scanf(od",&arith.real2);
scanf("od",&arith.comp2);
printf("Select the operation'nl. Addition'n2. Subtraction n");
scanf("%d",&a);
if(a=1)
printf("Addition -
%d+
odi'",arith.reall +arith.real2,arith.compl+arith.comp2);
clse iffa-2)
else
18 12i
Addition
-
tine: 9.781 s
19 (Bx13> execut ion
Process returned
Press any key to cont inue.