PDF 2

Download as pdf or txt
Download as pdf or txt
You are on page 1of 4

Roll No.

: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
Amrita Vishwa Vidyapeetham
B.Tech. Degree Examinations – Nov/Dec. 2014
First Semester
CSE100 Computer Programming
(Common to all branches)
Time: Three hours Maximum: 100 Marks
Answer all questions
Part A (10 x 2 = 20 marks)

1. Write a single for loop to print numbers from 1 to 10 and also from 10 to 1
simultaneously.

2. The following code is used to read the gender of a person and prefix his/her name with
Mr/Ms based on gender,assuming the name to be „X‟.Complete the code by filling
appropriate statements.
main()
{char gender;
printf(“Enter the gender (Male-M Female-F):”);
scanf(“_______”,______________);
if(________==‟________‟)
printf(“Mr. X\n”);
else
printf(“________\n”); }

3. Predict the output of the following


main(){
char *a = "Nothing lasts forever";
printf("%c\t%c\t%c\t%c\n", *a, (*a)+1, *(a+2), *(a+9));}

4. Consider the statement char str =”Hello”; What will be the output of the following printf
statements. Give reason for you answer: printf(“\n%s”,str); printf(“\n%s”,&str[2]);
5. What is the output of the program?
#include<stdio.h>
int x=0;
int fun1(){return x;}
int fun2()
{int x=1;
printf("x=%d\n",fun1());
return x;}
void main()
{printf("x=%d\n",fun2());}

6. If the array is declared as int a[4]={0,1,2,3}; Find the elements stored in it after executing
the following statements: for(i=0;i<4;i++) {*(i+a)=a[i]+i[a];}

R-A Page 1 of 4
7. Define an array of 8 Sample structures and assign 3.14 to b member of the fifth array
element, if Sample is declared as follows: struct Sample{int a; float b; };
8. Consider the following declaration: enum Colors{ white, red =2,blue,black=5,green};
What will be the value in white, blue and green?

9. What is the error in the following code? Correct it if any.


#include<stdio.h>
void main()
{ FILE *fp;
char c='m';
open(“filename.txt”,”r”);
fputc(c,fp);
close(“filename.txt”); }

10. What will be the output of the program?


#include<stdio.h>
#define MAN(x, y) ((x)>(y)) ? (x):(y);
int main(){
int i=10, j=5, k=0;
k = MAN(++i, j++);
printf("%d, %d, %d\n", i, j, k); }

Part B (6 x 5 = 30 marks)
11. A Rally is conducted as part of Swacch Bharat Mission by one of the organization. To
encourage and motivate the youngsters they decide to give opportunity to the youngest
among their group to lead the rally. The members were already standing in some random
order. Write a program to read the ages of all the members. Swap the age of person which
is the smallest to the first location. Assume that the ages of persons are unique

For example, if the ages are 40, 80, 20, 50, 90, 30 then after the swap it should be
displayed as 20, 80, 40, 50, 90, 30.

12. Write a C program to check the whether the given matrix is skew-symmetric or not?Hint:
Main diagonal elements should be zeroes and ith row and jth column element should be
equal to the negation of jth row and ith column element.

13. The greatest common divisor of two numbers (integers) is the largest integer that divides
both the numbers. We can find the GCD of two numbers recursively by using the
Euclid‟s algorithm that states

GCD (a, b) =
Implement GCD () as a recursive function.

R-A Page 2 of 4
14. Suppose marks is an array of integers. Consider the following code. Assume that integer
size is 4 bytes.
i=0;
while(i<5)
{ marks[i]=i*i;
i++; }
Suppose the base address of the array is 22222. Find the value of each of the following
expressions: a) marks b) marks[1] c) marks+5 d) *(marks+2) e) *(&marks[3]+1)

15. Declare a structure for an employee which contains name and age as members. Write a
function which compares two such employee structures and returns a value as to whether
are identical („y‟) or not („n‟).

16. Write a program that accept strings using command line arguments and display the
longest string.

Part C (5 x 10 = 50 marks)

17. a) Write a program to implement a function with the following prototype. (5 Marks)
void stringreverse(char *);
Your function must reverse the content of the character array which you are passing.
b) Write a C program which uses the above function to check if a string entered is
palindrome or not. (5 Marks)

18. a) Find the Missing Number. You are given a list of n-1 integers and these integers are in
the range of 1 to n. There are no duplicates in list. One of the integers is missing in the
list. The list contains the numbers in random order. Write an efficient code using
function to find the missing integer. [7 marks]
b) Predict the output of the following code [3 marks]
#include<stdio.h>
void fn(int,int *b);
main( )
{int arr[5]={23,45,11,3,0},i;
fn(5,arr);}
void fn(int n,int *a)
{ int *ptr=&a[0],i=0;
int **pptr=&ptr;
while(*pptr<=&a[n-1])
{printf("%d\n",*(*pptr)+1);
ptr+=2; }}

R-A Page 3 of 4
19. a) int student [5][2] ={1,50,2,20,3,50,4,40,5,80}; (4 marks)
Considering the above declaration, explain the meaning of following representations:
i)student[3] ii)student([2]+1) iii) *student([2]+1) iv) *(*(student+2)+1)
b) Write a c program to declare a structure called Player with fields: player_name,
player_number, total_runs, num_of_innings and average and read 10 players details.
Find the player who has the highest average and display his details. (6 marks)

20. Define a structure called date with data members int, dd,mm,yy. Define a structure called
student with members : name, roll number, date of birth of type date structure, marks in 5
subjects. Dynamically allocate the memory for one student ; Read the detail of a person
and display his details with the number of subjects he has failed.

21. a) Write a C program which implements the Linux command: copy file1 file2. Your C
program must accept the file names through command line, and copy the contents of
file1 to file2. Also display the number of characters copied to the file2 (7 marks)
b) Give an example for unformatted and formatted input statement in C with the syntax.
(3 marks)

*****

R-A Page 4 of 4

You might also like