0% found this document useful (0 votes)
38 views64 pages

C

The document contains 8 questions regarding computer programming in C language. The questions cover topics such as: 1) Defining a computer program and generations of programming languages. 2) Importance of algorithms and flowcharts in problem solving. 3) Identifiers, variables, input/output functions, conditional statements, functions, arrays, files, and errors in C programming. 4) Examples include programs to check if a number is even or odd, Armstrong number, string comparison, and array sorting.

Uploaded by

srivastava
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
0% found this document useful (0 votes)
38 views64 pages

C

The document contains 8 questions regarding computer programming in C language. The questions cover topics such as: 1) Defining a computer program and generations of programming languages. 2) Importance of algorithms and flowcharts in problem solving. 3) Identifiers, variables, input/output functions, conditional statements, functions, arrays, files, and errors in C programming. 4) Examples include programs to check if a number is even or odd, Armstrong number, string comparison, and array sorting.

Uploaded by

srivastava
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 64

1l

Progra,mmin1
Subiect: - Computer "FJ! "0J)
Pass Marlc

,/ Candidates are required to give their answers in their own words as far as practicable. ,/ Attempt All questions'
'/ Thefigures in the margin indicate Full Mqrks.
/ Assume suitable data if necessary'
1. a) What is computer program? Discuss in brief about different generation prograniming languagis.
[1+4] b) Vfhy is algorithm and flow chart development important in problem solving? Write an .

' algorithm-and draw flow chart to test a number entered by user whether it is even or not. 12+31

a) What is the identifier? What are the ways to give value to variable? Explain with
2.

example? [1+2+1] b) Explain about input and output function available in C with syntax and example of
eachpart. [Z+2+2] a) Write algorithm, draw flow chart and program to input a number check it is
I

[2+2+21
Armsffong or not. b) What do you mean by selective and repetive statement? Why do we need break and continue
statement? t2+21
a) What do you mean by "call by value and call by reference"? Explain it with suitable
4.
L4l
example.
b) Can we pass whole array element from the function? Write the program to pass an t6l
array to function and sort them.
I4l
a) Write a program that finds the largest word in a given sentence.
5.
b) Differentiate between the methods of passing argument to function with example. t6l
What are their advantages and disadvantages?
What is structure? Why is it necessary? Write a program to add two distances given in 6.
feet and inch
format rlring
***';X:r.:: **ut orrollowins prosram, explain.
structure. [1+1+6] a) what is
nuu
ff
7. [1+3]

int mainQ
{
if( ! NULL )
{. prinff("C programming is easy");
else
printf("C programming is not easy");
return 0 ;
)
b) Write a program to calculate the length of string without using string handling t4l
function.
A file name employee.txt stores employee name, employee id and employee salary. Write
8.
a program to diiplay the detail of all employees in the order of their salary.
[8]
r 10 inteers from user and short them in ascendin
ItI

A2 ,I'RIBHUVAN LNIVERSITY
INSTITUTE OF ENGINEERING
Examination
Control Ilivision
2074 Ashwin

$nU_qg!: c";t{; p;d;il* ;iie Grao t


t
Attempr
Candidates are required to give their answers in their own words as far as practicable. l!!questions.
The
Jigures in the margin indicate FulI Marks.
data
Assume suitable dnecessary.

\: l.
.,
L.

