Tuesday, 12 June 2018

ch-4 Loop


MCQ

1  How many times "IndiaBIX" is get printed?
int main()
{
 int x;
 for(x=-1; x<=10; x++)
 {
 if(x < 5)
 continue;
 else
 break;
 printf("IndiaBIX");
 }
 return 0;
}
A) Infinite times
B) 11 times
C) 0 times
D) 10 times

2  How many times is a do while loop guaranteed to loop?
A) 0
B) Infinitely
C) 1
D) Variable

3  How many times "INDIA" will get printed?
 #include<stdio.h>
 int main()
 {
 int x;
 for(x=-1; x<=10; x++)
 {
 if(x < 5)
 continue;
 else
 break;
 printf("INDIA");
 }
 return 0;
 }
A) Infinite times
B) 11 times
C) 0 times
D) 10 times

4  Which code will print k 20 times?
A) for (i=1; i < 20; i++)
 printf (“k”);
B) for (i=1; i = 20; i++)
 printf (“k”);
C) for (i=0; i < 20; i++)
 printf (“k”);
D) for (i=0; i <= 20; i++)
 printf (“k”);

5 What is the final value of x when the code int x; for(x=0; x<10; x++) {} is executed?
A) 10
B) 9
C) 0
D) 1

6 Which of the following is not an infinite loop?
A) for (i = 1; i < 10; i--)
 printf("%d", i);
B) while (i <= 10) { // Assume i is initialized to 1
 printf("%d", i);
 if (i = = 3)
 continue;
 if (i = = 6)
 break;
 i++;
 }

C) do { // Assume i is initialized to 1
 printf("%d", i);
 if (i = = 3)
 continue;
 if (i = = 6)
 break;
 i++;
 }
 while (i <= 10);
D) while (i <= 10) { // Assume i is initialized to 1
 printf("%d", i);
 if (i = = 6)
 continue;
 if (i = = 3)
 break;
 i++;
 }

7.  How many times "DOEACC" will get printed?
#include<stdio.h>
int main()
{
 int x;
 for(x=-1; x<=10; x++)
 {
 if(x < 5)
 continue;
 else
 break;
 printf("DOEACC");
 }
 return 0;
}
A) Infinite times
B) 11 times
C) 0 times
D) 10 times

8 For the program given below, which of the following statement is correct?
void main ( )
{
int i;
for(;scanf(“%d”.&i);
printf(“%d”,i))
;
}
A) The for loop would not get executed at all.
B) The for loop would get executed only once.
C) The for loop would get executed 5 times.
D) The for loop would get executed infinite times.


9 how many time the printf statement within the while loop will be executed
x=1;
while(x=0)
printf("hello");

a 1
b 0
c infinite
d 2

10 how many time  loop will be executed
int main
{
int i=0;
for(;;)
printf("%d",i);
return 0;
}

a  0 times
b  infinite time
c  10 times
d  1 times

11  The do…while looping statement
A) is executed only once if the condition is true.
B) is also known as entry-controlled loop.
C) is executed at least once if the condition is false.
D) is unconditional looping statement..

12  What will be the output of the following program?
Main()
{
int x = 5;
While ( x = = 1)
 x = x -1;
 printf ( “ %d\n”, x);
}
A) 5
B) 4
C) 0
D) syntax error

13  What will be the output of the following program?

main()
{
int x = 5;
 While ( x != 1)
 x = x -1;
 printf ( “ %d\n”, x);
}
A) 5
B) 1
C) 2
D) syntax error


1.1 Which of the following is not an unconditional control statement in ‘C’?
A) break
B) continue
C) exit()
D) while

True or False
    
    1.    while (0); is an infinite loop
   
    2.   While loop is post tested loop.
        .
    3.    A continue statement must be enclosed in a loop.
   
    4.   for(i=0; i<5;i++);statement has syntax error because of semicolon at the end. 
   
    5.   A break statement is used to exit from a statement block in a switch statement.
    
    6.   A ‘for’ loop in ‘C’ has three statements, namely, assignment, test and increment statements.
   
    
    
   r.
Fill in the blanks(A)
A.       
header
B.       
{}
C.       
relational
D.       
Ctype.h
E.        
break
F.        
AND
G.      
&&
H.       
Stdio.h
I.         
infinite
J.         
break
K.       
goto
L.        
Do…while
M.     
exit
N.      
double
O.      
Header file
P.       
ctype

    1.       ________ is logical AND operator and output of AND operation is TRUE if both the operands are true.
    2.       The ________ operators are used to compare the values of integers
    3.       The brackets used to mark the boundaries of a block are ________.
    4.       Relevant ________ files have to be included in a program for library functions to work.
