Professional Documents
Culture Documents
Introduction
1. With the help of block diagram of digital computer explain the function of control unit and
Memory unit.
2. How does digital computer differ from Analog computer? Define hybrid computer .
5. What is a programming language? Differentiate between high level language and low
level programming language.
6. Why second generation of computer is better than first generation. Differentiate between
third generation and forth generation of computer
Chapter 3
Variables and data types
1. Describe with example the different types of operators available in C.
2. What is ternary operator? Explain it with flowchart and syntax.
3. Why we need different data types in programming? Differentiate between local and
global variables with suitable example.
4. What are the final values of a, b, c and x after execution of the following statements?
int x =10, a = 10, y = 11, z = 12;
X + = ++a - b++;
x - = ++ z % --b;
x *= ++a + b++ * z -- ;
5. Given the code below write the output of the program.
#include<stdio.h>
#include<conio.h>
void main ( )
{
int x, y, z;
x = 3 ; y = 4 ; z = 5;
clrscr ( ) ;
printf ( “Given x = %d, y = %d, and z = %d, \n”, x, y, z) ;
x = + + x + y;
printf ( “ x = x + y assigns %d to x; \n”, x) ;
x = 6 ;
x + = y ;
printf ( “ x + = y assigns %d to x ; \n”, x) ;
x = 2;
z = z * x + y + + ;
printf ( “ z = z * x + y assigns %d to z; \n”, z) ;
z = 10 ;
z = z * (x + y) ;
printf ( “ z = z * (x + y) assigns %d to z ; \n”, z) ;
z = 10 ;
z * = x + y ;
printf ( “ z * = x + y assigns %d to z ; \n”, z) ;
z = 10 ;
Z * = x + y ;
printf ( “z * = x + y assigns %d to z ; \n”, z) ;
getch ( ) ;
}
Chapter 4
Control Structures
1. What do you mean by entry controlled an exit controlled loop? Explain different types of
looping constructs available in C with suitable examples.
2. Write a program in C to read temperature of 10 cities for a month (daily for 30 days).
Then calculate and display the average monthly temperature of each city.
3. Define "Nested Loop". Use the nested loop to calculate and display the multiplication
table from |X| =(1 to 12) X 12 = 144.
Menu
b) conversion of 0F temperature to 0C
and to perform task as per user's choice repeatedly until his/her choice is to exit.
8. Define nested looping. Write a program to generate all the possible combinations of
integer numbers 1, 2 and 3.
Income Tax
< Rs.10,000 Nil
Rs. 10,000 to Rs. 19,999 10%
Rs. 20,000 to Rs. 29,999 15%
Rs. 30,000 to Rs. 49,999 20%
>Rs.50,000 25%
Write a flow–chart and a program to compute tax amount when income
amount is given.
10. At which condition would you prefer switch statement in C? Explain switch statement
with suitable example.
11. Explain if, elseif, if..else,for,while,do..while with suitable example,flowchart and syntax.
(decision control mechanism and looping/iteration).
(Perform above task until the user wants to exit. Full marks is given if user-defined
functions are used)
main()
{
int k, a;
a = 10;
for(k=0; k<10; k++)
{
if(k%2 = =0)
a = a+k;
else
a = a–1;
printf("a=%d\n",a);
}
printf("\n the value of a = %d", a);
}
14. What do you mean by selective and repetitive statement? Why do we need break and
continue statement.
15. Write a program to find the terms in the given series till the term value is less than 250.
All users are also charged ‘meter charge’, which is equal to Rs. 50. Write a complete C
program to read the number of units consumed and print out the total charges.
j. To reverse it.
Cos x =
∞
(−1)n (2 n) = x2 x4
∑ (2 n !) x 1− + ............. .
2! 4 !
n=0
x 3 x5 x 7
Sin x= x− + − ............. .
3! 5 ! 7 !
22. WAP to display following series.
a. 1,11,111,1111,11111
c. 1,121,12321,1234321…
Chapter 5
Arrays and Strings
1. Why array is important in programming? How can you initialize different types of arrays?
Explain 2-dimensional array in C.
2. Define String. Write a program to read n employees names and display them in
alphabetical order.
3. How different types of array are initialized? Explain it with suitable example.
f. Transpose it.
7. WAP to read two m X n matrix and find their sum and product.
8. WAP to read n element matrix and sort them in ascending and descending order.
9. WAP to search supplied number in one dimensional and two dimensional matrix.
11. Write a program that asks a user for a number and finds out if the number is present in
the 2D array given below:
Example pattern
1N
2EE
3PPP
4 AAAA
5LLLLL
13. WAP to read n element array and find sum of smallest and largest element of matrix.
17. Write a C program to read a string and display only vowels of that string.
18. Write a C program to read a string and count vowels and consonant separately of that
string.
19. Write a program to insert a given character at the given array index of a given string. For
example if the given string is “Gnesh”, given character is ‘a’, and the given array index is
1, the resulting string should be “Ganesh”.
20. Write a program to read a message and print changing the uppercase alphabets to
lowercase and vice-versa.
Chapter 6
Functions
1. What is recursive function? Write a recursive program to generate the first 15 numbers
of Fibonacci sequence.
2. What do you mean by storage class? Define its types with suitable examples.
3. Explain how function can be used to write concise programming and also differentiate
between macros and function.
11. Differentiate between macro and function with the help of examples.
12. Write a program with user defined function using pointer to convert all the upper
case to lower case and vice-versa in a string given by the user .
13. Write a program with user defined function using pointer to convert all the upper
case to lower case and vice-versa in a string given by the user .
14. Write the output.
#include<stdio.h>
#include<conio.h>
fun(int p);
void main()
{
int x=4, y;
clrscr();
printf(“%d \n”, x);
y=fun(x);
printf(“y=%d \n”,y);
getch();
}
fun(int p)
{
return (2*p/12+13);
}
15. Write a program with user defined function using pointer to convert all the upper
case to lower case and vice-versa in a string given by the user .
16. Define prototype. Show its example.
17. Write a program to find the sum of all prime numbers in a given array. The main function
of your program should take the help of a user defined function that tests whether a
given number is prime or not.
Chapter 7
Pointers
1. What are the advantages of function call-by -* reference over call-by-value? How would
you pass a variable by reference to a function? Give an example.
2. What is Pointer? How does a pointer differ from an array? Explain dynamic memory
allocation.
3. Define pointer and show how pointers can be used to return more than one values from
a function.
4. Write a program with user defined function using pointers to convert all the upper- case
letters to lower-case and vice versa in a string given by the user.
For example: The C pRogramming.
tHE c PrOGRAMMING.
5. Write a program to sort (ascending order) n integer values in an array using pointer.
6. Why do we need dynamic memory allocation? How it is achieved? Explain it with
suitable example.
7. What is memory leak? Write a program to print reverse elements of an array using
Dynamic Memory Allocation.
8. Find output
a.
void main()
{
int a=9 , b=4, d;
printf(" a: %d b: %d \ n", a , b);
printf(" sum: %d", func(&a,b));
}
int func(int *y, int x)
{
return (++*y + (++x) );
}
b.
#include<stdio.h>
void main()
{
int i, j;
char str[]="POINTER";
clrscr();
for(i=0;str[i]!='\0';i++)
{
for(j=0;j<=i;j++)
{
printf("%c",str[j]);
printf("\n");
}
}
}
c.
#include<stdio.h>
void disp(int*n);
void main ()
{
int i;
int marks [ ]={15,16,17,18,19,20,21,22,23,24};
disp(marks);
}
9. What is the difference between array of pointers and pointer to arrays? Explain with
examples.
10. Define pointer variable. What are the advantages of using pointer in a function?
11. Explain malloc, calloc, realloc and free functions with their syntax and meaning.
12. Can function return multiple values? If so, how?
13. What is double indirection? Show its example.
14. What does the following mean
- int *p
- int *p[10]
- int (*p)[10]
- int (*p) (void)
- int *p (char *a)
Chapter 8
Structure
1. What is nested structure? When would you use nested structure?
2. Create a structure called book having member name, price, author and published date in
day, month and year. Write a program to read 100 books information from the user and
display those books having price is greater than 250.
3. What difference between Structure and Union. Write about the storage space (in byte) of
they have same definition.
Like –
Struct a Union a
{ {
int i; int i;
}; };
6. How structure is passed while calling function? Explain it with suitable example.
7. What is structure? Explain its components. How can you access the members of a
structure?
Chapter 9
File Handling
1. A car company requires that records should be kept in stated format.
Write an EFFICIENT program to read 4 sets of such data and store in a data file.
2. Describe the rules governing the use of fopen function. What information is returned by
it? Also describe about file pointer.
3. Write a program to read information of 10 students in 4 subjects, store in a file and print
the result:
EEMC
Name C BEE MTH CT Total
John 88 78 98 87 --
Beecky 78 65 45 23 --
------- ---- ---- ---- ---- ----
4. What is a FILE pointer? Write a program to create a structure for customers in a Shop of
the following data:
Read 100 customers from a file customer.dat and display the information of the
customers who is greater than Rs 1000.
6. Describe file handling functions fopen, fprintf, fscanf, fclose with their syntax and
meaning.
Write a program to create”student.txt” file to store the above records for 100 students.
Also display these records of students who are not from Pokhara.