whaj a1e
c-omp]rter
programming? are program
programs and computer Explain the steps that
required to build a computer foisorving a certain pioblem.
that precedence execution expression. program
Explain with an example the rgle and associativity play in the of an Rewrite the following
and
by correctiag any effors, if present also write down the output of the corrected code. Define MAX 5,
int main { }
{
int case[M&(l=12p,5,4,10],i,sum=0;
for(i=O,kMAX,i+=1)
{.
%d
print("Case = %3.2d\n',,i,case [iJ);
SUm +=+ CaSe+i;

h
average = sumlMAX;
ge}
pr i ntf{ "7o06. 2f ', ave ra ;
return 1;
,
12+61 [4+4J

3" a) Compare if-else-if la<Ider and switch construct with example and flowchart. isl
functions
b) ]vrite a Program in C to generate following pattern using unformatted inpuloutput onlv. [-{]
al
t\
FF>

PFPP
aaaaa
LLLLLL
F
aa
LLL
4' v/rite a program in c to find out whether the nth term of the Fibonacci series is a prime number or not' Read the value of n from the
main user-defined generare
user and display the result in the function- use separite functions ro r#';in il";;;;; i.rr" *0," check
prime or not.
whether a nurnber is t8l

t 5' a) How two dimensionar a*ays are created i1,c plgramming? write a program squaxe matrix of size NxN to read and find sum of
is parindrome
botir ailgonJ.. -' yvrrre a program to t) [z+4] xilHffif;ffi in C to check
whether a given srring or nor using
user

advantages poinrer C program to


6' What are the of using in n1q1m*:ng?_ Write a in C ff*,:::t* largest

-r"."*r-r'J'f;';", .ontui'ing concept


N:"r"m"nts using of I4l

'
structures 12+41 nested skuctures?
stmcture hold number
Explain and create a x+iy' write a program to any complex that

uses tt" t*"t* to read two comprex numbers and dispray a third cornplex number which ir1rr" *Jiiprication orth" 8' """r*
""rpl;;;'#;;t t3+51 "' ,H;lHoT*fr:J*ut/output tuncrions used with data files in c? Explain with b) write a program I4l in
integers say.s..no,,. the
c to read from user until user After reading lff.Hff.r*le odd numb." io-u nr" "u'";dd;;'",
*" even number recursive functions?
to file 9' when can we use I4l Iev ao we need conftor statem€nts programs? Differentiate
between do...while characterisrics
in computer *a ror rrui"i"-;,:'.*", srarem€nts in com; l0' what are [2+2+z] the of

calculate value evaluating rottwing


F'RTRAI lggramming? write aprogram to the of n bv in F'RTRAN the ;;;h,r,"

irrizJ-**r. ' t8l n=+(t--l '1 7 1


\
-\- s*s-l*A-..,)
*,r*

05 TRIBHUVAN UNIYERSITY
,t INSTITUTE OF ENGINEERING
Examination Control Division 2073 Shraw&n
ALL (Except B. Arch)
Fy?irsl:_9g_*sggrlss*jss(9ruJ)
Candidates are required to give their answers in their own words as far as practicable. Attempt AIl. que stions.
TheJigures in the margin indicate Full Marks.
Assume suitable data if necessary.

a) What do you mean by Programming Language? Explain about ,t, .uot*ion of


L
pro gramming languages.

b) What are the advantages of a Flowchart design? Write down the guidelines to be followed to draw a flowchart.
a) What is the purpose of the semicolon that appears at the end of most assignment
2.
statement in C? Explain the program compilation, linking and loading process with example.
b) Discuss the types of errors in programming. Horv do you debug a C-program? a) Explain relational and logical operators.
3.

b) Write a C program to display following pattern without using formatted inputloutput statements.
Programming
rogrammin
ogrammi
gfamm
ram
a
with
a) Why do we need control statements? Compare switch and if-else-if ladder example. .
4.

b) Write a C program to display all characters between a given ranges.


a) What are the advantages of using functions? Differentiate between Library functions
f.
and User-defined functions with suitable example.
b) Write a progfilm to check wtrether a given number is Armstrong number or not using recursive funetion.
a) Write a C program to read two strings in main and compare them using userdefined function.rDisplay appropriate
message from main.

b) What are overflow and underflow elrors in context of array? Write a progffim to add corresponding elements of two
arrays. The results should form a new array. a) Why should we prefer structure over array? Explain nested structure with
example.
7.

b) Write a progfitm to read name and roll number of 48 students from user and store them in file. If the file already
contains data, your progftlm should add new data at the end of the file.

a) What is the structure of FORTRAN program?


8.

b) Write a FORTRAN program to read n numbers and display largest number among
[1+3] 12+21
[2+41 12+4) t4l

t4l

t4l
t6I

tsI

t5l

t4l

[2+4] 12+41

t6l
tsl
',*
05 TRIBHUVAN UNIVERSITY
INSTITUTE OF ENGINEERTNG
Examination Control Division
2A72 Chaitra

* F r$:s!: :"c9qp$s:$eslsnnlgg g!!o ! )


questions.
Candidates are required to give their answers in their orvn words as far as practicable. Attempt All
The in the margin indicote Full Mat&s.
figures
Assume suitable data if necessary'

1. a) What is a flow chart? Use the various commonly used floW chart symbols. How does

b)
2. a) b)
a flow chart help computer programming?
What is a program? Brietly describe types of computer software. What is an operator, datatype, constant and variable? Define.
Define and write syntax of the following:

t getsQ
ii) putcharQ
iii) scanfQ
iv) strlen$
[2+2+21 I2+2\

t6l
t4l

a) How is the switch statement used in decision making? Explain with a suitable
3.
t4l
example.

b) Write a program to check whether a given integer is a triangular number or not.


i6l
number
(Any number is a triangular number if the sum of nqtural from I to any number i is exactly equal to that number.
For e.g 1,3,6,1A,15 etc are triangular number as, l+2=3, J+2+3:6, I+2+3+4:10, I +2+3+4+5:l 5)
a) Briefly explain the passing by value and passing by reference in function with 4.
example. t6l b) Write a program to calculate sum of digits of a given S-digits number entered by the
user using recursive function.
t4l
What is a string? Write a progmm to read a 3*3 square matrix, find minimum integer
5.
value of a matrix, replace the diagonal elements by the minimum element and display it
using pointer. [2+8] a) What is the principal difference between a structure and an anay? t21
6.

b) Write d program to read structure "college" having name, estDate and location where estDate is an another structure
having day, month and year as members. Display the
records of l0 colleges.

