C Programming Past Updated - 2080
C Programming Past Updated - 2080
i -.--- -
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*
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© 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
{"!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.
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
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]
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
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
'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
i!
7. a) Write the output of the follovring.
l6l
a r---l
lro--_J b ii---__l
i .Lr_---t I
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
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.
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
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
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
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.
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)
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 ',
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
,/ 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
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
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 '' :
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 *-_
!
L4l;,
05 , TRIBHUVAN MVTVENSITV
INSTITUTE OF ENGINEERING
Exarnimation Contro[ Division
2071 Chaitra
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
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.
:
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
:
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) ;
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]
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
(
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.
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 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
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
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]
**{<
\
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 " ' : : ,
-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
'-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] -
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
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'}, \
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
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
^ |.fr _:-._
\-"
9
>-^,$-Att are FORTAN's constanrs valabl:si' ..--'*-
anrl i:brar',. i*nctioons.' h:ipLiin. \\'rrie a
-",1::'"