Sie sind auf Seite 1von 5

Roll No.

: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
Amrita VishwaVidyapeetham
B.Tech. Second Assessment – March 2016
Second Semester
15CSE102 Computer Programming
(Common to all branches)
Time: Two hours Maximum: 50 Marks
Answer only on the question paper
Answer all questions
1. a. Give the structure of a C function. (2 Marks)
b. Complete the missing entries in the table given below. (2Marks)

Storage Class Visibility

Automatic variables

Persists until the end of the program and


initialized only once

c. Which operator cannot be used with register variables? Why? (2 Marks)


d.Give two differences between while and do..while loop constructs. (2 Marks)
e. The following is a piece of C code, whose intention is to print a minus sign 20 times. But you
can notice that, it doesn't work. Fix the bug by changing exactly only one character at one place
in the code. (1 Mark)
#include<stdio.h>
int main()
{
inti;
int n =20;
for(i=0;i< n;i--)
printf("-");
return0;
}

f. Write a C program(one.c) that invokes a main function which prints “Hello” written in a
user defined header file(user.h). (2 Marks)

2. a. Do as directed. (3 Marks)

(i) Predict the output.


#include<stdio.h>
intmain()
{
inti=2,j=2;
while(i+1?--i:j++)
printf("i=%d",i); return0;}

(ii) What value does testarray[2][1][0] in the sample code below contain?
inttestarray[3][2][2]={1,2,3,4,5,6,7,8,9,10,11,12};

Page 1 of 5
(iii) Find the error.

void message();
void main()
{
void message()
{
printf(“C is efficient and fast”);
printf(“C is highly portable);
}
}
b. Identify and correct the errors in each of the following C statements if any.(2 Marks)
(i) Function header : float fun(int a=2,float b=2.5);

(ii) intarr[][]={1,2,3,4};

c. Trace the order of the function calls. (1 Mark)


#include<stdio.h>
void main()
{
f();
}
f()
{
f1();
printf("CSE\n");
f2();
}
f1(){printf("ECE\n");f2();
}
f2() {printf("EEE\n");
}

d. Complete the printfstatement such that it prints the number of elements in a given
array. (1 Mark)
#include <stdio.h>
void main()
{
// Assume that an array is declared in a variable named arr
printf(“%d”,………………………………………………………………...);
}
e.Write a „C‟ program that has a user defined function „multable‟ which take two integer
parametersm and n, and printsthe multiplication table of m up to the limit n.(2 Marks)

3. Predict the output (If any errors in the program state the error). (5 X 2=10 Marks)
(i) #include<stdio.h>
int f1(int count);
main()
{
int a, count;
for(count = 1; count <= 4; ++count)
{ a = f1(count);
printf("%d\t",a); }
}
Page 2 of 5
f1(int x)
{
static int y = 0;
y+=x;
return(y);
}
(ii) #include<stdio.h>
void main()
{
intnum=1,k=1,j;
while(num<=15)
{
for(j=1;j<=k;j++)
printf(" %d",num++);
printf("\n\n");
k++;
}
}
(iii) #include<stdio.h>
int main()
{
int x=011,i;
for(i=0;i<x;i+=3)
{
printf("Start ");
continue;
printf("End");
}
return 0;
}
(iv) #include<stdio.h>
void main()
{
int a[5] = {5, 1, 15, 20, 25};
inti, j, m;
i = ++a[1];
j = a[1]++;
m = a[i++];
printf("%d, %d, %d", i, j, m);
}
(v) #include<stdio.h>
int main()
{
int i,j;
i=j=2,3;
while(--i&&j++)
printf("%d %d",i,j);
return 0;
}
4. a. Is this a valid C code that can execute without any error? If so predict the output, if not
justify your answer giving reasons. (2 Marks)

Page 3 of 5
#include<stdio.h>
int r();
int main()
{
for(r();r();r())
{
printf("%d ",r());
}
return 0;
}
int r()
{
int static num=7;
return num--;
}

b. What will be the output of? (2 Marks)


#include <stdio.h>
int main()
{
unsigned char flag=0,tally;
for(tally=0;tally<=4;tally++)
{
flag |=(1<< tally);
}
flag |=((1<<2)|(1<<3));
printf("%d",flag);
return 1;
}
c. Is this a valid C code that can execute without any error? If so predict the output, if not
state the error (compile-time or run-time). (2 Marks)

#include<stdio.h>

int main()
{
intarr[1]={10};
printf("%d\n", 0[arr]);
return0;
}

d. Add only one statement to the body of the loop such that it will print 1 2 3 4 5 6 7 8 9 10.
(2 Marks)

#include <stdio.h>
int main()
{
int tally=0;
for(;;)
{
if(tally==10)
{
break;
}
Page 4 of 5
}
return 0;
}

e. Write a C program that prints numbers from 1 to 100 without using any loop construct or
goto statement. (2 Marks)

5. a. Write a program to read a matrix and multiply the diagonal elements of the matrix by 3
andsubtract 5 from the non diagonal elements and display the new matrix.(3 Marks)

b. i. Write a C program to swap two numbers using a user defined function named swap
that uses a call by value mechanism for exchange of parameter values. The function
should swap the numbers using bitwise operations. (3 Marks)
ii. Which concept of computational thinking process is preserved by call by value
method? (1 Mark)

c. Write a C program to model the voting scenario given below:


There are three nominees (A,B and C) for an election. Assume nvoters are voting for
them. The vote is recorded as a unique character symbol for each candidate ( A-@, B-
#,C-$). Define the number of voters as a static variable.Vote casted without possession
of Voter-ID card is to be treated as invalid. Your program should
i. Count the number of votes for each candidate.
ii. Count the number of invalid votes.
iii. % of votes cast in that region. (3 Marks)

*****

Page 5 of 5

Das könnte Ihnen auch gefallen