a) What is a data file in C? What are the modes in file handling? Explain briefly. b) Write a program to read the
information of a file named "data.txt" and write its contents to another file "record.txt".
a) Compare DO and implied DO statement in FORTRAN.
b) Write a FORTRAN program to add and subtract two matrices and display the results in matrix form.
t8l
[1+3]

t6l
t3l

t71

'3?. ..,

/
r'.
r'

1. a),,

b)
3. a)-

a_-
l;.

.,
i

b) Write
the element
8. List different tlpes of stsdard VO [pes of goto statements in FORTRAI{
used iu C. Write aprogrysl age of five to write name, roll
shrdents into a disk file aame "
STUDENT.DATU. 9. a) Explain differe,nt
read n from user and display
3)+(1+2+3+4)+....
[4+4] -...I1
example. Write aprogram. to till ns terms:
1+(l+2)+(1+2+

b) Explain with suitable example to show how an Impiieri Do loop works in FORTP,AN. ' t4I '
:*r.*

P.1.21,
05 TRIBIIUVAI.I UNITERSITY . INSTITUTE OF
Examinaticn,
2A7L

b) WriteaCprogrqm that
computer- rearra[ge tlren@es with example that
"Array*
Level BE Futll!(!rLsl 80" Prograqme
AII @xceptB. Arch) P+s,! Mar.F Y.ear /'Part

Itl Tiine' 3 hrs,

t4I
is indiiectly a pointer". Write program
to
7.. Iltustate calctrlate sum and between
M'and N (where value of M and N are
read
numberi
average of integer
from keyboard) usingpointer
8. Write a program to contiduously read
rvtme, age and salary of a worker and write it into a
file rmtiiusir confirmsio end- Then read n from
user and display the n6 record in the file. Details of 14+4J
worker must be represented by a sEtrcture.
9. a) Compare arithriretic and logical if
staternents inFORTRAN tl
b) Write a FORTRAITI prograrn to display U1

nature of roots of a quadratic equation. Calculate


and display {he roots, if they are real and equal.
pl
c1

:1.
I {.*

P.1.22
lj

05 TRIBHUVAI.IUNIVER.SIfi
'l
Fult [Grks
Eram.
ExamiRation Control Division

W.ritp qmtan,
i) pintf( )
:1..j,
,,
'r;...-: '-

. rlrl..-.i, ,

.i;; f.
'Ir ::
i' ': '
.
I I . ,,i '
Ycar./Part Ut .:,.
Time

program

,do.,,,, lo,9R the progran "to find


while
13+71

of n+uqber uili.l the , ..


i ::.: :. {2+2+4J

8
Level Programme trIl (Exc-eptB.Arch) iass Marks
:J.: order.

,.
,Each sales of a Calculate .-
a)
4bout
'6. t4l
a) Write a
3,'sales.

in a text fiIe. Read,data from.the text file, sort


.

them ia ascending ordei of salqry and store the


' .; l
sorted record to a binary file. Display
to swap the value of
function.
[2+61
8. \l/ritg 4 C progr4m to store ernployee dglails

by the user. g.
the details and rank of employee given . t8] a) What do you mean by formatted
and unfonnatted input/output statements in Fortran and also give suitable example which explain the
.

concept of Formatted UO. t8l b) Write the program to convert a binary number to a decirnal
number using Forkan progra@ming language. t4l t** :

P.1.23
05 TRIBHUVAN I.JNIVERSII'Y c11 r
Bxam.
INSTITUTE OF ENGINEERING -
Examination Control Division
2070 Ashad
(
Lev-el- Full Marks 80 Programme All Except'
.

Arch ) ;, Pass Marks 32


B. "

Year / Part Ill )t, Timc 3 hrs.


,/ Candidates are required to give their answers
their own C? Differentiate call by value and cail by
in { Attempt AII reference.

questions. b) Write a program using a function that


{ Thefigures inthe margin returns the largest number from an array of
numbers that is passed to th9 function.
Marles.
indicate Full { Assume suttable 5. a) How are one dimensional and two
dimensional arrays created in C? Explain with
data if necessary.# practicable.
examples.
l. 1)zDefine software. Explain its types. .,1;: b) Write a C program to read two matrices from
&)z What are the steps required to develop a user, add them and display the result in matnx
computer program? Explain. form.

2. *z'1l What are relational operators and 6. What do you mean by nested structures?
with examples., Give suitable example. Write a program to read '
assignment ffperators? Explain
the Heights of two students and display the
'b) Rewrite the following program by difference between their heights. Use feet and '
inchcs as members of a structure to define height.
correcting any syntactical errors, if presend' 'a)
7. Compare array and pointer with example.
Also show the output of the corrected code.
b) Write a program to read a string from user
#Include <stdio.h> "o and use a user defined function to copy the
( content of the read string into another
int main )'
t character array changing lower case letter to
' float root int i= I; upper if any. Use pointer to process the string.
do sum=2i- l; 8. Write a program to read the details of book
{
print ("\P/od\n,', sum)q authors and write it to a file, until the user -
confirms to end. Then read and display the nh
i *- 513;
record in the file, where n is read from the ' user.
while (swn <: [5) The data for authors must be represented by
I structures that contain name, nationally and
root = pow (i, l/2); number of books published.
print ("\n7o.3f ', root);
v ;,9. a) Explainthe FORTRAN structure. What
return void; are data types in FORTRAN.
) rprlt" to solve
t) a prog1am in FORTRAN

v \tr/rite a program to read the number until - I quadratic equation and displav roots in ptoper

is encountered. AIso count the number of ,kd.*


format. '1 f
t,
3
even number and odd numbers entered by the
user.
b) Distinguish between break and continue
statement with example.
4. a\ Explain how function is defined in t3l
tsl
t3l [+2] tsl
[3+2]
l2+2J t6l

