0% found this document useful (0 votes)
1K views

C Programming Past Updated - 2080

1. The document is a past exam paper for Computer Programming from Tribhuvan University Institute of Engineering. It contains 10 questions testing concepts in C and Fortran programming. 2. The questions cover topics such as the differences between system and application software, constants and variables in C, arrays, strings, functions, pointers, structures, file handling, loops, and recursion. 3. Students are required to write programs to demonstrate their understanding of concepts like sorting strings, calculating series, finding frequency in arrays, transposing matrices, and checking for palindromes. They are also asked to explain concepts in detail with examples.

Uploaded by

abhi1361yadav
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1K views

C Programming Past Updated - 2080

1. The document is a past exam paper for Computer Programming from Tribhuvan University Institute of Engineering. It contains 10 questions testing concepts in C and Fortran programming. 2. The questions cover topics such as the differences between system and application software, constants and variables in C, arrays, strings, functions, pointers, structures, file handling, loops, and recursion. 3. Students are required to write programs to demonstrate their understanding of concepts like sorting strings, calculating series, finding frequency in arrays, transposing matrices, and checking for palindromes. They are also asked to explain concepts in detail with examples.

Uploaded by

abhi1361yadav
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 32

TRIIIHUVAN l-iNIVEi{strY r Exam"

i -.--- -

TNSTITLITE OF ENGINEERING ii' Level BE, Full Marks 80

Examination Control Division i r"rg.u**" #lu,il;"ot BAR Pass Marks 32


i-
2080 Baishakh iYear/Part Ii I Time 3 hrs.

Sub.ject: - Cornputer Programming (cT 401)


{ Candidates are required to give their ansrvers in their orvn rvords aF*q
,/ ,llterupt 4ll questions.
/ '[he
Jigures in the margin inclicate {uil M!!!kg NCH
'/ A.ssume suitable data if necessary) L[MRARY
1. a) How is an application softrvare dilferent lrom s-vsteni soflt.,vare? F.xpiain r.vith
crantples. i4l
b) F{ow is code in sollrce file is converted to the executatrie hle? Explain with key steps
irvolved, t4l
2. a) liow is constant different than a variable? r11
LLI

b) \\irite a C program to read an integer 'd' fiom the user. If 'd' is the radius of, a circular
ground in meters. then this progranl should calculate and dispiay the area of'the circle
in sqrmre meter. 16]

3. \\rhat are formatted inputi olltpllt liii-iciions'l Erplain each tn cletaii "'r'ith exarnples. {2*41
1,. a) Diflerenriate betr,veen libralr iirnction anci itser deirneci fimctions. i'rovide relel'ant
examples. l3l
b) \\ihat is a function prototype'? Write a C program to find sum of, first 10 natural
numbers using recursion. Ii
-'-41

-5. a) Write a prograrn to read marks of zl8 students iti a class and dispiity the second highcst
niark. i5l
b) l-[ow can we copy one string to another string without using any string handling
function? l5l
5. What do you rnean by arral' of structure? Write a prograr'l) to oreate a stfucture named
"Student" having members Roll" Name, Address and N4ai'ks. l,Ise this stlucture to read the
information of 48 students in a ciass and ciisplay the inforrr-ratioli of, only those studertts
ivhose marks is between 50 and 70. [2-8]
i " What are pointer arithmetic'/ Explain rvith erample. Write a C program that uses poirtter
to reattr mxn matrix flr'lm user. Pass itto function that ttncls tlie transpose of the matrix. Ia-tul]
8. a) LJow is a binary llle different than a text file? Write the s.t'ntax anci itse of fseek 0 and
rewind0 fr.inctions in C. 12*21
b) Write a C program to read the name, year_of release, and langr-iage of i movies. Sa,.'e
lhe movie daLa of ali 'ilngli.sh' langi:age rnovies in a clata fiie. i4]
9. What is the use of FORMA-[' statement? Explain I and F lorrnat r,'u'ith example. Write a
program in FORTRAN to read a number fi'om user and check u,irether it is a prime
number or not. [4r-4]
10. Vv/rite shoft notes on: [2x3]
a) While and do-lvhile stateinent
b) String manipulation in Cl.
TRIBHWAN LTNIVERSITY Exam. lltgular
INSTITUTE OF ENGINEERING Level BE lFulllta_rfts if-p" ..
BAsl
Examination Control Division Programm. , flfi*t Pass Marl*

2079 Bhadra vJaiira* I/I Time ,3hrs.

Candidates are required to give their answers in their own words


Attempt Atl questions.
Thefigures in the margin irudicate Fu$ Marks.
Assume suitable data if necessary.
I
t. a) Differentiate between system software and application software. Provide relevant
examples for each of them. t4l
b) List the steps involved in solving a problem using a computer. Why do we need an
algorithm before writing program code? 12+21
a) nlflne tgkens in C programming language. How are variables declared as constant?
Explain with examPle. l2+2)
b) Write the output of the tbllowing: t6l
# include < stdio.h >
int main ( )
t :
char shl [50], str2 [50] { N' ,'E' , 'P' ,'A' , 'L' } I

scanf (
uohlA-Zi,'', strl ;
)
printf ("%s\n" , strl);
printf ('% 0.5 s\n" , str2) ;
printf ("% 5.3 s\n" , sff2) ;
printf ("% -0.3 s" , str2) ;
return 0;
)
Input string: KATHmanDU
a progmm
a
How are break and continue statements used to jump out from the loop? Write
to evaluatethe following series until the term value becomes less than

ro{:cos(x)-1-*.*-f;+* t4+61

4. a)
--/ Write a syntor offuo"iion-declaration, function definition and function call in C
progr**ring. Can a main function be called recursively in C? Justiff your opinion. t3i1]
b) hxpiain the use of recursive fi.rnction with a suitable example. t4l
5. ;i Differentiate between array and string. Explain
how to declare and use multi
dimensional arrays in C. [3+2]
to read a string &om the user. Pass the string to a function and sort
b)' Write a C program
-in
the alphabets descending ordei. For example, if the user entered "exam" then the
-wfrit should display "xriea".
;;"d" pointer ^ ,- p a fi'rnction in t5l
Define
6. ,l in
is the meuning'of data type used declaration?
your program to r*u! trro integers using pass by ryfe1ence. [1+3]
of a number in array. Explain the relation of
-' Write u progru111 to iind the frequency
b)
pointer*alrtuyusingthisprogram. t4l

write the purpose and syntax of fopen () and fclose- Otrnction. wAP to create
,7 a structure
&om user write it to a file
book with its-member r"u*" price and author. Read 10 records
named ,,book.dat". Read information from book'dat file, search author ftlme
"Gotterfried". If foun&copy the records to a file "gotterfried'dat"
[3+7]
program in FORTRAN to check
8. What are the data types availabie in FORTRAN? Write a
u rr,r*b", is palindiorne or not. [3+5]
9. Write short notes on: lZxal
a) Associativity in C
b) Entry and exit control looP
TRIBHUVAN UNIVERSITY Exam.
INSTITUTE OF ENGTNEERING Leve! BE Futl Marks 80

Examination Control Division Programme ALL except BAR i Pass [iarks : 32


" -"--"----"*-----
2078 Bhadra Yerr / Part lli iTlrne l.!r:, ,

{"!i9cl.*-QggsglS:p11glggltqlg$ail
Canditlates are required to give their ansrners in their own words as far as practicable.
t e m;tt
At 4l! que sl ions.
T'ke Jigures in the rnar4in indicate fuU Mqr&:.
Assume suitable dala d'necessary.

t. a) Whar is a program? Explain different types of prograrrxning language in brief. [1+-:1


b,) \\tiat is an algorithrn? Explain hcirv does algorith;n and florr,'chafi hslps in computer
programming. li+3j
2. a) Explain Ternary operatot in C rvith an example. IJefine following terms. l2+2]
(i) Preprocessor directives (ii) Keyworcis
bi Write the output of the follovring C program. t4l
int a,b;
. double c: 123.55667788
char str[] = "I enjoy programming":
scanf(" %3do/ozd" ^ &a, &b);
printf("a : %5m b:Yo-7d",a,b);
printf("\noA 1 0.7s ",str);
printf(" \n1loC. 3 f ',c) ;
printf("\nozi,- I 0.6f ',c) ;

inpui:123456 789
3. Write the diiference betrveen fcrraatted t10 and unfbrmatted I/O functions in
C-prograrnming. Write the syntax for following functions. [2+4)
(i) getche$ (ii) getchar$ (iii) scanffl
4. a) What do you mean by iteration? Explain lhe operation of break and continue
statement with a suitable example. [1+3]
b) Write a C program to check whether an entered word is a palindrome or npt without
using library function. t6l
5. a) What do you mean by a function header? Explain the function parameters and its
types. [l+3]
b) Write a C program to calculate the sum of cigits of a given number unless the sum
=) 29 =) 1 1 => 2]
becomes a sirrgie digit using recursion. [Hint: 9785 t4l
6. a) What is an array? Why is it necessary in c programming? i1+21
'n) Write a prograin which display fbliowing pattern. l5l
fJ
HE
I{EL
HELL
HEI,I,O
HELL
HEL
I]E
i-i
]' Is tirere any relaticn.hetrveen amay and pointer? If yes, show the relatiln l;etr+,een
ve*Yvw* aray
and pointer wirir a suitabie exarnple. '
8. trtriliat is siruc:r,i|e?
ir*ri
prcgram to reai a structure named ',Faculty,, liaving
a-
!1ite
Name" Adr-l;*ss a-nd ServiceYear as rner.',ber. vy'hr:re
sta{flD,
Serviceyear: is another structure
having Di:rationlnYcar as rne:nber. Ni...; fllsf1r4,v the
service duratian i:- inore than 10 anci Jc;s trrrin i
detaiis of those YYr
lseurlrv' whose
-"vev faculties
1lars, [1+?]
9. a) whv iio we need fiie liandin"r,' s.,rite diffcrent mocies of lile opening.
[1-]-3]
b) Wrat is the puipose of fseek ani u,rite a prrlgraru to write the name,
roll ,o, and age
of fivs students into a disl: file name "S i-itngNt.DAT,,. [S]
l0' Describe X {brrnat and T format in FoRTiviN. Diflerentiate
betrveen unconditionai soto
and compuiec goto in FCRTitr\N. wrire a
irrcgrzur in F'6RTRAN;;;;ffi*.?rt;r,
uua' lrvuiur'Lr 1
ID array in ascending as u,eri as descending o*ier. iz+z+61
Exam. Ilaeli
TRIBHUVAN UNIVERSITY
LeveI BE Full Marks 80
INSTITUTE OF ENGINEERING
Programme Allexc+bt BAF Pass Marks
Examinaticn Control Bivision Year I Part til Time 3 hrs.
20?8 Kartik
ingQT
t|-l !y!i
a01)
^ _ syl*s"r:; Qo,rypi{e1Pl-o-g'3.P*:',-g
ansrvcr: in their o1ln wotds as far
as practir:eb1e '
candiciates are required to 11iYe their
A t t e ; tltt 4U uc s I iotts.
r L1

