Beruflich Dokumente
Kultur Dokumente
: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
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)
Automatic variables
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)
(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};
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--;
}
#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)
*****
Page 5 of 5