12+61 t3l

tsj

t8l
12+21 rbj
t6l
t4I
1
I

't
I
I

-
I

-l

I
I

-'1
I

-1

t2
, l2o .
22 TRIBHUVAN I'NIVERSITY Exam. Old Back Q065 & Earlier Batch) Level BE
INSTITUTE OF ENGINEERING
Full Marks 80 Programme BEL, BEX,BCT Pass
Examination Control Division 2070 Marls 32 Year / Part Ul Time 3 hrs.
Chitra

Subject: - Computer
Programming | (EG442CT)
{ Candidates are required to
give their answers in their own
practicable.
words as far as {
Anempt All
questions.
{
margin
The/igures in the
tndicate Full Mailcs.
{ Assurne
suitable data if necessary.

t. Why do we
need
programming
language? Write
down the
advantages and
disadvantages of
high level and.low l9v9f programming languages. Write an algorithm and flow chan to check
[Hint year is a leap year if it is divisible.
whether the given yedr is a leap ]reaI or not; ^ -

ty 4 not by 100 and by 400.1 12+3+51

2. What do you mean by operators? Explain differcnt operatorc along with their precedence and
associativity. Write a program to count the number of vowels in a string you ar€ not allowed touse
library functions. 12+2+61
3. What is a nested if-else statement? Explain it with an example. Write a program to find the largest ofthe
three numbers using a nested if-else statement. U+2+11 4
Compare while loop, for loop and
do-while loop. Write a program to evaluate the following series until the difference between the two terms is

xt .S-=f+3-+-+...
less than 0.001. [3+7] 13 " 3., 5!
5. Explain why we need function in programming, Write a function to check whether a
number is prime or not and use the output of that function to print prime numbers from I to n
entered tiy the user. 13+71 6. What is a pointer? Write down the relationship of aray and pointer.
Write a function that takes string as an argument and return the number of characters in the string. Also
return by
converting the string to upper case. Don't use library function. [l+2+71
;
How is nested structu€ formed? Explain with example. Write a program to perform
additioq subtraction, multiplication and division of complex numbers. Make separate
functions foleach operation. tl+2+77 What are binary and text frles? Write a progftm to
write any structure information in a
E.
binary file andtotead and displayillater . Make a menu driven program to read and display

information from file. [3+7)


* *tt
t
,'t*
:

05 TRIBHWANI,JNryERSITY Exam.
lltcgular Level
,BE
Full Marks 80
INSTITUTE OF ENGINEERING
Examination Control Programme AII @xcept B. Arch) Ur
Division 2070 Chaitra Pass IVIarks 32

Year / Part Time 3 hrs,

r' Candidates are required to givi their answers in their own


practicable.
words as far as { Attempt All questions.
{ The/igures in.the margin indicate Full Marlcs / Assume
suitable data if necessary.

J/4 What do you mean by software and


explain about generation of programming
14 l
Define the term "Flowchart". Discuss about
in Flowchart. Z-
different symbols used [4
of a, b and c
9{iAa out final value
where following expressions are executed

sequentially t4l int a=2,b = 3, ci


a= (b+) + 1++b) + a; lo

,/ Q=o>b?aib; 3
+a;
'6 = (a++) + (b-) V
c= c+t_*b_-i S
b) What are the difference between formatted
and unformatted UO statements? Describe with

proper example. t4l !*Y exylain


importance of break and default statements in
swirch statements. tll'
b) Write a C program to display following pattem using unformatted
output statements:
l7l
P

Pu
PUL

PULC
{'

Pul.cH

pulcHoW
PULCHOWK
/
4.\af Dqfine "firnction definition" and write the program to find the sum of tu,o numbers using
user-defined functions. t{L yI Wtlm;t do you mean by "call by value and call by
reference" along with suitable
: -:
examFle? I{] S/Canwe pass whole array element from funotion? Write a
program to display only those students infomration which are passed. Use separate function to
check the result of student. The information of students like Name, Roll No, Address and Marks are
passed from mainArnctions and pass to functions using array t)?e arguments. L2+8I
A. of t5,pedef of keyboard in structures.
r{nxplain the use -/' 12) b) /xplain the need.of nested
structure. Writeia C program to convert data in BS to data
y-/ in AD using structure. Use the data

difference of current'data. tl*S]


t3]
t5l_

l4J

t4l
t4l /
a FORTRAN program to read m*n matrix, transpose it and display both the
Srf'W;te

**
il

,]
;i -ll.
i

,..-,,,,,.. . -.
. -r -.-.,',i.J'
ri
li
I

I
i

i
:

I
''t:; .

-l
Examination Control Division
I
2069 Ashad i'
I
I

s
i

Level BE Full Marks 80 Programme AIlGo""pt n. rrct.)


05 TRIBHWAN T'NIVERSITY 3.t
(2066 Pass Marks Year /Part lll Time 32 hrs.
Exam. Nen,Ilacli & Later, Batch)
INSTITUTE OF ENGINEERING

/ Candidates me required to give their answers in their owr: words as far as practicable.
')

{ Auempt.AlI questions.
l

'/ Thefigures in the margin indicate Full Marks.


i
'!

{ Assume suitable data if necessary.


iI
I

Vt Dry"rentiate between high level and low level. Explain the steps of solving a problem
II
I

using computer- [4+4]


' 2. Consider a statement
scanf ("8s", str) ;
Where st is a string variable
In above statement, why '&' symbol is not used? Can we input string with space in this
statement? If not, why? t4l \,
find all possible roots of a quadratic equation a:r2+b>i+c=0.
fu \Vrite a program in C to t8] 'r"

-.$--Wlile pas,!y.lalrl9;,_
$to:un sieniticance qf u'pin()$n-ction in Ci Diftereajate betwe_en v :e
Describe both witJr meaningfuIexample.
and pass by reGrEnce arguments.
! - 12+61 {
5,. Explain how array can be passed to firnctions. Write a program that passes an array to a \/
element.
firnction and print the largest and smallest \ [2+61 -Q How are sEuctures different from
arrays? Create a structLue in C to store the name of a

v batsman, runs scored and no of times the batsman in dismissed. ln the pregram, read the data
of five players and display the batting average of the player whose name is entered
Wnte
by the user. Batting average is given by totalruns/total-dismissals. ,t [2+61 l-
down advantages of pointer. What type of arithmetic operations can be
t implemented in
pointer? Also describe the relationship between array and pointer with [2+3+3J appropriate syntax

and examples. ,f 8. Write a progr.un in C, to read the following information for 96 shrdents.
Student Name, Student roll number, Marks obtained(in 100)
Record all data in "ioe.txt" file, and program should print roll number and name of
student who have obtained greater than or equal to 40 marks. t8] 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. 14+41 ,

?
/program to convert
.rL.

list
of

temperatures
L
/in Centigrade to Eahrenheit .
*inclucie stdio-h; 8'
int main ( )
{
int i, n-3;
float celc Ini , faren In] ;
6sg1i=0; i<n; i++)
{
. Print ( "CeIc t tdl =" )
scanf ("td", ceicIi] ),'
]

' i6nlrert (berc, faren, n) i ' t ' for


print
(i=0; i<n,. i++) lfarenii) ) ;
break;
rftroat.
);void convqct:(.ftoat,c.eAlJ,
fa:r[], int n)

forli=0, i<n,' i++) celzfar(farIi]i


1

celIil);
-
I

:l
them in array,
,,I
10. '/
i;cel2far(float f, float c) *lJile
I., e
{ f = 9/5*c+32; !; i,:

it with implied
\
.11. What exampie. ['+.1 j

l/-
***
v
the syntax of two dirrrensional in FORTRANI Expiain \{ith

i,

/
---*
"05 TR]BHWANUNIVERSITY INSTITUTE OF Year / Part ilr Time 3 hrs.
ENGINEERING Examination Control
Division 2058 Baishakh
Exam, Resular / Back
Level BE FulI Marks 80

Programme All (except


I

Pass Marks 32
B.Arch)

t'
Candidates are required to give their answers in their own rvords as far as
practicable.
{ Attempf&.qtrcstions. ,/ Thefigures in the
Fu!!@fu.
margin tndicate / Assum.e suitable data if necessary.
1. What is high level language? Write different types of high level programming languages with their
examples. Hpw compiler is different than assembler programming language? [1+4+3]. '.'2. What is a

pseudo code? How is it different from an algorithm? Draw the flowchart to solve the multiplication of two
matrices. U+2+51 l. Write a hierarchy of operations of the following expression in computer
programming C: IEOF tt B-Salary + Daily-Allowance > 8000&& eligible_code =: 1tt nelpay>10000. Write
different forriraited input output used rn For Tran programming language. [4+4]
4. Write a program.in C to calculate the frequency (F) for different values of cap.acitanees(C), for a certain
resistance the darhped natural frequBncy is given
electrical circuit. with an inductance (L) and @),
by-F:./11tll.Ci-Cn'zl+C11.-It is.iequired to study ttr'e variation ottiis
frequencyw^ith capacitance
defined.function.
starting frbm 0.0.1 to 0.1 in steps ofb.01, and calculationlhould be,dohe.u$ing uqbr [8]
5. Write a syntax in C- programming wittr example of the following: "scanf', single statement
"do....while", "strcpy'', structures with arrays. fax?J 6. What are the rules that govern the passing of
arrays to user defined functions? Compare'"user defined
functioni' and "switch" in C- programming language. [3+5] 7. What are the importances of "Pofutters"
in C programming language? Write the output of the following program. L4+41

# include<conio.h>
voidmain0
, t int k; int.a[ ] = {1, 2,.3};.int*b[3]; int **c[3];
**,Fe[3J.
int***d[3] ; int* 1o1**** *,f[3];
clrscO;

for g =' O;t<:; t++1 i


{ blkl.: q+ hclkl :b + k; d [k] : c + k'
e[k]:d+k;f[k]:e*ki
il
(t
fo. --L;t.3;k+-r)
printf ('oA3il',
t *b[k]; printf ("%3d", **c[k];
printf ("%3d", ***d[k]; pintf ("Yo3d', ****e[k];

Printf ("%3d\nr' *****f[k] ;


)
)
8. Write a progtam to read name and age of 10 different students as the two members of a structure named
"studeirts". Display the name and corresponding age of the students sorted in an alphabetical order. t8] g.

What are the inputs and outputs functions used with data frles? Explain, error handling process d-uring
reading and writilg in a data files. t5:31 i0. Write a program in ForTran to test whether the acceptcd year
is leap year, or not. (Hint: A year is
leap year if: the year is divisible by 4, but not by 100 or the year is divisible by a00) t8l
rl
:1.
{.*

I
t

il
tl
l
I

tilr

I
i
I

\
,,:a

06 'I'RIBHUVANI.JNIVERSITY BE Full Marks 80, Programme All (Except


INSTITUTE OF ENGINEERING Pass Marks 32
B.Arch.)
Examination Control Division Year / Part TIT Time 3 hrs.

2068 Shrawan

(2066
Exam. New Back Batch & Later) . Level

Subject: - Computer
Programrning
'/ Candidates are required to give
their answers in their own words as
Attempt
practicable.
far as ,/
All.questtons-
./
Thefigures tn the margin indicate
l:ull,Mqiks.
,/ As-rume
suitable data if necessary.
1. Define algorithm. lVrile an algorithm for finding largest and smallest values from a list. [2+6J. 2.
Draw a flowchart and algorithm to find roots of a quadratic equation (ax2 + bx + c : 0). Include all

three conditions of thedeterminant. I [10] 3. Write a program to read values from user and
find sum until user types 0, also display sum and average. t8L 4. &Ihy prograillmers prefer
using user d.efined functions? What is merits and demerits of using functions in program?
Differentiate actual and formal parameters used in functions.[3+2+3J - 5. Write a pro$am to take a list
of values from user into an L$ay. Pass the list to a function which sorts thq vaiues in ascending order.
Display the sorted list from main program. [315] 6. Write a proglam to represent cornplex
number by a structure with real and imaginary as members. Take 2 complex numbers as input from
user into structure variables. Pass the complex numbers to a function which calculates sum and returns
it. Display the sum from anothgr tunction displayQ. [10] 7. What is the role of pointers in
passing parameters to functions by reference? Give example, how 2 dimensional array can be
accessed by a pointer. 14+41 8. \lhat do you mean by opening a data fiie? Iiow is this
fread, fwrite functions. [l+3+4]
accomplished? Explain fscanf, &rintf, g. Explain the skucture

of a FORteX program. Differentiate between arithmetic and logrcai if statemenl 1Z+Z1t 10.

Write a program in FORTAN to read two matices from user, find their srmr and display the sum.
t8l **rf

L
I

i
I

i
ir

i
I
i

1
I
-
t
I

'1
I
I

I
I

-''l

i
I

-t

i
I

I
I I
I
1

a.**J Eram. RegulariBatk Level BE tr'uU Nlariis 80


05 IRIBHUVA}ITJNIVERSITY
INSTTTUTE OF ENGINEERING Prograrhme All @xcept
Pass 32
Examinatlon C on rrol Divisi,*rr B.Arch.) ^\Iarks

2067 Ashadh Year / Part UI Time 3 brs.

prdcticable.
{, Candidates are required to give their answers in their oum words as far as { Auempt All
questions. Marks.
,/ Thefigures inthe margin indicate Fult / Assume suitable data if necessary.
1. What is high level language? What are the different types of higfu lwel languages? How
computerprogramming language C is different from FORTRAI.I? [1+]t{ 2. 'Write an
algorithm aud flowchart of the distance betwee,n two points (xr, yr) and (x2; y2),
I

(xz *r)' + (yz- y1)2. Where, xr, xz, yr, yz ari given by user,
govenred by formula Dz = -
I

ts+fl'"
.::... ... ,

3. Write a qmta:r used in:C prograinming tHI


a) scan( b)
teinguage for the followings: )
while c) stuct
4. What are the significant meanings of '&' and '*' established in C programming? How . car
by refereuce'-with irt
you differentiate between 'ciIIed by value' and 'called "*iropt.
(
Cprogramming?. : t4+61 5. State with example, how switch ) function differs
from user defined function in
computerprogramminglanguage C. t4l 6. Write a pseudocode to
find the standard deviation of an array of values in C programming. The array ele,ments are
read from the terminal. U'se user defrned functions ' to calculate standard deviatipn and mean. Standard

deviation of n value is given by ,EI, ,

1-',.'E;;;
r'=
1= ,
Where x, is the'mean of the values.
7 . 'Write a prograur in C programming language accor<li.g to the output displayed below: (to
open a file named RECORD.txt for the n number of data where Cost, Service Charge 5o/o,
[0]
VAT 15%, and Total Cost must be calculated by program itself).
Output is:
Item Code Description Rate Ouantitv Cost OOlCT Computer 22.000.00 5 110.000.00
007M Cell Phone E,C'00.00 IO 80.000.00 VAT 15-"/C
Sersice Charge 5%
Total Cost
Thank You!!! Visit Again
8. Rewrite program correctly and write .oritput of
I

the glven proglam written in C programming I anguage


below :
-1
# include stdio.h 1

# include conio.h
I
main(
void ); t8l

'{char arl[1 1] : {'t"'o"'E"'


i
I

"'P"'IJ"'L"'C"'Hi,'O"''W"'K',}; char ar2[15] = "IoE,


Pulchowp';

char ar3[1 1] = { {'I'},{'O'},{'E'},

{''},{'p'},{'u'},{'L'},{'c'}, {'H'},{'o'},{'w'}, {'K'};


clrscsr(
);

{printf ("\nArray l:
o/oc\n",
arl);

Cf"arrayz:o/*Yl',lr2,)i'
I

riit"tf
l
:

priutf ('lnArray 1: %c'rn-', [3);


retum 0
)
I4l
9. Describe the formatt$ inpu! and output statement ip
IOR'[RAI.{ programming language with it's syrtax.
10. Write a program in FORTRAI.{ to evaluate the following series:
t8l
!

series.: 1/11 + Ll22 + lt32 + ... ... ... + lN


,f :f !f

I
i

,I

'22 Tir ":,'..'-{1IUNIVERSITY ]N:-iNEERI]'


INSTITU' - ,T ' r., i aminal
:..Onti'Ol Fuii ]i: rks
l. * [)iv.i:ii :: BE 80
r- ./ E:r ik
BEL, BEX, Plls..; .r. 32
BCT I,i::ks
2CSi ihra;,'an \'ear lPzrt
I/i 3 hrs. Ti;:re
Subject ter Proprarnn'ring I
Candidates are requr-;?d to give thelr answers in their own words as far.as'practicable.

Anempt in the margin indicate Ata*s.


, ilil questioi;s. '/ Thefigures Z"U 'r' Assume suitable
date if necessary^.
-

1. a) What are'the-Cen:erits of C programming? Fiowchart is representation of an . algorithm.

Jushfy the statement with suitable example. 12+21 b) Draw a florvchart and then rvrite a program to
read three ,iau, oi
" ri*gt" and print
or
area for vaiid data and to print "Invalid data" ifeither one side oftiangle-is greater ' equals to thq sunq of
othertwo sides. [Area=
66:AGTC;O, where a, b, c are t"'. ""= ..,,
'
threesid.dsands=(a+b+c)/2. .' . .' _ t4]

2- a) b)

3. a) b)

4a) b)

s. a) b)