Mtri'g'
ii,n pguZ in rhe m,argin indicate Full
Assttme suitable data if neussary'

1. a)l)iscusstherecentsoftwaretreirds.Erplainindetailsabcuttirefcaturesthata lir 2]
so{iware shouid lnclr'dc
,t - eirors that m;
--^-- +L^+ ftht occur during
might rlllfln-
b) I-ist ocrt the general ruks for florvcharting. What are the ^.arlr
i?-+,)1
debuggirrg?

2.a)Whatarepre-pfocessordirectives?Explaincornpilationplocesswithsuitableblock Ii-3]
diagrsm.
solving it.? Deflrre tokctrs, expression
b) $,"hy do we need to analyse the prlrblem before il+31
and tdentifiers. rl +?l
3.a)Whalisthecontroistatcment?Writedorvntheclassificatioroiccntrtlista.rements.
[ax 1]
b) Write down ihe syntax of a given functir-tl'
(i) printfQ
(ii) scanfQ
(iii)getcha:0
(iv)gctchl)
1"3 l
4. a) Write lhe output of following program:
int mainQ
(
\
char ch='G';
int g:11t;
float gravitY = 9'81;
Print(" %7od %oou6fl n" ) ;
g);
Printf("%1Od\:",
ch);
Printf("%3c\n",
irintf("%. 3 f\n", gravitY) ;
printf("%-l Ci' 1 fo'6d\n"' gravity' g);
return 0l
) [3xi]
Define and vsrite syntax of the
follcrvrng:
b)
(i) gets0
(ii) Putchar()
(llr)scamt )
ri';ritr: il program to evalu:'te ihe followirrg
5. Why do we nsed locp for programming? [2+41
series' 2 --'t --5
vv-\ -'/
cos(x)= l---*-l' 4! 6:
21
parameter.
6. Wh.v <io 1ve need to declare a function? Del-irre fonnai parameter anci ;rciual
Evaluate foilorn'ing series using recursi'le function' [2+2+4]
1, Ii, l1l. lli !, 1l I il. .'..... nterms

an lri.r"iry of string with an examplr. Drstingu-ish between an array and a


pointer. i2r21
7. a) Deflle
bi Write a C program to inserl an sir.,-iii i0 a desired position to an array using
l"uncticn.
"{
he r-,-c,* element to be i;:s,.:rte.i ;lnd iesired position should be givne by
user. l6l
t?l
8. a) Define a void pcinter rvith an appropriate exampie' L-)

b) Write a C "lrogrant that uses pointerii.. i"(:rpi.stnt twc 2-D array of size of m'n and
pxq resp.esiil.jr,. Find the i-,r.,duct of th,,ri: iwc matrices if possibie otherwise display
u *urrg" "Caiculation cannLri be performi:d" ''tsing function' l6l
g. Discuss about neited structure lviih a suitabl* exr.rnpler. Create a structure called
"student"
id.pass :r'iiitclure to function and sorl the inl-ormation
v,.ith daia member n3.rne. address and
ol st.Lirientrhe basis of aiphabetical oicr:. cf"'name" and display the resuit in mainO
ou
fui:el.iuir 12+6]

l0.illiite a C program to creaie a ncw file,':,r,-rcd'-employee.dat" which consisi the


ilil.*rrrraLion einployees. Er:rpioyee inforr,el:nn includes empName, salary and post"
oi i0
Rrilii ti-,e fiie back to seaich the r*"i;rd "managei'"' [6]
in
ll. iirplain diit-erent forrnat typr.r rrse,J in FOI{|RAN. Mention different data types used
FORTRAI\1. [3+2.i
+*:*
TRIBITUVAN I-TNIVERSITY Exsm"
INSTITUTE OF ENGINEERiNG f,evel BE Full Marks 80
All except BAI
Examination Control Division Programme & EAR.
Pass Marks 32

2076 Chaitra ieaiiPd"t Ur Tirne 3 hrs.

Swbject: * Computer
|Putef Pro ing
tsrogl-axlmmg $r
{c! !u}.
401)

'/ L-andidates are required to give their answers in their own r,vords as far as praeticab:
"/ Atlentpt 4ll questions.
,/ The.fignres in tlte margin indicate Fwll Marks.
./ tlssum.e suitahle data if necessa,'y.

1. What are ctrifTerent types r:f computer software? What do you rnean by high level and low
level programming larrguages'? A long rvitir ttre biock diagrarn explain the steps involved
during compilation of a source code. {2+2+41
2. Explai;r different types of error that usually appears during the prograrnming. Define
preprocessing direetive and explain its type rvith exarrrple. \&rite the aigorithrn and drar,v
the flow-chart to find the reverse of given number. l2+2+41
3. Why are formatted output irnportant in Cl language? Write a program to print all tl:le roots
(liverrr imaginary roots) of quadratic equation. [3+5]
4. Explain the importance of a switch case statement. Cornpare switctt-case witl: if-else
tradd,er. Write a program to tjnd sum of numbers iiorn i to 100 u4iich are exaclh, divisible
by 5 and not by 3. 12+2+41
5. I{ow is function eieclared? !Vh1, is ftrnction prototype necessary? Write rer:itrsive tunction
segment that returns the sum of numbers liom 1 to n given by the user. 12+1+51
6, LIow can you pass one dimensional array to function and what does narne of an array in
finction call represents? Write a program to find the largest and smallest element of an
array using a single fi.inction and display the result in calling function. [3+5]
7. Explain how a structure can be defined and structure variables can be rleclared in C. Write
a program that reads name, roll numbers, program and marks obtained in five subjects by
students until the user enters 'e'and display the student detail and total marks obtained by
each student. [3+5]
8. What is pointer? Discuss its relationship with an axray. Write a funetion pragram that
behaves strcpy$ function using pr:inter as arguement. [1+2+5]
g. Explain different modes in opening file. Write a program to read a string, write it inlo a
flle and display the content of a file into a screen. [4+4]
10. Explain different data types available in FORTRAN. Write a program in FORTRAN to
check whether a number given by user is palindrome or flot. [2+6]
*rk*
,/
,
I
I

I
I TRIBHUVAN UNIVERSITY Exam. Back
INSTITUTE OF ENGINEERING Level BE Full Marks 80
AU (ExsEpt BAR
Examinatidn Control Division Programme and BAS)
Pnrs lVlnrla 32

2076 Ashwin Year / Pnrt tl Tlmo 3 hrs.

pj-o-g_Ig-glm$s_{9"T"!9"!)_
Fy$f r!:;.cggg1pef
{ Candidates are required to give their answers in their own words as far as practicable.
Attempt ALquestions.
Theligures in the margtn indicate Full Marl*.
Assume suitable data if necessarY.

1. a) Define a language processor. Explain the main types of language processor in detail. [2+3]
b) List the basic step of problem solving using computer. Write an algorithm and draw a
flowchart to find the sum of N natural number. [l+4]
a) Define formatted and unformatted I/O functions. Write the operations of following
functions: 12+31

(i) getchQ
(ii) getche0
(iii)getcharQ
b) What is an expression? Write a program to display the smallest number between three
integers entered from user using conditional operator. [l+4J
J. a) Differentiate between while and Do-while looping statement with example. t4l
b) Write a program to evaluate the following series up n term. Prompt the user to input
x.f(x) = l-x2l2l+{/4!-x6/6!+x8/8!-----up to n terms.
value of n and t6l
4. a) What are the different types of functions available in C? What do you mean by pass
byreference andpassby value. t2+31
b) What are the similarities and difference between iteration and recursive function?
Give suitable example. tsI
5. How do you initialize aID away? Explain with an example. Write a program to input two
matrices of size mxn and pxq respectively. Pass these mafiices to the function to calculate
the product matrix. Display the product matix in the main () function. [2+8]
6. a) $/hat is a structure? When do we use structure? 12+21