5.       The ________ statement causes an exit from the innermost loop or switch.
6.       Name the header file to be included for the use of built in function isalnum() is ________.
7.       The ________ operator is true only when both the operands are true.
8.       By default a real number is treated as ________.
9.       Header file in which NULL macro is defined is ________.
10.   Avoid the use of ________ statement in the program.
11.   ________ loop is executed atleast once.
12.   If there is no test condition in a for loop then it becomes a(n) ________ loop.
13.   NULL is macro constant which has been defined in the heard file ________.
14.   A library function ________ causes an exit from the program in which it occurs.
15.    The ________ statement causes an exit from the innermost loop or switch.
16.   Name the header file to be included for the use of built in function isalnum() is ________ .
(B)
A.       
header
B.       
return
C.       
conditional
D.       
Right to left
E.        
goto
F.        
bit
G.      
preprocessor
H.       
Main()
I.         
0 and 1
J.         
void
K.       
text
L.        
register
M.     
stdout
N.      
multiply
O.      
gets
P.       
string


1.       ________ is an unconditional jump statement.
2.       The operator && is an example for ________ operator.
3.       The keyword used to transfer control from a function back to the calling function is ________.
4.        NULL macro is defined in ________ file.
5.       The line from which a program execution begins is ________.
6.       p++ has associativity ________.
7.       The standard file, in ‘C’, ________ is connected to screen.
8.       Ultimately, all data items processed by a computer are reduced to combinations of ________.
9.       If a function return type is declared as ________ it cannot return a value.
10.   A group of related characters that conveys meaning is called a ________.
11.     Most information stored in computer systems is stored in ________ files.
12.    The smallest data item a computer can process is called a ________.
13.   The ________ is a program that is executed before the source code is compiled.
14.   ________ is more appropriate for reading in a multi-word string.
15.   A Register variable is expected to be placed in machine ________.
16.    The operator i << 2 is equivalent to ________ i by 4.
(C)
A.       
Cpu register
B.       
Array of character
C.       
Logical operator
D.       
flowchart
E.        

F.        
1 byte
G.      
Stdio.h
H.       

I.         
goto
J.         

K.       

L.        
4/8
M.     

N.      

O.      
Return
P.       
void

1.       The variables of storage class register are stored in ________.
2.       Size of char data type is ________.
3.       In ‘C’, strings are stored in the form of ________.
4.       ________ breaks the normal sequential execution of the program.
5.        Ovals are used to represent starting and ending points in the ________.
6.        ________ are used when we want to test more than one condition and make decision.
7.       A float is ________ bytes wide, whereas a double is ________ bytes wide.
8.       The keyword used to transfer control from a called function back to the calling function is ________.
9.        If a function return type is declared as ________ it cannot return any value.
10.   Input/output function prototypes and macros are defined in ________.

Question
1.       Write program to generate multiplication table for first ‘n’ number, where ‘n’ is a user input.
2.       Write program to compute factorial .
3.      
4.        Write a program to generate the following patterns.     
   *
 * * *
5.        a) Write a program to calculate number of vowels (a, e, i, o, u) separately in the entered string. b) 
c) Draw a flowchart to print the factorials of numbers from 1 to n, where n is entered by user. (6+5+4)
6


7.       Differentiate between the following:  while and do..while loops

8. 
9.       What is the output of the following code segments?

       char a[] = "Hello", *p = a;
 while (*p != '\0')
printf("%s\n", p++);

10.    a) Write a C program to read a line and print it reverse.
 b) Write a C program to print given number of terms of a Fibonacci series.

 (5+5+5)
11.    Why we use do-while loop in C? Also give any properties which you know.
12.    a) A lucas sequence is given below:
 1, 3, 4, 7, 11, 18, 29

 The third number is sum of previous two numbers.