6. a)

,,
'7." a), b)
Describe the meaning of Write a program in C to find trace factorial and other calcuiates
precedence.and associatively and norm of a matrix. Trace is power of anumber.
of operators with suitaLle defineC as the sum of principal Wlry pointer operator is called
example. How much memory is diagonal element; Nonn is defined indirection
operator? Give
required for long integer and its as square root of the sum of example.
range? the.squars of all the eiernents
to check
inmatrix. Write a C program
Write a progam in C to calculate
the sum of given series up to the Ciassify the variable according to ryhether the given sfting is
term given by the user. : the scope aod exteqrt (Storage palindrome or not. Palindrbme
class) with C. Write a program in shorild be chEcked by user defined
2/x2 + 3lx3
Y = L 12 - C which calculates F, where p,=
function.
-.................,........... What are the differences between
Distinguish betrveen call by value (a t bn)/ c!,and n is. an integer. malloc( and calloc( Wheu we
) ).
and call by reference with exampleFor designing above program,
in C. use two functions, one calculatbs
use realloc(
).
Write a C program to read n
integer numbers in an array
dynamically and create two
functions to sort in ascending and
descending order and display the l3l
result in the maiu function. b)
Discitss [6r'r arra] of strings can be9' a) b)
stored in.ai-ray of pointer variable.
Write a C p'rrsglam to enter the
strings uatil the user enteis "end';
and display the list of string in
aiphabeticai order using two 10. a) b)