b) Write a program using pointer to swap the value of two variable where the swapping
firnction.
operation is performed in separate t6I
7. a) Why are fgetsQ, $uts$, fgetc$ and Sutc$ used? t4l
b) Write a prograxn to display the reoord in sorted order, sorting is performed in
ascending order with respect to name using data files eoncept. t6]
8. a) Compare Logical IF and Arithmetic If statement inFORTRAN with example. t4I
b) Write a FORTRAN program to sort 10 integers given from user and display the
second largest integer. t6l
** {.
-

.'1'RIBHUVNNUNIVERSITY

. INSTITUTEOF'ENIGINEERiNG
Progrnmme
Examination Control Division
' }WiChaitra

::- ----*qg;gei-tjry!Etsryeg3s"ris-_-'l --:--=---_-


./ ca,didares r;;;;;;;.
their answers in their own words as far practicable'
as

/ Attentpi Alt ^."


quesfi'ons.
'/ the figures irc the margin indicate
Fu! Morks'
/ Asstune suitabte dcta dnecessary'

What is computer programrning and corirputer softrvare?


Explain about types of
1. d software' ,r*ra
ru' L)
programming tranguages and
b)W.hatdoyounreanbyconrpiler?Explaininbriefthestepsinvolvedduring
[2+4]
compilation p{ocess along with block diagram'
2. a) what is expression? what kind of inforrnation is represented
by expression? l2+2J

function? How is it used rvithin a C program?


-/ Wirat is the purpose of the putchlrr
b)
Co,rpur**itriiu* g.ttr'ar function with example' i6l
structure along rvith flowchart' t4]
3. .1) Coruparenested-if controistmctuLe with else-if ladder
b) write a program to read a number from user, count the number of
even digits
containeel l* ii *nA display w'hether the resulting count is
prime or nct. t6]

4. a) write a prograrn to generate the following outpr-rt. t6]


1714543?. I

'1;i?,
l2i
1'
I
$ function? Explain actual parameter and
b) What. is a funetian? What type is the main
ior,"uip"rometer with [i+1+2]
"*u*fl.. for
5. a) S/rite a progran-! to read one dimensional array of n elements',pass it to a function
element of an
p.o."rtlr*g Io that, the program should display the largest and smallest
'u"uv
rro* the raajn funition- t6]

b) Hoiv can u,e i*itiaiize 2D array of charaoter data type during compilation? Illustrate
with suilable examPle. t1l

6. a) What is a stxueture? Explain nested stuchlle rvith an exarnple. [1+2]


address, salary as its
b) S/rite a pr.ogram to define a structure named P.qrs,T with Name,
rne'rber. Eiter values for five persons. Pdbs the structure to a functi<in
w'hich
increases t1e salary by 15% each. Display the updated information in the main $
tunction. t7j

i!
7. a) Write the output of the follovring.
l6l

a r---l
lro--_J b ii---__l
i .Lr_---t I

address: 655 I 0 adiress: 65550 address:655g0

irrt a=10.*b. *+c;


b=&a;
c=&b;
pri nt("%d\t7od\n ", b, *c) ;
p ri ni f("%d\toZd\n", c, + *c);

pri nt("%d\tolod", +b+5, &c+Z);

b) what do you mean by Generic pointer, Null pointer and File pointer? t4]
8. a) Explain the F-ORTRAN strucfure. what are data rypes in FORTRAN? l2+zi
b) Write a proglam to print the Fibonacci series until the term is less than 500. t6]
{.**
01 :ITRIBHUVANUNIVERSITY l-I-*1g1- -ffi
NSTITUTE OF ENGINEERING i Level I BE IlullMrrlis 80

Ex a min a tio n C ontro I D ivisi o [I*:XFi-J n Ali q.;:4


r-- -------.------*"*--+--"..----
;:1ji]j Pass Marks 32
Time I 3 hrs.

Wi r: t : 9*osPtt}9l-*wr+rr:n a LCf!!9!- - - -
Candidates are required to give theil answers in their own words as far as practicable.
Attempt All questions.
The figures in the margin indicate Full-Marks.
Assume suitable data if necessarY.

1. a) What is computer program? Discuss in brief about different generation of


pro grafilrnin g I anguages. Ii+4]
b) Why is algorithm and flow chart development important in problern solving? Stite an
algorithm and draw flow phart to test a number entered by user whether it is even or
not. 12+31

2. a) What is the identifier? What are the ways to give value to variable? Explain with
example? [1+2+I]
( b) Explain about input and output function available in C with syntax and example of
_i each part. LZ+2+21
a
J. a) Write algorithm, draw flow chart and program to input a number check "it is
f,)r.)rl
I L I L) l
Armstrong or not. LL

b) .What do you mean by selective and repetive statement? Why. dc we need break and
continue statement? 12+21

4. a) What do you mean by "call by value and call by reference"? Explain it with suitable
example L4)

b) Can we pass whole an'ay element from the function? Write the prograrn to pass an
anay to function and sort them. t6]
{ a) Write a program that finds the largest word in a given sentence. t4]
b) Differentiate between the methods of passing argument to function with example.
What are their advantages and disadvantages? t6l
6. What is structure? Why is it necessary? Write a program to add two distances given in
feet and inch fbrrnat using structure. [1+1+6]
7. a) What is null pointer? What will be the output of following program, explain. [1+3]
#include<stdio.h>
int mainfl {
if( ! NIILL )
printf("C pr'ogramming is easy");
. else
printf("C programrning is not easy");
return 0 ;
)
b) Write a program to calculate the length of string without using string handling
function. t4l
o
o. A file name employee,txt stores employee name, employee id and employee salary. Write
aprogram to display the detail of all employees in the order of their salary. t8l
9. Write a program in FORTRAN to read 10 integers fi'om user and short them in ascending
order and display it in screen t6l
*:ri(
</)

\\ I

TRTBHUVAN LTNIVERSITY Exam,


INSTITUTE OF ENGINEERING BE Full Marks
Examination Control Division I:qqllry:- AII (Except B. Arch.) Pass Marks
2074 Ashwin Year / Part i/i**-*_-**-- 3 hrs.

sr9lggLlgrp.gt". Pigerg *i!E


-{gll 0 t)
r' Can'didates'are required to give their answers in their oram words as far as practicable.
{ Aitempt AII questions.

{ Assume suitable data dnecessory.-


1. What are computer programs and computer programming? Explain the steps that are
required to'build a cornputer program for solving a certain pioblem.
12+61
2. Explain with an exarnple the role that precedenci: and associativity play in the execution
of an expression. Rewrite the following program by correcting *y if presenf and
also write down the output of the corrected code. "oorr,
W+41.
Define MN( y
int main { }
{
int case [MAX]=if 3,5, 4,10],i,surn=0;
for(i=O,kMAX,i+=1)
t-
printf(,'Case %d = %3.2d\n',,i,case[iJ);
SUITI *=* CaSe+i;
h
average = surnlMAX;
pri rrtf( " yoo6.2f ', ave rage);
return 1;
)

3- a) Compare if-else-if ladder and switch construct with example and flowchart.
I5l
b) lvrite a program in C to gen€rate following pattern using unformatted input/ouput
functions only.
l5l
N
'vv e
PPP PF
aaaa aa t

X,LLLL LL LL
4' Write.a program in C to find out whether the nrh term of the Fibonacci series is a prime
nu'mber or not. Read the value of n frorn the user and display the result
in the main
function. use separate user-defined f,nctions ro generate
check whether a number is prime or nor.
r#';il,il";;;;; i"#La
,o
tg]
,</ \
t)-J-r'

5- a) How two dimensional arrays are created in C programming? Write a program to read
NxN and find sum of bo& diagonals.
square matrix of size [2+41
6f Write a program in C to check whether a given string is palindrome or not using user
defined function,,,
r'a
I
. ,"., L41
'6. what are the advantages of using pointer in C programming? write a program in C to
find,. second largest elements from an array containing N elements using concept of
pointer. l2+4j
7. Explain structures and nested structures? Create a structure to hold any complex ntrmber
x+iy. Write a program that uses the structure to read two complex numbers and display a
third complex number which is the multiplication ofthe entered complex numbers. [3+5]
8. a) What are different inpuVoutput functions used with data files in C? Explain with
syntax and examples t4l
b) Write a program in C to read integers from usbr until user says "no". After reading the
data write all the odd numbers to a file name odd.brt and all the even number to file
named even.txt.
;i':
t4]
9. When can we use recursive functions? Why do u,e need control statements in computer
programs? Differentiate between do...while and for statements. 12+2+21
characteristics of FORTRAN Programming? Write aprogrcm in FORTRAN
do.Whatut'th"
to calculate the value of n by evaluating &e following formula for the first 25 terms. t8]

n=4(r-i.1-+.;-...)
:t ,F rk
01 TII.IBI.i L]\IAN I] NI V I]R S IT\T Exam.
ii----------,,,-
NSTI'II]I'E O]T ]]NGINEERING Level BE ; Full Marks :80 i