Write a program to print first 10 numbers of lucas sequence.
13.     Write a program to print the value of numbers in words when number entered is in the range of 0 to 999.
1
15.   Describe output of following program: #include main()
 {
 auto int i=10;
{
auto int i=5;
 printf(“%d”, i);
}
printf(“%d”, i+s);
 printf(“%d”,i);
    
   
        18 Draw a flowchart to print the factorials of numbers from 1 to n where n is entered by user
       19. Write a program to determine the sum of the following series: S = 1 – 3 + 5 – 7 + …n Read the    value of n from the user.
20 Write a program to display all the prime numbers between two positive integers m and n. The values of m and n are to be taken from the user

22 Write a ‘C’ program to count number of words in a string
23  Write a ‘C’ program to find the power of number using function.


26 Write a program to calculate number of vowels (a,e,i,o,u) separately in an entered string.

28 Write a ‘C’ program to computer the average of every third integer lying between 1 and 200? Include appropriate documentation
29 Write a program to calculate the income tax of an employee for the current financial year. A user will enter his age and Total salary of the current year and program will calculate and display the payable Income Tax from the given table.
For All Tax
Rs.0 to 2,00,000
0% of income
2,00,001 - 5,00,000
10% on income excess of 2,00,000
5,00,001 - 10,00,000
30,000+20% on income excess of 5,00,000
Above Rs.10,00,
000 1,30,000+30% on income excess of 10,00,000
For senior tax
For Senior Citizen
Tax
Rs.0 to 2,50,000
0% of income
2,50,001 - 5,00, 000
10% on income excess of 2,50,000
5,00,001 - 10,00,000
25,000+20% on income excess of 5,00,000
Above Rs.10,00,000 
1,25,000+30% on income excess of 10,00,000

31 Differentiate between do-while loop and while loop with the help of one example for each.

33  Make the flow chart to solve the following cosine series. S = 1 – x2 / 2! + x4 / 4! – x6 / 6! + … 100 terms
35 What are different storage classes in ‘C’? Explain each.
36 Write a program to compute the following series: x + x3 / 3! + x5 / 5! + …
37 Give an example of i) Switch statement ii) Conditional expression iii) Nesting of loops
38 Write a C program which calls a function to swap values of two variables.
39 Write and explain the action of WHILE statement. Develop a program in ‘C’ language to compute the average of every third integer number lying between 1 and 100. Include appropriate documentation.
40 Write a program which asks the user a number between 1 and 7 and prints the corresponding day of the week. (1: Sunday, 2: Monday, …)
41 WAP a program to print 10,9,8…………0
42 Write a program which asks for a integer from the user. It reverses the integer and prints “same” if after reversal the number is same as old number otherwise it prints “not same”.
43 Write a Program to count lines, words and characters with a definition that a word is any sequence of characters that does not contain a blank, tab or new line.
44 Write a program using function to read an array from the user and print the odd number at odd position and print s the even numbers at even positions. For example input array is 1 2 3 4 and output is 2 1 4 3.
45 List out the rules to declare a valid variable in ‘C’ program. Evaluate the following expression and show the hierarchy of operations: (2 + 4)/3 + 2 % 3 * 2 – 5
46 Explain the concept of structured programming in detail.
47 Write and explain the action of WHILE statement. Develop a program in ‘C’ language to compute the average of every third integer number lying between 1 and 100. Include appropriate documentation.
48  Develop a function to calculate sum of n even integers starting from a given even integer.
 49  Identify all the compound statements which appear in the following program segment:
{ sum=0; do{ scanf(“%d”, &i); if (i < 0) { i=-i; ++flag; } sum += i; } while (i != 0); }
50 Write an interactive ‘C’ program to evaluate the series: 1 – 1/2 + 1/3 – 1/4 …±1/n, where n is entered from keyboard.
51 Write a suitable ‘C’ program to print the following structure.
*
 **
 ***
 ****
*****
******
the number of rows should be input from the user.
52  a) Define Auto and Register variables in context of C. What is the basic difference between these variables?
b) Write a program that takes as input an integer between 1-12 (both inclusive) and prints the month corresponding to that integer.
 c) Draw two flow charts to distinguish between break and continue statements.
53 Write a program to find out whether a given number is Prime or not.
54. Write a ‘C’ program to computer the average of every third integer lying between 1 and 200?
18 Make the flow chart to solve the following cosine series. S = 1 – x2 / 2! + x4 / 4! – x6 / 6! + … 100 terms
35 a) Write a suitable ‘C’ program to print the following structure.
*
**
***
 ****
 *****
 ******
 the number of rows should be input from the user.

28 Write a program which asks for a integer from the user. It reverses the integer and prints “same” if after reversal the number is same as old number otherwise it prints “not same”

34 Write an interactive ‘C’ program to evaluate the series: 1 – 1/2 + 1/3 – 1/4 …±1/n, where n is entered from keyboard.


No comments:

Post a Comment

ch-12 File Handling

Mcq 1. What does fp point to in the program?   #include<stdio.h> int main() {   FILE *fp;   fp=fopen("trial",...