dimensional array of character


usirg flrnction.

[2+41 l4I

12)

.t6l
121

t6l
t3l

tsl
[2+1]

tsl
t3l

tsl
-t!
i

-l
I
I

8. a)
Explain nested struchre in C, with
example.
Write a C program that illustrates
the pointer pointing to the assignment operator. Explain
function. How can we'pass with exa:nples.
.
l2l
structure variable as a pararneter Write a program in-C to create
in function. Illustrate with an a file named "subject.brt" that :r,".;
exari,rple. stores subject name, subject code 1

Create a structure Shrdent(Roll, and full marks where subject


t\
Name, Address, Age) to store 10 na:ne and subject codes are t6]
stings and full marks is float.
different records of students
Also display aillhe records stored
and ariother structure
in the file. Write. a.progarfl to
Marks_Sheet(SN,
keep the records of 10 subjects
Subject_Name, Full Marks,
and display allrbcords from the
Pass-Marks, Marks-Obtained) ,c
file.
within Snrlent tL store the
records of S different subjects. tsl nl
i

Write a program to enter the i

records of students and display tLe l2l


records with the percentage each "{
student have scored.
In which condition unary
operator is equivalent to
l6l
i

r' ,j;.
-- 1.- :-*'r'+-;lit,,!a;ir-::..1ilt;:,.-:;.i:.f l-: ,.,,.,-.)t.. '., ,. ..-
1 -.. .:..i:.-:::-::. :.i: )