Fixamination Control Divisioll i Programme Ali (Except B. Pass Marks


"7) ...
i

20-T4Chaitra li;;;iP;i:i ,lzt Time


. :.........
.3hrs.
i

Subje-ct: - C,omp_uter Prograrnming (CT1At)


v/ Candidates are required to give their ansu,ers in their own words as far as practicable.
'/ Attentpt Aff questions.
,/ The Jigttres in the ruargin indicate Full Marks.
/ ,4ssrune suitable data if'necessary.

i. a) What is a programming language? What is the difference betv"een source code and
object code. 12+21
b) Wirat is debugging and testing? What are the step that need to be follou,ed for
der.,eloping the application software. l2+Zl
2. a) What is the difference betu,een variable declaration and variable definition? Explain
with example. 14)
b) What do you mean by macro expansion and file inclusion in C? Explain with
example. L4l
3. \\/hat are functions used for forrnatted and unformatted output? Write down its syntax.
Write dou,ll the output of printfl function lor the following sections of statements. l4+41
float a : 5.7891;
int b: 6789;
printf("a:%4f andb:o/o-ld from first line", a,b);
printf("a:oZ-7 .2t andb:%07d fi'om second line", a,b);
print("a=9/0.2f andb:oh2d from thirci line", a,b);
a) Explain about while ioop vr,ith its syntax and flowchat. l4.l
b) Write a program to convefi a decimal number into binary number. 16]
5. a) Can a finction return an alray to the calling function? Explain u,ith example. t1l
b) Write a program to read a mxn matrix of integers and to find the largest eiements of
eacir row. Store the largest elements of the ror,r, in a one-dimensionai aray of rt
integers before displaying them. t6l
6. a) How does a structure differ from an array? What are the different ways to access
structure member? 14]

b) Create a structure named student that has name, r:oii and marks as members. Assume
appropriate types and size of members. Use tiris structure to read and display records
of I0 students. Crete two functions: One is to read information of students and other
to display the information. l6l
l. a) lJefine following tenn: t<t
t.'t
j) int'rp;
ii) int p(char*a)
iii) int(*p(char*a))
iv) int *p(void)
r,) intt(*p[1 0])char a)
b) Write the advantages of using pointer in C- prograrnrning. 13I

8. Write a program to copy to copy content cf one file source.txt to another


destination.txt. [8]
9. a) Expiain the FOR.TRAN structure. What are diflbrent types on FOR'[AN? l2+31
i

05 TRIBHUVAN I.NIVERSITY Exam. r Nei$''Ilac[ f206ri c.Lritcir i ntch) '


" INSTITUTE OF ENGINEERING Level BE Full Marks 80
Examination Control Division Programme ALL (Except B. Arch) Pass Markr 32
2073 Shrawan ' Year / Pant UI Time 3 hrs.

--i"lx-;li:I;se1eriresr" 7%i!:, -._-=-__=-


Candidates are required to give their answers in their own words as far as practicable.
Attempt All questions.
Thefigures in the margin indicate Full Marks.
Assume silitable data if necessary.

l. a) What do you mean by Programming Language? Explain about the evolution of


programming languages. [1+31
b) l{_hat
ar9 the advantages of a Flowchart design? Write down the guidelines to be
followed to draw a flowchart 12+21
2. a) What is the purpose of the semicolon that appears at the end of mosl assignment
statement in C? Explain the program compilation, linking and loading process with
example. 12+41
b) Discuss the types of errors in programming. How do you debug a C-program? [2+4)
3. a) 141
b) Write a C program to display following pattem without using formatted input/output
statements. t4l
Programming
rogrammin
ogramrni
$amm
ram
a

4. a) Why do we need control


,i
statements? Coinpare switch and if-else-if ladder with
exampre. 14l
b) Write a C program to display all characters between a given ranges. l6l
5. a) What are the advantages of using functions? Differentiate between Library functions
and User-dpfined functions with suitable example. t5l
. ..
b) Write a program to check whether a given number is Armstrong number or not using
recursive function. tsl
6. a) Write a C program to read two strings in main and compare thern using userdefined
t4l
b) :What are overflow and,underflow enors in context of anay?,Wnte a progra.in to add
corresponding elements of two arrals:'The results should form a'new arrayi 12+4)
7. a) Why should we prefer structure over array? Explain nested structure with example. 12+4)
b) Write a program to read name ancl roll numbcr of 48 students from user and sto,re
them in file. If fte file already contains data, your program should add new data at the
end of the file. l"6l
8. a) What is the strucrure of FORTRAN progranr? tsl
b.1 Write a FOR IRAN proglam to reacl n numbers and displav largest number among
them, 15l
TRIBHUVAN LTNIVEESITY Exarn.
INSTITUTE OF ENGINEERING Level BE Full Marks 80

Examination Control Division Prograrnure All (Except B.Arch.) Pass Marlcq 32

2073 Chaitra Year / Part Ur Tirne 3 hrs.

S_yhiec| 1 Coml:uter Ppgrapmrng {C,T4at)


Candidates are required to give their answers in their o*tr words as i-ar as practicable"
Attempt All questions.
The figures in {he. margin indicate Fult lfqrl{s.
Assutne suitctble data if necessary.

1. Explain the generations of programming language. Distinguish between High levei and
Low level programming language. [3+3]
2. is an algorithm and how it dift'ers from pseudo-cc,de? Develop algorithm and draw
trItrhat
flowchart to find the largest of N numbers. [2+3+3]
3. a) \\4rat are identifiers? List the rules to define valid C identifiers. [2+3j
b) \\rhat is operator? lJescribe the conditional operator in C with syntax and exarnpie" [2+3]
4. What are the differences betrveen global and local function, variables and data types, &
(Ampersand) operator and * operators used in c-programming language? Explain rn'ith
example. [4+4]
5. a) Differentiate befween pass by value and pass by ref"erence. t3l
b) Explain the significance of user defined firnctions with exarnple. tsl
6. a) Write a program to read a string and check whether it corrsists of Alphabet *r not. Use
user defined function to acconiplish the task. tsI
b) Explain how 2D array is passed to a function. Write a C prograrn to display largest
and srnatrlest elements of a, 2D array. l_si

7. What is nested structure? Write a prograrll in C to read name, age and salery of 10
difibrent ernployees as the three members of a structure named as "employee". Sort this
data in salary basis using user detlned function anC display sorted data from main
function. [2+8]
8. Write a prograrn in C-programming language to colnpute the cosine seies. (hints:
cos(x) : l-x2/2!+xol4r.-*616t.*".............up to n terms) t6-I

9. Write a program to open file named INVENTORY and store in it for maximurn 10000
data of ITEM-NAME, NUMBER, PRICE, QLIANTITY. Extend the program to read this
data from the above given filename and display the inventory table with the value of each
item. t6I
10. a) Cornpare unconditional goto and computed goto in FORTRAN with s,vntax. t3I
b) Write a program in FORTRAN to read an arr&y containing N elements, sort this data
in ascending order and display the result. tsI
rF**
].

TRIBHUVAN T]NIVEF.SITY
INSTITUTE OF ENGINEERING
Bxaminutiot, Control Division
2072 Kartik

as practicable'
Candidates are required to give their answers in their own words as far
Attempt All questions.
The figures in the margin indicate Full Marks
Assume suitable data i"f necessary.

i. a) Explain different generation of programming languages. [4]

b) why do we need analysis and design before coding a program? t4l

What do you mean by precedence and associativity of an operator? Explain with


.|
/ /.. a)
suitable example. t3l

b) What are the differences betrveen formatted and unformatted Input / Output. Give
o l}i,o/o3c,o/o'10.3f and %x' [1.ha]
suitable example with sample output for the foilowing:
What are the purpose of the continue statement? Within which control statements
can
,J. a)
statement'
continue statemelt be included? Compare with the break 11+7+2)

b) Write a pr()gram to find the sum of series Sn = Il / n2 up to N term' I5l

4. What is the meaning of function prototyping? Write a program to calculate the sum of the
series 1+11+1 t l+..I...+,rp to N tirrns uri.rg .""ursive function. If N is read as 5, the
series il

is:1+11+111+1111+11111. [2+6] i.

i
5. a) Explain with an example for compile time initialization of 2D array- Describe how
given
compilier manages according to the number of initializers and size of an alray ',

by a user in case of lD anay. [2+3]

b) Write a program to read a word from a main fiurction, pass it into a function that rvill
convert ail of its characters into upper case if the first character is in iower case and
into lower case if the first charactei is in upper case. Display the converted string from
main function. lsl
6. a) Explain need of structures. How can we create and use a structure within another. [2+3] :

b) Explain clot and affow operators for accessing the rnembers of a structure. l

13l

7. a) If Ptr is a pointer to user defined type or basic type, by how many bytes is Ptr
incremented when the stater-nent Ptr++ is executed? [2]
b) Write a C program that calis re\rerse array () to reverse the array ancl return the array
and display the etement of reversed array using pointer' l6l
8. t,ist'different types of standarcl llo used in 9: Yli,,._ufiog:"". to write name, roll'no a:rd
age of f,tve students into a disk file name "STUDENT'DAT"' [2+6]

