Mid 2

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 15

RAGHU ENGINEERING COLLEGE

(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

b What is a pointer? Explain declaration, initialization and accessing of a

pointer variable With example.


3 a Explain how to define and initialize a union with suitable examples.
b Write a C program to read, display, add and subtract two complex
numbers using structures
(RECI2402202
wniat- 5

1 Wte a pHognam i C to punt all Mqme lomenm in a

uplakrodavn D aYra urth 5 elementa


Cals1
AXYOy dumantu
aCol aL ala a[3] alu]
5 2715
the
wiq lemat
PrOgYam
#indada <Stdio h
nt main
nt arr 00, n, COuter D
int i )
Print input Hhu umbY o eumenta to be tored m the
SCanf ( Y.d", &n); aray
yrintf v inpu 4h d edumt In the arrayn n)
DYi-0;1<n;i44
printf (oumtnt 7.d:')
Scanf ( ,d",
3 &arr Dil);
priwtt " n The niauu elementa ond im the aray are
for (i-0; 14n; i44) \n

(ounten0

or lj 0; 0<njjtt)
RAGHU EDUCATIONAL SOCIETY
Date

/4 Tnremet +he Coutey Lahun the ALandh valuue u dupktatu "/

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

DaM M nthina o nay


ay oana
o a1ay
Declaation - Optional

ntaL dataty pe aray-hame51zt 1S1zE 3


V
int
vald Cer umuw
Loat
ideni u
Inde Yange> 0 to h-

t auJ L33, 12 y bytu4

o alo1 L alolla] oo]


af i 1
2aJate afa]a a 0La

wt n28] ,2,3, 4,5,tY


a Lo1j aCa al612] a[oJaliL af1l27
1 3 5
%Db 5 LOC7 bD69 Go1 6013 6675

la0 L5
Initializatim o 2D Aray s
ntialiuoti on Can be dlone An two way Compill ime
And run tivme

Compile time Antialadion Thi Can be don


MAng Aignment opetatvd (=S
ad
ho-Uoud
Suwtax datatype arraynameSIzE |SIZE 2 = valu

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),

ttialise and awsoin9


kWw a pM0Mam to duUaru,
D Ard
#indud <stdio h>
int main )

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

kor Cj-0, j<njjt+)


I,
i'd'y t aLiT
SCanf
sOYi0; >m)+t)
1 acueAing
orCj-0 j>h j++)

prtnt +(yd", 1),


R
Pnayan
#incde <stdioh>
Int pim (int);
unctib oclaradabl
iwt main C)

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

AOhile li < h/))


14 (ni-e0
Ttum b;

+
YUum

Dutput 4

The wuMaer H ua pime umber

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

in umovy to hold the


Rusetspoce
inttQut valuue
'a with this nunto
)AssociaBe. thu nam

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

natiali 3ation Pointz


addrev u vouabu to a
ASSigning
Peito. obdt shani
narme
Suntax Pointt vGiabu a vaiabl:
P2a
Naiabus:
ACCeaing Yalues ir
Jh. vaue Vauabls
can be acce sed
tuoo waus
3ha vaiabu *hv6ughits nae (a)
oddrex Jocoien uing Pointyu (=
Jhmough
is useed in
NOTE 3h indivection ope1atov
pointo.ubr
two distinct wys with
When a beint is declaud
Declaatien:
indicaBts hat i a beinto1
Derefouna:- Hee '*indicaty
thu vau at
t h peinto
sha memovy ocation stoed in
to be atcimec
a d d r ê x s valu

int a2 - addved
JGDD654D

256D

ns tlou
o p

ll Snitiaisatien
P *(Ra)ha

h b o pir
# incudu <stdío-h>

intwmain C)av daiar ndhio


int a 5
int P t dacla1ahion phib
2 a ; l intiaizatien
is u n P)
pvint (" Jhu addrexs e a

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;

printf("Memory occupied by Employee variable: %d\n", sizeof(employee);

return 0;

Output:

Memory occupied by Employee variable: 32


4. Write a C program to read, display, add and subtraet two complex numbers using structures.

Ans:

#include stdio.h>

#include<conio.h>

struct.hi

int reall,real2;

int comp1,comp2

arith;

main)

nt a,

printt("Enter the real and imaginary part of first number respectivelyln");

scanf("%d",&arith.real1);

scanf("%d",&arith.comp1);

printf("Enter the real and imaginary part of second number respectively'n");

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)

printf("Subtraction -%d + (%%di)",arith.reall-arith.real2,arith.compl-arith.comp2);

else

printf("Not a valid operation.");


Output:

the real and inaginary part of first


nunbe respective ly
Enter

the real and inaginary part of second nunber


respective ly
Enter
Se
lect the operat ion
Addition .
Subtract ion

18 12i
Addition
-

tine: 9.781 s
19 (Bx13> execut ion
Process returned
Press any key to cont inue.

You might also like