18CS0501 PPS
18CS0501 PPS
(b) Write a program to find the sum of even and odd numbers from 1 to n.
8. (a) Write a program to find the factorial of a given number. [5+5]
(b) Write a program to generate ‗n‘ Fibonacci numbers.
9. (a) What is a nested loop? Write a program to display multiplications tables from 1 to n.
(b) Write a program to display the following pattern. [5+5]
*****
****
***
**
*
10. (a) Explain else-if ladder with the help of flowchart and program. [5+5]
(b) How does nested if-else works explain with an example?
1. (a) Define an array. How to initialize one-dimensional array? Explain with suitable examples.
[5+5]
(b) Write a C program to sort the given array elements in Ascending order.
2. (a) How to declare and initialize a Two-dimensional array? Discuss with examples. [5+5]
(b) Write a C program to print the sum of diagonal elements of 2-D matrix.
3. Write a C program to multiply two matrices of different order. [10]
4. (a) Write a C program to read and display a 3 by 3 matrix. [5+5]
(b) Write a C program to add 2 matrices of size n by n.
(18CS0501) PROGRAMMING FOR PROBLEM SOLVING Page 3
PPS QUESTION BANK 2018-19
2. (a) What are the features of pointers? Write a C program to print address of a variable
(b) Explain the declaration of pointers and pointer to pointer with examples. [6+4]
3. (a) With proper examples explain different arithmetic operations on pointers. [6+4]
(b) Write a C program to show that pointer of any data type occupies same space.
4. (a) Explain the concept of functions returning pointers with example. [5+5]
(b) Write a C program to read and print an array of elements using pointers.
5. (a) Explain the concept of array of pointers with examples. [4+6]
(b) Write a C program to read and display multiple strings using pointers.
6. (a) Write a C program to count the number of vowels, consonants, digits, spaces and special
characters in a given string. [5+5]
(b) Write a C program to read the elements in an array and print the same in reverse order.
7. (a) Write a C program to implement strcmp() , strcat() , strcpy() and strlen(). [5+5]
(b) Write a program to find the average marks obtained by a class of 50 students in a test.
8. (a) Explain declaration and initialization of array of strings. [4+6]
(b) Write a C program to find whether a given string is palindrome or not.
9. (a) Discus about arithmetic operations on characters. [5+5]
(b) Write a C program to read a set of strings and sort them in alphabetical order.
10. Explain the following string handling functions with example: [10]
a. strcpy() b. strcmp() c. strcat() d.strlen() e. strncat()
1. (a) Define Structure and write the general syntax for declaring and accessing members.
(b) How to copy and compare structure variables? Illustrate with example. [5+5]
2. Write a C program that defines a structure employee containing the details such as empno,
empname, department name and salary. The structure has to store 20 employees in an
organization. Use the appropriate method to define the above details and define a function that
will display the contents? [10]
3. (a) Explain the following: [6+4]
i. Nested structures ii. Array of structures
(b) Write a C program to read and display student details using structure.
4. (a) Define union. Give the general template for union. [4+6]
(b) List out the differences between unions, structures and arrays
5. (a) How data elements are stored under unions, explain with example? [5+5]
(b) Write a C program to illustrate the concept of structure within structure.
6. (a) Write the syntax for opening a file with various modes and closing a file. [4+6]
(b) Explain the following file handling functions:
a. fseek() b. ftell() c. rewind() d. feof()
7. (a) Write a C program to display the contents of the file in reverse order. [5+5]
(b) Write a C program to copy the contents from one file to another file.
8. Write a C program to count no.of characters, spaces, lines, words of a file. [10]
9. (a) Discuss command line arguments in detail with examples. [5+5]
(b) Write a short notes on
i. fgets() ii. fputs()
10. (a) Explain the following preprocessor directives: [4+6]
i. #include ii. #define
(b) Write a program in C that reads the name of a file and displays the contents of the file on the
user screen.
{ int fruit=1;
switch(fruit+2)
{
default:printf("apple");
case 4: printf(" banana");
case 5: printf(" orange");
case 8: printf(" grape");
}
}
(a) applebanana orange grape (b) grape (c) orange (d) banana orange grape
14. Which for loop has range of similar indexes of 'i' used in for (i = 0;i< n; i++)?
(a) for (i = n; i>0; i–) (b) for (i = n; i >= 0; i–)
(c) for (i = n-1; i>0; i–) (d) for (i = n-1; i>-1; i–)
15. What will be output when you will execute following C code?
void main()
{
int check=2;
switch(check)
{
case 2: printf("1");
break;
case 3: printf(" 2");
break;
}
}
(a) 12 (b) 2 (c) 1 (d) Compilation error
16. Which one among the following is the correct syntax of for loop?
(a) for(i=0;i<n;i++); (b) for(i<n;i=0;i++);
(c) for(i=0;i<n:i++); (d) None
17. ‗for‘ loop in C program , if the condition is missing
(a) assumed to be present and taken to be false
(b) assumed to be present and taken to be true
(c) syntax error
(d) execution will be terminated abruptly
18. if c is initialized to 1, how many times following loop is executed
While((c>0)&&(c<60))
{ c++; }
(a) 60 (b) 59 (c) 61 (d)1
19. The library function exit () causes an exit from
}
(a) 12345 (b)1234 (c) 2345 (d) Leads to infinite loop
27. for(;;) can be terminated by
(a) break (b) exit(0) (c) return (d) All the above
28. What is the output of the following program
main()
{
for(i=1;i<=5;i++);
printf(―%d‖,i);
}
(a) 12345 (b)1234 (c) 6 (d) leads to infinite loop
29. What is the correct syntax of for loop
(a) for(i=0;i<n;i++){ } (b) for(i<n;i=0;i++){ }
(c) for(i=0;i<n:i++){} (d) for(i=0:i<n:i++){ }
30. Array is an example of which of the following?
(a) Derived types (b) Fundamental types (c) User-defined types (d) None
31. Which of the following is used to display a string on the screen?
(a) %s (b) %c (c) %d (d) %f
32. What is the final value of x when the code int x; for(x=0; x<10; x++) {} is run?
(a) 10 (b) 9 (c) 0 (d) 1
33. Which of the following is exit controlled loop
(a) for (b) while (c) do-while (d) None
34. The default statement is executed when
(a) All the case statements are false (b) One of the case is true
(c) One of the case is false (d) None
35. How many times the following C code prints ―Hello‖
int main()
{
while (1)
printf("Hello ");
}
(a) One (b) zero (c) Infinite (d) Produce error
36. How many times the following C code prints ―Hello‖
int main()
{
do
{
printf("Hello ");
}while(0);
}
(a) One (b) zero (c) Infinite (d) Produce error
37. How many bytes the array price occupies. float price[10];
(a) 10 bytes (b) 4 bytes (c) 40 bytes (d) 20 bytes
38. Which of the following is syntactically correct?
(a) for(); (b) for(;); (c) for(,); (d) for(;;);
39. What is the output of the following code
main()
{
int a= 0,b = 20;
char x =1,y =10;
if(a,b,x,y)
printf("hello");
}
(a) Syntax error (b) hello (c) 10 (d) None
40. ______ is used to terminate from the entire program
(a) return (b) break (c) exit (d) goto
int main()
{
int arr[]={12,13,14,15,16};
printf(―%d, %d, %d\n‖,sizeof(arr),sizeof(*arr),sizeof(arr[0]));
return 0;
}
a) 10, 2, 4 (b) 20, 4, 4 (c) 16, 2, 2 (d) 20, 2, 2
18. Which of the following statements correct about k used in the below statement?
char ****k;
(a) k is a pointer to a pointer to a pointer to a char
(b) k is a pointer to a pointer to a pointer to a pointer to a char
(c) k is a pointer to a char pointer
(d) k is a pointer to a pointer to a char
19. What will be the output?
main()
{
char *p;
printf(―%d %d‖,sizeof(*p),sizeof(p));
}
(a) 1 1 (b) 1 2 (c) 2 1 (d) 2 2
20. What will be the output?
main()
{
printf(―%d %d‖,sizeof(int *),sizeof(int **));
}
(b) 4 4 (b) 0 2 (c) 2 2 (d) 2 4
21.Which one of the following is a string constant
(a) ‗3‘ (b) “hello” (c) 30 (d) None
22.Which of the following is used to display a string on the screen?
(a) %s (b) %c (c) %d (d) %f
23.Which of the following is used to determine the length of a string?
(a) strlen (b) strcmp (c) strcpy (d) strcat
24.Which of the following is the correct syntax for copying a string S1 into S2?
(a) strcpy(S2,S1); (b) strcpy(S1,S2); (c) strcmp(S1.S2); (d) strcmp(S2,S1);
25.The function strcat(S2,S1) appends ____ to _____
(a) S1,S2 (b) S2,S1 (c) S2,S2 (d) S1,S1
26. Which of the following is used to read a string
(a) getchar() (b) gets() (c) getstr() (d) getch()
27. Which function is used to search for a substring in a string?
(a) strchr (b) strstr (c) strspn (d) strcpy
28. How many arguments that the strcmp() function can take?
(a) 2 (b) 3 (c) 4 (d) 0
29. What will be the result of the following character arithmetic expression?
X=‘A‘-2
(a) 63 (b) 64 (c) 65 (d) 66
30. Which of the following header file is required for performing string operations
(a) stdio.h (b) conio.h (c) string.h (d) ctype.h
31.Which function is used to count and return the number of characters in a given string A)
strcmp() B) strlen() C) strrev() D) strcat()
32. If the two strings are identical, then strcmp() returns ____
(a) -1 (b) 1 (c) 0 (d) yes
33. Which of the following function is more appropriate for reading in a multi-word string?
(a) printf() (b) scanf() (c) gets() (d) puts()
34. Which of the following not belongs to String functions?
A. strcmp() B. strcat() C.strlen() D. isdigit()
35. Which function is used to reverse the string?
(a) reverse() (b) strrev() (c) rev() (d) None
36. What will be the output of the program?
void main()
{
char str1[20] = "Hello", str2[20] = " World";
printf("%sn", strcpy(str2, strcat(str1, str2)));
}
(a) HelloWorld (b) World (c) WorldHello (d) Hello
37. What will be the output of the program?
void main()
{
char str[ ] = "online\0exam‖;
printf(―%s‖,str);
}
(a) online\0exam (b) online (c) onlineexam (d) exam
38. String concatenation means
(a) Combining two strings (b) Extracting a substring out of a string
(c) Comparing two strings (d) partitioning the string into two strings
39. Which function locates the first occurrence of the character in a given string
(a) strstr() (b) strchr() (c) strrchr() (d) strrstr()
40. What is the output of the following code
main()
{ char str1[ ]=‖mahendra singh‖,str2[ ]=‖dhoni captain‖;
strncat(str1,str2,5);
printf(―\n %s‖,str1);
}
char c;
int x;
float y;
}p;
How many bytes are allocated to union variable p?
A) 7 bytes B) 4 bytes C) 1 byte D) 2 bytes
10. In C language the Bit fields are used to ___________
A) Save time B) Save memory
C) Change order of allocation of memory D) Save Program
11. The size of structure and union is same when they contain ___________
A) Single member B) any number of members
C) Arrays of different types D) Pointers to different types
12. The operator used to find the size of any variable _______________
A)sizeof() B) sizof() C) size of() D) size()
13. The operator is same as the combination of the operators _________
(18CS0501) PROGRAMMING FOR PROBLEM SOLVING Page 19
PPS QUESTION BANK 2018-19
C) fp = fopen(―abc‖, ―w‖);
D) None of the mentioned
34. What does the following segment of code do
fprintf(fp, ―Copying!‖);
A) It writes “Copying!” into the file pointed by fp
B) It reads ―Copying!‖ from the file and prints on display
C) It writes as well as reads ―Copying!‖ to and from the file and prints it
D) None of the mentioned
35. FILE reserved word is
A) A structure tag declared in stdio.h B) One of the basic datatypes in c
C) Pointer to the structure defined in stdio.h
D) It is a type name defined in stdio.h
36. Which of the following causes an error
A) Trying to read a file that doesn‘t exist
B) Inability to write data in a file.
C) Failure to allocate memory with the help of malloc
D)All of the menioned
37. fputs adds newline character
A) true B) false
C) Depends on the standard D) Undefined behavior
38. In fseek() function , the position value 2 indicates _____
A) Beginning of file B) End of file C) Current position D) All
39. Which of the following are C preprocessors?
A) #ifdef B) #define C) #endif D) All
40. In fseek() function , the position value 1 indicates _____
A) Beginning of file B) End of file C) Current position D) All