9. 'a)
' Explain diffgren! types:of goro statements in FOR.I'R-{N programming with suitable
i Write a program to read n from usei and display the sum of iollorving series
'

"*u*ple.
til1;'iteims: 1*i1+Zy(1*2'j1+(1 +2-3+4)+...........n L4+4]

b) Explaln rvith suitable exampie i6 s[or.v how an hnpiled Do loop rvorks in FiORTRAN' t4l
* {:ir
i I..-.---r
l-Ri BHir V u\rr l-ll\ lVii il.:i i'i
I,ereI fluil }5;rilis , 8ii
iNl; t l'flj1-ii Llir E1!alil'lE,rrlj'-iN'lr
il xilminati* ra C o :etr'$ I B i *,'cse*:e
I irne i lli:i.
?072 Chaitra

Seehi.ecr: ' {lrynpuier Prcgralllming {CT40I)

,/ Cariclidates are requirerl io glv'e their ansu'ers in tilelr c'wn wurds as far as ;;;;';;;;';
'/ Att cntpi 1!1! cttte";tici''t
'/ The Jigures in the ntargln inciicctte {4!-Mgrks-
'/ Asstnne suitub/e dttta iJ'nece siurll

What is a flovr chzirt? IJse the valions cornmonly use'i flovi chalt symbcls. !{or,v
ctoes
1
a)
a florv chait trelp compul.i:r prograrnming? l:+l-l]
b4 l,Vhat is a progran-r? Briellrv soiivrare-
<iesclibe iypes of coritpllier {2.2)
a) Wirat is an operatol, d.atat-YPe, constant and ','ariabie? ileline. [6t

bi Detirr* anii -.,';rite svnl"ax r.li- ihe foliowing: i4]


i.i gets()
iil putchar{)
iii) scant(l
iv; sirlen(7

3. a) F{arv;s ttre sv,,itctr siatentent usecl iri tlecisit,n nlak-ing? Eili:la"irr wirli a" st-iiiablt:
r;i8iTI0ie .
i41

number t)r liot. lrr


b) Write a progratn to clieck r,,rhether a given inieger ls a lriangi.llar
r

l'I

(.iny nrtnber is a i.i icngulrtr number if the sttru o{ ntLttrro.l nt.rnber V'ofit I lc env vttt:viber i
is exitc:tl;,equal tct that;r-un.ber. For e.g 1,3,5,!C,15 erc ore ffiangular nurt'"bzr es'
t+2-J, l+2+3:6, i+2 r3+4--i0, I +2+3+4 '5:l5)
A< a') Briefly explain the passing by value anrl passing h',' r*fe,ence in filncticn "xilh
eKaintrle '
i5i
b) Write a prograrn to calculate sum of digits cf a giv'en 5-ciigits numbcr entererl b1' tile
i.iser lrsing recursive tunction' it,j
5. What is a string? write a prograiri to read a -l*-l solrare rnatrir. tind iDrriircLrrli,itlegei
. value of a rnairix, replace the diagorral elements by the mirrirnrmr eLetnent aird ili:icia-,' ii' i 1- i)iol
i4
using pointer.
i71
;f $ What is the prii-rcipal <liff'erence Lretween a strltcture and arr affzy?
'
fl lvrite ptcgrant ..0 y;,.d sil:ucture "coiiege'' ha'ring name, es-tDale anil i0c;r.tiol, 'r;h,:;i
a
estDate is rr', ,nrrt.ter slnjcilrie !iat':ng'J11 . nrontll and )'cu.i ,J mcri'"bir'3. i;i;,41 ": i'.'
tcr:ot'ds ol i'J colteges ['3'i

7{ a1 Wirat is a aata.frle in C? Wliar are tire rnocie s iii fiie han,'llii,g'i Ei-ola.irr }x'le il'';. Ii _i-r '-li1

b) Write a'pfogranl io rtaii rnitiinialion ,-,f a f,tle riSltr':i "crit:r ixt" and ,','ii;e ' iir-r
t1-ie-'
lKi
conilnts to a.n':riher file "recciil'r:il ' iL't '' :

....::.. a: i}rnpai-e L]li arrd itrpiier.l lJo statemer,i i1 F{iif i'i(A}.i.

i,:
in r.t.;.lrix folry1. t-'_:
ENGINEERING L!ag| - --,-]
INSTITUTE oF - --f
ExarninatiOn
iOn COntrOl DiviSiOn Ii Programme
Program_me -----
ntl(ExceptB.Arch)
II All(Excepr passMarks
B.Arch) j| pass Marks i ]2
shawan [I*1g.1iL--iIL1-----*------Ti,""-_- --ii *-_
!

2071 ---------__-i-_- -L_----_.---

$_y li g:{: c og.g19l-$9 g-lqlgi ys (Q! t o t )


'/ Candidates aie required to give their answers in their own words as far as practicable.
'/ Attempt All questions.
'/ Thefigures in ihe margin indicate Fult Marks.
,/ Assume suitable data if necessary.

1. a) Categorise programming languages on the basic of their uses and applications.


Among them which programming language is C programming? t4l
b) List and define different steps to solve the problem in qomputer system. t4l
2. a) Differentiate b.il;;; J";fu.utio" and definition. Explain structure of C progru* Jrn
an appropriate example. t4l
b) Write syntax, example and use of following: "
[1xa]
i) pintf( )
ii) scanf( )
iii) getche( )
iv) getch( )
3. Write the difference between do and do..... while loop and write the prograrn "to find
whether a year is leap or not'. [3+7]
4. What is recursive function? How does it work? Find out sum of digit of number until the. . ' i
nrrrnber becomes one digit number.[89]>1F9]. t2+Z+4|
c
a) 'S/rite a program to read a string.and rewrite its characters in alphabetical order. t4l
5 b) A multinational company hds hired 3 sales persons for milrketing/selling iu 3
J different.products in Kathmandu. Each sales person sells each of these producs.
Write a program to read number of each product sold by all.sales-persons. Calculate
total sellsof each item and the total sells of each sales-person. Use arrays. t6I
6. a) Explain about "Asays within strJcfJres" alcng',r'ith piogramming exarnple. [4]
h) \I/q!g-!!e progralujlto,uderstand,trow stnrcture members are seut to a function" :t4]
7. Write dorlrt advantages of pointer. Write a progrun using pointer to swap the value of

L4l;,
05 , TRIBHUVAN MVTVENSITV
INSTITUTE OF ENGINEERING
Exarnimation Contro[ Division
2071 Chaitra

S ub_j 9 ct : 1 Corypgler Pro gtammlng_ (C T-'4 0 I )


Candidates are required to give their answers in their own words as far as practlcable.
Att e mpt All qtte s t ions.
The figures in the margin intlicate Full Marks.
As,sume stitable data if necess(try.

1. a) What is mean by compilation? What is mean by interpretation? How do these two


processes differ? l4l
b) l)efine programming language? What are the features of good cornputer program? [1+3]
t)+)1
2. a) What a.re preprocessor directives? Explain constants and variables. L" -.t

b) and exampie of following statelrents/fu1ctions:


write syntax [1 x4]
i) prinff
ii) getch
iii) scanf
iv) long
3. What are control statements? lilustrate nested iF statement with its flowchart. Write a

program to calcutrate the series: 1x10+ 3x20+6x30+.,.'....ryTtUx10N, where N is

an integer teryr read from the keyboard' l2+2+61

4. a) Write a program to display Armstrong numbers between the range entered by a user
and also.disptay their counts. You must use a futrction to check for Armshong
ruunbers and display them lrom main' t4l
b) What do you mean by nested function and recursive function? Give an example of
t)+)1
recursive function. L" -)

5. a) Write a C prograni to read a string and display its reverse. Use user defined function
to count number of characters in it and to reverse it' t4l
b) Write an algorithm to insert a value in afl array at a position gir,en by user. [4]

6, What is a tag? Must a tag be included in a structure type definition? Must a tag be
"l included in a structure variable declaration? Explain' .
tl+t+2)
b) Write a C program that reads several different names and address using structure
r-i11
cornputer, ,"ur.ing" the names into alphabetical order atl,i write out alphabetical list. L.tI

.7.. Illustrate r,vith-exan-rple that "Aray is indirectly a pointer". Write prcgram'to calculate
sum and average of integer nunrbers between M ancl N (where value of M and N are
read
14 )-4j.
from keyboard) using Pointer.
8. Write a piograrn to continuously reacl name, age and salary'ola rvorl<eruand write it into a
f,rle untii uslr confirms to end. Then read n from user and display iile n"' record
in the file .
"Ifetails of worker must be represented by a structure' U)
g,a)Compatearithmeticand1ogicaiifstatementSirrFoRTR^'I{-' L7l

h) write a FORTRAN progranr to display nature of roots ol a quradratic equation.


calculate and display the roots, if they arQ real and equal. t8l
>l *,k
t'
.
.05 TRIBHUvAN uNIVERSITY Exam.
INSTITUTE OF ENGTNEERTNG
ExaminaJion Control Division
2070 Ashad

$y!ject; !9mpute1 Programmtng QTa0l)


Candidates are required to give their answers in their ou,n words as lar as practicabie
Attempt All questions
TheJigures in the margin indicate Full Marks
Assume suitable data if necessory

l. a) Define software. Explain its rypes.