-' ::::-:1:r-iE:i1,:.i:1:i:::-_:*t',:-r ..- h :

22 TRIBHUVAN UNIVERSITY BEL,BEX,


OF ENGINEERING Pass Marks 32
INSTITUTE BCT

Examination Control Division Year / Part vl Time 3 hrs. I


2055 Shrawan
Exam.
Level BE FullMuks 80 Programme

/ Candidates are requhed to give their answers in their own words as far as
practicable.
{ Auempt All.questions. t Thefigures in the margin indicate Full
Marlis.
r' Assumb suitable data if necessary.
I.- E

1. a) b)

.2. a) b)

3; a) b)

4. a) b)

5. a) .b)

programming agree that the compilercan produce the


Iilfhy is C most
executable file directly itself? Elaborate
commoqly used in simulation? Do you
your answer. .[2+2] Write an don't good' programmers prefer example. : [+2] Write a
over
algorithm and a flowchart to read a five goto-statement? Compare switch program to read number and call a
digit number and check whether the
if-ladder. function till 'yes' is entered by the user.
number is a
palindrome
or B+21 not. else
. [+1+l] Write a
You should count and sum the
List different operators with their program using recnrsion to comlute the numbers using static variables in the
corresponding associativity in C. function and
Mention the size and range of signed
sum of the followind ieries: tsl 12 the main
return ?verage to the
(-1)*' n2 without
long int and float. [2+l] Write an -22 +
32
- 42 ..... + fuuction._
interactive progrun that readi positive using pow( function. You should read
t5l
Compare'array ,,
) pointer
numbers until user enters "no" and then with sptactically and
the
sum the numbers divisible by 4 that value of n from the user.
lie between the range of 10 and 50 How does a function optimize physically.
t2] Write a program
and frnally display the count and the resources at the progranrmer and thq
to compute the deterrrinant of a square
matrix of nth order and then check
average value. I51 IllusEate the machine side? How does a fr:nction
whether the given mgtrix is singular or
retum value? Illustratewith
formatted VO sking data. Why not. You need to have two frmctions as
read ( ( ).
-. ) andprocess -' '-,. '- -:' '-
[6t
r:: I.'.,:, , - 1.. t-

I pointer arithmetic on both data variable memory spaces


and pointer variable.
-
b) Write a program that dynamically
allocates twb different strings and pass
:
where 1I(B 1024 B and 1B=8 bits and

them to a function where the second dispiay the results in the main functien.
sh'ing is compared with the reverse of the
first string on the chanicter basis and [1+i]
display the message in the main
function. You are'not allowed to u1e.!he
sting functions. l6l
-8. a) 'Illushate the self referential
ll+11
I sbucture and the position pointer. ''':
6. a) \Mhy do we need IIMA? Explain b) Write a prograur that illustrates
the significance of calloc( ) with example. passing function address to other t61
--'
using
functions directly and Pointer. ,F+tl
b) Write a pro$am that reads positive 9. a) Sketch the bits assignment in a
integer nrunbers into an aray
stuctue if.you have 7 bit fields of 5 bits l6l
dyna:nically and pass them to a function length each. Justify the bytes
where odd nudrbers are filtered into consumption by above stnrcturc with
another array and disptay the array reasoning. t2l
containing odd numbers in the main
functiou. b) Write a progrurm to compute any
two instant memory spaces in a format
7. a) Mention the applications of t6l
(Kilobytes: Bytes: Bits) using stnrcture.
pointer. Illustrate the invalid and valid
Build functions to add and subkact given TT!
b) Write a program that first appends the from
binary file and display the file. The file
customer records ia a the number of
name
customer records as well as the contents
should be given by user and display if it does not exit.
l6]
i

I
I
I
I
I

-1
I
I

You might also like