Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Topics :
• Loops
• Variables
• Command line Arguments
• Data Structure and Algorithm
• Array
• Data Types
• Functions
• Scope
• Recursion & Iteration
• File Handling
• Trees
• Graphs
• Linked List
• Stack & Queues
• Registers
Today’s Topic
• Loops
• Variables
• Command line Arguments
• Data Structure and Algorithm
• Array
How do you print ‘hello’ without “;”
#include <stdio.h>
int main(){
if(printf(“hello”)){
}
}
QUESTION: 01
void main()
{ OPTIONS:
for(int i=0; i<=3; i++)
A. 0 1 2
{
if(i == 2) B. No output
break;
C. 0 1 2 3
printf(“%d”,i);
} D. 0 1
}
OUTPUT: D
QUESTION: 02
void main ()
OPTIONS:
{ A. Garbage Value
B. 5
int arr[10] = { 1,2,3,4,5};
C. 6
printf(“%d”,arr[5]); D. 0
}
OUTPUT: D
QUESTION: 03
#include <stdio.h>
int main() OPTIONS:
{ A. Yes
int i = 1; B. No
if (i++ && (i == 1)) C. Depends on the compiler
printf("Yes\n"); D. Depends on the standard
else
printf("No\n");
}
OUTPUT: B
QUESTION: 05
int main( )
OPTIONS:
{
A. 5
int i;
B. 0 1 2 3 4 5 6 7 8 9
for(i=0; i< 10; i++){
C. 0 1 2 3 4 6 7 8 9
if(i == 5)
D. 0 1 2 3 4 5
continue;
OUTPUT: C
printf(“%d”,i);
}
return 0; }
QUESTION: 06
OPTIONS:
A. Dynamic Algorithm
B. Greedy Algorithm
C. Recursive Approach
D. Divide & Conquer
OUTPUT: B
QUESTION: 07
#include <stdio.h>
OPTIONS:
int main(){
A. 0, 4, 2, 1
int a = -1, b = 4, c = 1, d;
B. 0, 5, 2, 1
d = ++a && ++b || ++c;
C. -1, 4, 1, 1
printf("%d, %d, %d, %d\n", a, b, c, d);
D. 0, 5, 1, 0
return 0;
}
OUTPUT: A
QUESTION: 08
OUTPUT: D
QUESTION: 09
OUTPUT: D
QUESTION: 10
OPTIONS:
A. n
B. n - 1
C. n + 1
D. 2n
OUTPUT: B
QUESTION: 12
OPTIONS:
A. Best case
B. Average case
C. Worst case
D. NULL case
OUTPUT: B
QUESTION: 13
OUTPUT: C
POINTERS
int i = 5; i = 15;
printf("%x\n",p); }
printf("%x\n",pp);
printf("%x\n",*pp);
printf("%x\n",**pp);
QUESTION: 15
#include <stdio.h>
int main(void) { OPTIONS:
int i = 10; A. 90
int j = 20; B. 10
int *p = &i; C. Error
int **pp = &p; D. 20
**pp = 90;
p = &j;
printf("%d", **pp);
return 0; OUTPUT: D
}
QUESTION: 16
#include <stdio.h>
int main(void) { OPTIONS:
int i = 10; A. 90
int j = 20; B. 10
int *p = &i; C. Error
int **pp = &p; D. 20
**pp = 90;
p = NULL;
printf("%d", **pp);
return 0; OUTPUT: C
}
QUESTION: 17
#include<stdio.h>
int main() {
OPTIONS:
int a = 6; A. 6
int *p = &a; B. 7
(*p)++; C. 0
printf("%d", *p); D. error
return 0;
}
OUTPUT: B
QUESTION: 18
#include<stdio.h>
int main() { OPTIONS:
int a = 6; A. 7 10
int *p = &a; B. 7 11
(*p)++; C. 10 10
int j = 10; D. 6 11
p = &j;
printf("%d %d", a, *p);
return 0;
} OUTPUT: A
QUESTION: 19
Given an array of positive integers, rearrange the array alternately i.e first element
should be maximum value, second minimum value, third second max, fourth second
min and so on.
Example:
Input Array (First number is Number of elements)
123456789
Modified Array (Output)
9 1 8 2 7 3 6 4 5
Program: 01
Constraints:
N>0
Sample Input
12346
Sample Output
61423
SOLUTION
#include <stdio.h>
int main() OPTIONS:
{ A. -1 -3
int i=0; B. 1 2 3
for(i++; i<4;i++) C. -2 -3 -4
{ D. Compilation error
printf("%d",~i);
}
}
OUTPUT: C
QUESTION: 24
int main(){
int i = 0; OPTIONS:
while (i < 2){ A. In while loop After loop
if (i == 1) B. After loop
break; C. In while loop In while loop After loop
i++; D. In while loop
if (i == 1)
continue;
printf("In while loop");
} OUTPUT: B
printf("After loop");
}
QUESTION: 25
OUTPUT: D
QUESTION: 30
void main ()
{ OPTIONS:
int a[5] = {5,1,15,20,25}; A. 3,2,15
int i,j,m; B. 2,3,20
i=++a[1]; C. 2,1,15
j=a[1]++; D. 1,2,5
m=a[i++];
printf("%d %d %d",i,j,m);
}
OUTPUT: A
QUESTION: 28
int main()
{ OPTIONS:
int val = 1; A. 25
do { B. 50
val++; C. 12
++val; D. 4
} while (val++ > 25);
printf("%d\n", val);
return 0;
} OUTPUT: D
QUESTION: 22
ANSWER: A
QUESTION: 29
int i = 5;
if( i ){ OPTIONS:
printf("Hello, World! \n");
A. Hello, World!
}
else B. Bye, World!
{
C. error
printf(“Bye, World! \n");
} D. No output
OUTPUT: A
QUESTION: 21
OPTIONS:
A. greedy programming
B. dynamic programming
C. divide and conquer
D. none of the above
OUTPUT: B
QUESTION: 31
void main ()
{ OPTIONS:
char str1[ ] =“abcd”; A. Equal
B. Unequal
char str2[ ] = “abcd”; C. Error
if(str1 == str2) D. None of these
printf(“Equal”);
else
printf(“unequal”); OUTPUT: B
}
QUESTION: 32
#include <stdio.h>
int main() OPTIONS:
{ A. 0
int x = 2, y = 0; B. 1
int z = x && y = 1; C. Compile time error
printf("%d\n", z); D. 2
}
OUTPUT: C
QUESTION: 33
int i = 0;
if( i ){ OPTIONS:
printf("Hello, World! \n");
A. Hello, World!
}
else{ B. Bye, World!
printf(“Bye, World! \n");
C. error
}
D. No output
OUTPUT: B
QUESTION: 34
int i = 5;
if( i == 15 ); OPTIONS:
{
A. Hello, World!
printf("Hello, World! \n");
} B. Bye, World!
C. error
D. No output
OUTPUT: A
QUESTION: 35
OUTPUT: A
QUESTION: 36
ANSWER: D
QUESTION: 39
OUTPUT: C
QUESTION: 40
#include <stdio.h>
int main() OPTIONS:
{ A. 2
int y = 2; B. 12
int z = (y = 10)+y; C. 20
printf("%d\n", z); D. error
}
OUTPUT: C
QUESTION: 41
#include <stdio.h>
int main() OPTIONS:
{ A. 2
int y = 2; B. 12
int z = y+(y=10); C. 20
printf("%d\n", z); D. error
}
OUTPUT: C
QUESTION: 42
OUTPUT: B
QUESTION: 43
What will be the output of the following program if argument passed to command lines
are : prog 1 4 2
#include<stdio.h>
int main(int argc, char *argv[])
{ OPTIONS:
int j; a) Error
j = argv[1] + argv[2] – argv[3]; b)3
printf(“%d”, j); c)Garbage Value
return 0; d)None of these
} OUTPUT: a
QUESTION: 42
OUTPUT: b
QUESTION: 38
int main()
default: printf("Choice other than 1,
{
2 and 3");
int x = 2;
break;
switch (x)
}
{
return 0;
case 1: printf("Choice is 1");
}
break;
case 2: printf("Choice is 2");
break; OUTPUT: Choice is 2
case 3: printf("Choice is 3");
break;
QUESTION: 42
a)File Name
b)Program Designation
c)argument passed by user
d)Program Name
OUTPUT: A
QUESTION: 37
#include <stdio.h>
void main(){ OPTIONS:
int h = 8; A. 9
int b = h++ + h++ + h++; B. 10
printf("%d\n", h); C. 12
} D. 11
OUTPUT: D
Program: 02
Given n doors and n persons. The doors are numbered from 1 to n and persons are
given id’s numbered from 1 to n. Each door can have only two statuses ie open (1)
or closed (0). Initially, all the doors have status closed.
Find the final status of the door which is mentioned, when all the persons have
changed the status of the doors of which they are authorized. i.e. if status " open "
then change the status to closed and vice versa. A person with id ‘i’ is authorized to
change the status of the door numbered ‘j’ if ‘j’ is a multiple of ‘i’.
● Note: A person has to change the current status of all the doors for which he is
authorized exactly open
Program: 02
import java.util.Scanner; for(int i=2; i<n; i++)
public class Toggle { {
public static void main(String[] args) { if(n%i==0)
{
System.out.println("enter the number");
fact++;
Scanner sc=new Scanner(System.in); }
int n=sc.nextInt(); }
if( n==1) if( fact%2==0)
{ {
System.out.println("open"); System.out.println("closed");
} }
else
else{
System.out.println("open");
int fact=2; }}
}
THANK YOU