b) what are the steps required to develop a computer program? Explain- tll
15l
a) What are relational operators and assignment operators? Explain with examples-
b) Rewrite the following program by correcting any syntactical errors, if present. Aiso tll
show the output of the corrected code.
[3+2]
#lnclude <stdio.h>
int main ( ).
{
float root, int i : l;
do{ sum:2i-t;
print (..\to%d\n,', sunr);
i *= 5/l;
] while (surn <: L>)
root : pow (i, li2);
print ("\nyo.3 1,, root);
retum void;
\
I

3- a) Write a program to read the number until - 1 is encountered. Also count the number
of
even number and odd numbers entered by the user.
b) Distinguish between break and continue statement with t6l
example
[4]
4- a) Explain how function is defined in C'1 Dii'ferentiate call by value and call by
a, " h)
reference.
rV:;ic a progratlrr using a Q.r:c i,r,i that refum:
.he iargest nu:rb.;r lrom an irra1, of'
ll f2l
numbers that is passed to the function.
tsl
5' a) How are one dimensional and rwo dimensional arrays created in C? Explain with
exarnples.
b) Write a C program to read two matr.ices from user, add them and display the result in 12+21
matrix form.
t6l
6' What do you mean by nested structures? Cive suitable example. write a prograrn
to read
the heights of two students and display the difference betvu,een the ir heights.
Use feel zurd
inches as membe rs of a structure to defirre heishL.
[2+61
1 . a) Compa:e array and pointer vr ith exampic.
b) Write a program to read a string from user and use a user defined fi-rnctron to copl,rhe l3l
content of the read string Into another ch:rracter array ehangrng lower case 1ener to
Lrppef if.a.'n1, Use poir-iter to proce ss the stnnq
ir l
8- \\/rite a Drograrn to read the details of book ar,ri)ois and wrire it to a irle, until the user
conf-rrrns to en'l , rhrn rta.,,i a.d rlisplay lhe atl're..:din rhe fil:.. vr.lcri
n i,. rcad L,or:r tl..c
user- Tlic dita for ar-rthors musr be represellied b,,, :tlrctrrres ti,ai
corrtai tr namil, nationally
and number oi'books publisheo.
tri l
12+ 2l
,-:h0t
n{ h --

I. a) What 'do you mean by software and explain about generation of prograkroing
languages.
:

b) Define.the teim "Flowchart". Discus.s about different slmbols used in Flowcbart.


2. a) !'ind out final value o[ a, b and c wherc following cxpressions arc executed
se_quentially:

inta=2,b=3,c;
a: (b++) + (+$) + a;
c:a>b?a:b;
b: (a#) + (b__) .ra;
c = c+++b--;
b) Whatare rhe difference between formatted and unformatted VO statcments? Describe
witJr proper example.
a) Explain importance o

'i i

-
PULCHO
-
,- ]
prilcHoW 1

PULCTI()WK
4. a) Define i'filnction definition" and writc the program to fino thc sum of two numbers
usin g user{cfi ned :fiurct.i ons.
b) plat do yoir mean by "call by value and Uy rcfcrcnce,' alon& witlr suitable
cxample? "uJl
t4l t
!
5. Can we pass.wholc array element from fuucrion? Wrire a Drogrux to displav only lhose I
r
sludents information which are passed. Use separatc luncrion ro chccK the result. of-
'l'he inibfiation
of student( Iike Name; itoll,No, Addrcss and Marks are passi:rl
from main functions *d pors to functions uslng arra)'type arguments. : ' ' -- I
ltud"al- .
I

' 12+gl
.:l'
I
:

6, . a) Exllarn ttre use of rype{ef olke}-h'oard


in strucrures' '-"
'
' datain p$'toidat-1
Write a C proglam to co'vgn ., ;or,'i.'i'
b) Exp-lain,tt" n..O oil.,ested structure.
".'';'' ''''' 't"i'r'
, ,. inAD*i.,g.*o.'"ii'::iltctrtJ"i"oirttuntuoit'-t"tot'uto:''., . iwe need 'i'J- ' ' '
' -"' howe'#r'
; ol some other variables'
tddi!t-]l'.,t"Tl,llfin'i'-"
a)
?. -' A pointcr variable is uscdto
3t"." ". -
,' i [3] II, i: I
'

declaring a pointgr variablc


,ot*.ciffdatatypewhiledcclaringapointervanaDlc'wrr)''", ' ''
'. lVhY? ,.r*r; ;,-J-**"r::
to'spec;ryao,'ryp"t*i'ile
-.: ,. , U,iSiilr..\
*ravandpoinrerrelated?Giyeex'imilbr i.t]l1i,.\;,
b)Briefly.explainanayofpointers.l{oware.a,,.7-..*'.,. i '
s u; O"no"opin;r,*andclosingafilealorigwithsuitableexdmples'': is " ' l:''\ ;

b) write *.. rro*r,- to o;s"pt^v tn' l':::o^'',,:1.,;Xt


ryrformed id
""i " 101 |
to nune usrng data IllL:s
uurrLrv" I
a-scending o'Oe' *itt' respect ""i11,.'on'o* ""
FORTR"\N:I [4J'
if stor.,*tls in '
9. a) Compare'arithmetic and logical and dilRlal l|n *:
it :'*nt"'exampla
m*n matrix' transryF:
b) wrire'a FORTRAN program to read
,ll
I8l
'.,
4tt
05 TRIBHUVANI MVERSITY Exam. i': Nitt',,Bilck,(2066 &:.Later, Batch):: .
Level BE Full Marks 80
INSTITI-TTE OF ENGINEERING
All(arc"pt s. .r"n.) Pass Marks 32
Examination Control Division Programme
32 hrs.
2069 Ashad Year I 1t1 Time

Subject: - Com (cT 401)

/ Candidates are required to give their answers in their own words


as far as practicable'
/ Anempt All questions.
'/ Thefigures in the margin indicate Futl Mqtkg
{ Assume suitable data if necessary.

1. Differentiate between high level un6 1614' level' Explain the steps of solving a proble'rn
using cornputer. t4+41(

2. Consider a statement
scanf ("%s", sLr) ;

Where str is a string variable


In above statement, why '&' symboi is not used? Can we input string with space in this
statement? If not, whY? t4l
a
\Yrite a program in C to find all possible toots of a quadratic equation ax2+bx+c:0' t8l
4. Write down significance of main( ) function in C. Difterenti4te between pass by value
and pass by reference arguments. Describe both with meaningful example-
L2+61

5. Explain how array can be passed to functions. Write a progmm that passes an array to a
fi.rnction and print the largest and smallest element. [2+6]

6. How are structures different from arrays? Create a structurc in C to store the name of
a
batsman, runs scored and no of times the batsman in dismissed. ln the prQgram, read the
data of five players and display ihe batting average of the player whose name is entered
by the.rr"r. i"tting ur"rug" it totalruns/totaldismissals.
given by [2+6]

t. '#riie down advantages of pointer. What tyFe of arithmetic operations can be


implemented in pointer? Also describe the relationship between array and pointer *it|^ -,-_
appropriate syntax and examPles. [2+3+3]

6. Write a program in C, to read the following information for 96 students.


Student Name, Student ro11 number, Marks obtained(in 100)
Record all data in "ioe.txt" file, and progrcm should print roll number and name of
student who have obtained greater than or equal to 40 marks' t8l

9. Rewrite the following source code correcting any error present in it. Also indicate the
error corrected in comment. Then write the output of the program. [4+4]
I
I

/ /program to convert list of temperatures


//in Centigrade to Fahrenheit
1*include sidio.h;
int maino
{
int i-, n=3,'
float celcIn], farenIn] ;
for11:g' i<n,, i++)
{

Print ( "CeIc t *dl =" )


scanf("td", ceiclil i;
l
convert (cefc, faren, n); :
for(i=C; i<n; i++) print(farenIi]);
Lrreak;
);
void consert,(float ce1[],, float fa:rti, int n)
1

for(i=0; i<n,. i++) cel2far(farIi], cef Iil);


t,
cel2far(floar f, f]oaE c)
{ f =9/5*c+32; },.
10 are do-loops used in FORTRAN? Explain tvith example.
J{ow Compare it with implieo
do-loop' Write a FORTRAN program to read ten integer
n'umbers, itore them in anay,
arrailge thern in ascending order and clispiay the soned ILt.
[r+i+5]
11' what is the syntax of two dimensional arrays in
FORTRAN? Expiain with example. t4l
***

(
t)5 TRIBI,lUVAN IJNIVLRSI I \' l-x a nr.
[\STITU fE OF ENGIr _.-EERINC l.evcl BE Iiull Marks B0
Ilxa nr i n ation Control I)ivision A ll L.rcepr
l'rogrlrnme l)rss r-ks I 2
B Arch N4 a
2069 Chairra Yt;rr i Parl t/t 1im9 i hrs.

Subject _ Cornputer progr-am-lrg l6rtorl


Candidates are required to give their ansr,vers in their
own worcls as far as practicable
Ailentpt All questions
The.figuies in the margin indtcate 17uil Marks
Assume suitable dato i"f necessary.

l) ,) the difference berween compirer and interpreter.


yl[r:"wn

r
E,xprain the rore of
b) Explain the importance oitlowchart. [2+2\
Also draw a flowchartto find reverseof
integer r;umber- For example, 12345 is an
an integer number and its reverse
is 54321.
lt+31
2) a) why do we incrude.<stdio.h> in our program?
can we write a C prtigram without
using any header file?
b) C ive the outpur ol the lollo*,ing [2+ i]
program and.1 ustr$,youi- answ.er with reason.
. #includecsrdio h> t3l
int maino

int x:J ,1-5.2:l.

int a,b;

a=\ + 2+\,15 Z* J- ,

b:++x *(y-3)/2-z++*y,

printf("a:o%d ''.r);

prin tf("b:%d",b);

retum 0.
|,
[21
c)Writcaproqralnthatprintsttrei)oaringpointr,alue.,vithfollorvirre.specification.
' i) Correct \]p 10 t\\'o decinrai piaces
ii) Cor-rcct up to forrr rlccinral places

])a)Writeaprogranltoreadthenumbcr-t.ll.rtil.liserrcorintcrcdAlsoCollntthenurrlberof t6l
b;' tlle user
numbers erltered
prirne number and conrposite
b)ExpiainwhygotoStatementshouldbeavoided?Distinguishbetrveerrbreakand Il+3]
source code'
continue statemellt with erample '-r ^...
exp(x'y) usirrg luncrion rvithout using
to calculate the l:1":i)'"
4) a) Writ'e a program [41
powO tr.,n"'ion' 1i*pt"' exp(2'3)=2^l i e' 2r2r2:8')
with example' t4l
reierence and call by value
b) Diflerentiate between call by
a 3+3
(\ E-^t-:- h^\r,2ff2w"an be oassed to a function.
write a program totranspose
)) Li.Pi;iii iit'- *"-J

matrix.Twomatrixareinputfromthemain()functionandpasstoauserd^efined lz+6)
functionwithargurnentasafiay-Theresultisdisplayedfromthemainfunctton. 6r
6)Whatisadvantageofusingstructure?CreateallarTayofstrucrurenameEmployeelvith
nameandsalaryasstructure*",u*undthearrayofstructureispassedtoafunction
display the sorted srraY from12+61
in ascending order on the basis of salary and
which sorts
main0. t3l
example
1) a) Compar e array and pointer wrth n to copy the

arrav changing lorver caSe lettert"'lPerlS)


b)WrireuO'o*'un-'readsastringfrorntrserdnciuseauserdefinedlunctrot
anothercharacler
./ content of the read string into
if any. Use pointer to process the string t2]
a) Diflerentrate betu'een text
file and binary file'
8)
b)Writeaprogram,takingcareofallthepossibleerrorconditionthatmayOCCUr,toopen
anewf]lenameDATAthatreadsintegersfromuseruntiluserSayS..no,..Afterreading
thedatalvritealltheoddnumbers,o,fit"calledoDDandalItheevennurnbertofile t8l
called EVEN. t2+21 qffir
structurs -rvhat are data types irr Fortran'
e) Explain the FORI-RAN
roots in proper
in FOR-|RAN to sclve quadratic equation and display
10) Write a program {81
f,ormat-

i
i

l"
I

i
I
I
I

I
l
I
.- t;i"
06 TRI:]HI.JYAN T\IVERSITY
iE*;. ,- , ii;.r. iill'oo siiir, .q il,i"ii
. lE
I

NSTiIUTE CF ENGI].JEERNG !-evcl


il':.......,,..-...... ]Iar-rs . s,]
.l rrll :
i \ lt r/L.
Examination Control Division ' Prograrnme , .ti.-lr
nrr r ,\CiDl
.\!arks ' 1 '
^'". ch. l Prrss
-

2068 Shrawan i ).9T.1 -P..l_ll _ _ l. .. ii*! i ll


S1tbje(,'
- Compurer Frogramming
'/ Candidates are required to give thei.r ansl.zers in their own R,orcls as far as practicable.
t Aitempt 411 qu-estions.
"' Tl.ie iigures in the margin indicctte yt!!Ul!!rks-
/ A-r;tin:e:uitable datct if necessai-,;.

i Define aigorithm. Wrire an algorithm for finding largest and smallest vailres ficn a list. 2+61
2. Drarv a flc"vchart and algcrithm to find roots of a quadratic equation (ax2 + bx + c:0).
Inciude ai1 iluee conditions of tiie detennini.*rt.
Ii c]
:i. \ir'te a piogram to i-ead values fiom user and fi,d sum ur:tii osoi tlpes 0, al:'t dispiay'
s'rrn and average. trl
iui

\1i11'1ll"c'5;ralnmers preier using rrser defined iirncticns? WhrLr is rnrrits and iJerneriis oi
'1.
using iunctiori:r in prcgran? Differentiate actr,iai and fonnal paranrerel's useC in 1i;ncirons.i3-2-l I

5. \i./rite a program to take a list of valr-res I}cn-i iiser into an arra.y. Pass tfie list r,t-r a tr,inctl.:lt
Vririch sc'-ts the values in ascei-iiing order'. Dlslria:,thc so,1ed list from rii;;in riogiain.
lj.) j
{. r'\-riie a Frograni io represent ccmplex nurnl:r-:r'bl.a
str;icti-lre r.viih rl:ai ar:i ilirip.iuar-v as
Il1cnl'l,rlts. T:r,l:e 2 conpiex nui:rbers as input li-.:le.irs:r'inr,:, stiuciure rrai:jabies. F::;s ihe
ccmpiex num.bers to a i.tnction u,hich caicuiatcs sur:r ani retr-ln'i:i l;. r.lisplay tiic sum fiort
anclirer function disp1a,vQ.
ii tl
7. \ri1-rat is the roie of pointers in passinq parameters to functic-rns bi, rel:r"enle? ci,,,e
e.i"nple. liolv 2 dimensional ai:ray carr be ac,;rssetj b.7 a i;oirrter. [+--r,
8. $'r1rat do you mean by opening a data f;ie? Ho',"i is this accompiisheC? Explain fscmt,
iprintl fiead, fu,riie functions, ii--t -;il
- .q' E.rol:iin the stiucture of a- FORTAN prcgrirm. DilTerentiate betrveen arithneiic ancl
iogicai if statement.
l2=.1]
iC. Write a program in FORTAN to recd trvo matrices iroin user, find thejr sum anC di:pie1..
the sum.
[8]
**{<
\

TRIBHU VAN LI}']] VER SITY


. NST]TUTE OF ENGINEERING
n
trrxamination, Control Division
2068 Chaitra

-------.:l-_._____ - - p-._:---::1.11'tr, t.vI aua)t


candidates are required to give their answers in
'A
their orvr rvords as lhr as practicable.
l! qu e stf ons.
ttempt A
figures in the margin indicate Fult Mark.s
The
Assume suitable data if necessary.-----

1. a)
b)
design makes programming
points. Also clr;rrv flor,vcharl

2. a)
{2+21,
b) L2l
c) L2l
3. [4]

Ur" ,S"rtdefindd
ur rL rorrl rtrvtrrstj lt..
[g]., ..
5' write down the significance ol arral i1 c.
a program to multiply tw*o jx3 matrix.
*:*:li:_1.:j:1,1,1:- T1i, ( zu,.iion j
.write
;;;;;..
to a us€r denned tt""tlun wrtfl
nrncrion with
argumentvrith array. The resurt is arso dispiayed
_ f.oiimain ( ) function. '.
6' why struclure variable differs flrom airay? wrire e+6)
'-
of ten ernployees. flom main ( ) funcrion and pass
a piogram to input name, posl and
salary --'
(arguments
io
of this function should also a rt*.t
,,*.*e rype user defined fhnction
.. iype). This function r;;#r"J*;?al
, rIffi",H*i::,* :",i,h;l+;;iir"". w.hosq
:::^::yi,:_r #;1";H;"";'il:fil
0,000. rhis modir,id.;;"{;; greater than
saiary is Breater than
_ "# ffi::,'ji'"o is
trzzn,
-r
7,.'WriteaCprogramt1ratreedsastring.fromuser,#ffi:""TJ:i,"i:ffH#i:ii;,ljfr
.Exp1:t:}",::^"yi: .p b".usecr i1 c. How can you u"."*, *r;;;-ents
,iins roi.,t.i
rhe conrenrs of the read string;nro rioirr.r-;;;;;";
upper if any. Use poinrer,o pfo..=,
;;;.,rrrn"*'i"wer case rerrers ro
*li.' 1+6] +
8' write a progralx to input and save ,..o.J,,u" narre, rol[, address
anr] obtained mark * i'
stud.elts. in a binarv file and r;.;.h
;;; ;ii;;i;; ;. record or a srucrenr
mark in highest. The information shoul;
",
whose \ru'La,ruu
obtained
;";;g#;';;'il;.::uLrurr.v1,u* IBt
: 9' writer'a'program'in t"l.
entered Ilom.;i" ',
FORTAN to'clieck whether a positiveinGggr
palindrome
to , .
'keyboard"is a o. rroi. \l,rtt5
Gr"irr ar\ nuqrDer ls paltndrome
palindrometfiir
,,tt i itSl11;,'="3iY Ij."-:' if r"r*rse is equal ro
"*irir'i. !11 lelerse .
--r,UmU..
10.writeFORTRA-- ' ',':to display greatest
i\ prograrn " ' : : ,

and smallest number form list ten elements.


{.++
TRIBHU VA N i,!\iVE RS iTY Exarn.
1),.STlT'l.,TIr Ci: '
i1...-C 1..., EEIi il, rl ''LEVCI
[- x:rniiu ut ion f]orr troi Iii-,.isio ir i Frogramme A1l (Except
a 067 Ashalh
, -Y9{ L Pjg_

-Ql
Su bi::!,
p:lLq p. o g, u",m, n g
_ .
/ Candidates are reoriired to give their
ansr.vers in their own words as
/ Attempt AII questioits. lar as practicable

{ Assume sttitable dctaif neces

'-h\--
1
\';rltat is high
le'el Lingr;rge? \'i'hat lr: fie Jrrlcrent
(onrp'rljrprolrlrrirr:in.. rrngrLl;. tyrcs or rrgh rever langLrages? Horv
c ii.irr,r.r,r ;i,,,,; I,'oR rr,.rir.l rr :, ,;
; I - J a'
2. \\ rr:e ur algtrrithnr rn.l fl,y.ch rn or .. t: r ,, r. .*,.^^..

;:l;**lm*i;,:'i:l:",i;'l',,',._1t, ;';11.1:tlil",::;l',l,IJi,1l,l,l;,;:]: w
3. }\rnlie a sl.ntax used il C progranrlring liutguage
[5+5] -

lor the fol1or.,irgs:


t2xsj
\,' a) .scanf( )
b) wirile 'c) stmct
o) rf ... else
e) static ,lr/
4 vrhlt are the signific.rni nreanirrgs ,rl ,,\,
lr l .- e tablirhcrl :n c l,rsgllnrrrring? Horr
bct\" t'r'tr 't.lt.d b;' r'atuel ;.;r;:i;), r.rerence ,*r.,,itb
:T.:H^**reariatc ",,,r eralmpie in
5 state rvith to*o'
""T]-t: hor"' srvitch^ 1 I firncLi,r, cliflers ftom user ce fined l.urr",r" ,r,
comf tllir programrnirrg
n\ larrgurg.'r'. r.r
(6^ \"/ritc r nseudocoJr lo tlnd rlir .i':rrJrri cri iation l*l r

d'5r\ programr*ing' The attoY bl.rn.nts or arr array or varrres in c


arc read fiom rhe tendnf . use
user defined iu.ctions
f'r"o 'ut'$a".a ci.riui.o;;;u;;.^" s,r..j.rJ-i*r"i,;"r. r,alue
_.- is given by fsl
i-;-.-.--..
l\-
f |,tx*
r'l
- x, rl
SI-l-ll
lnt
ere x- is the mean of the values.

ll:X:X:",m:ji:IH#T::i:
o,cn a irle named REC_'B? ],Tl=-,:=e lccordils
ix,.i,r,_..";,ill,ffi.",,r*:Ii::,
to the outpur drsplale d bero.r: (ro
o I dara where r,,ttst, s -;i;"
vAr t5e;, u"a rotr Corthit;-";i;i;;;;
:li:: ::::,:.r a;;.r_, _/o,
:i.
by;irogram itseifl. "
18 Output is: [10]
:,.
Item Code Description ,
Ilate Quantity
OOlCT Cost I
Comput# 22,000.00
tvl
5 l 10,000.00
Cell Phone 8,000.00
VAT 15% 1U 80,000.00
.,]
I

l otal Cost

Tha* Youlll \Iisri Again

i::
Reu.rite program correctly and rvrjte cutput of the given program r.rritten in C
programming larguage be lolv: i8l
q include"stdio.hr
# include*conio.h *
# ilciude;string.h >
void main( )1
I
\
char arl[1$: {'I','o','E',' ', 'P','U','L','C','H','O','W','K' '\;", i '( '
char ar2[15] : "loE, Pulchowk"; ' t
charar3[l$: {{'t'}.('O'},{'E'}, \

i';),{'p'rJ'u'},{'L'}, t'c'}, {'H'}, {'o'},{'vr'},{'K'}; '..., a '


eBse$r( ); :. -;r--
-
"{pnntf ("\nArray | : %\n", ar1); ,/
printf ("\nArr ay 2 - o/oyXn"
, ar});
printf ("\nArray I : %"p\n", ar3);
-+eh:"w0
\t

9. Dcscribe tiie formaltcd rnput and output staternent in I;OR-TRA-r\ prograrnuring iiinguage
slrltax.
with it's [4]
10 Write a program il FORTRAN to evaluate the follorving series: lSt
series = ]i 1r r I 122 r 1132 f ... ..- ... i l/rl

p 4.ff

'.1
I
I

i
'I

4a T FiE iiT]r.r-\ L;l\ I \.,' ER S ITta D.- ^l II]


l.\ 5 I, r fTE Or E\IGI:.IEERL\C
ELrii ]'ier!:;
ll -rrr iirllt aiio n C onti" oi Dil.isi,on r. -
rl-09-tlltI_tj
: --.. tl- .(l:Oi
_ . .i-ai5 r\1-t il-i
_*. ilrc.r. )

ZOb J Ash'grn Year / Pari ,

Subj ect Ccmo,.iler Pi-n r-.l-, m-i -,-


I rrD:u1i!Lu1l.:
^
*---_' '-_'--.--
'/ Cani Lca:,.s ::: r:c-uir:C io sir.e the i: at-.s\\.:is i,. .-rt: ol,,,t
Jr;,"t.,rr )/l r,-.-Ja-o/:-r.
.,,i
orcs as f:r as practicable.
"/ -.-_-..-P o

'/ Th"e Jigrtres in rlie trLlrgitt ittclicat: ?tLij i,lrtrks


"/ A s s t t iit e s ti t tib / e a i a i-i' ne cJj-sa j-.,
cJ

l Difier:niiate int:ror:ier and c-rrlDile;. Elieilrv erpiain in-e si.-os lollowed for ce.,,eloping
ct:nl-ru:Jr sCi:rual:.
ll. l]
2 What ls i datr t'.r, :' F.vplein tn-'op-rrrors available iii C aloi=: l,-,.ith ilr.:iL-- r,r-,r.d:u,ra rn,l
associarivitl,. ' r--
It+ 't1

' tit) \-I\


co:rLlnua u'n:il Lir: usar en'-'' l\Lr' \--"- ^' -'
r rl1.ll syslinl ml-tsl hl!'e caoa,--iiv tc calculrte l:13 sum
and av'erage o[ rhose numbers are exacriy drvisib]e by 9 but not by 6 ar-Lci l.ies in
',i:uch 'sir:te
ber.rzeen i" to roo and displa1, ,"i,"tr.
^ sLich systenr. . ;-.r;s; r ;; ;.; ;;-;;r;1
;=;;;
algorirhm and floir.,chart to del,elop f \={.r
' \ LJ,-]J
1 f9'r'.recursion is Ciii'el'ent lioni ir:r:;ion? \-',;riii: coC= in C rr-r c,:lcula,e ihe sLinr oi
lbLlowing series uo to n ie,ms so:citt:d br"the Lrser,,vher:;i is pas-.:c1 t.- ih.
calclLlat:s ihe sun. \'or-rr progranr sholilo have rnore than r'..r,.o f,.incijons.
*..,i"",f..a,
Ii -7]
(2't'3l5) + (.1* / (5*7,9t=.
i!l)+ \- - / \
5 Describe the iimrtations oiusing geichar anrl scanf fiLnctions for reading
stnngs. \y\;riie a
cotnplete proeram to insert a siring into anoiher srriit: in tite locatiu-rn
spe.:ii133 b.r the
user. P.ead lite sirine in main fi.tncrioLr. prss ihenr to aro-t1...l- nrnction
position and retuins rhe resi-ilting stnng. "io^S,;j;h-ir;ni;;
[2+S]
0 Eilnlain the r:iation of array and poirier. What is mrant b.i call by value and call bv
a conrplele progran that adds the con'espon,iing .f.**i" n"t
:i::=-i if thl J\'":.
otirenvise nrLririply the conesponJing elements"lusing
i.,
elenrenis,a5e
I lairices
the'coticept of pasiinq arravigsiti\:e,
to th; f,r-ructit-rr-r,r''fr.6:,^^;**-- i
-,' -.
ir+:+:t
i. Detlne thLi stftrcrrLr:s in C proglailn-,i:._q? E:rptlain nesiec st1:crur: rvit[ slir.ab1: ex:nple
\'\'Llte :r p--o2::tt. -ts.;-.g simcl'-tre a;.i
; ,ssi:-t rhc slnrcl... r .; ::r,' [-rnc,ior- ,ar, ,a,,-r,. ,.-,a
rtsr'ill ro conven tne date (in lormat \'\-/NIIvV,DD) rn B.S. to A.D.
t2+2-61
S E'<plai;r tire lO operrtions on fl.e ri'iir sr-.itabie era.r:ro.e and also srale r5e t.,,pical er;or
sr:uaiions d.uring ir'o operarions in file. Hoiv tire.on,.,rr-r-in-trr- nr..r,-, b.'.r,.,a"o-,i,
lCC3SSirl ) . '

^ |.fr _:-._
\-"
9
>-^,$-Att are FORTAN's constanrs valabl:si' ..--'*-
anrl i:brar',. i*nctioons.' h:ipLiin. \\'rrie a
-",1::'"

---- ---:'-^- "..-


oosition insi,i,- o. i:.rr1r conteinins r eltments
[a=S]

You might also like