Personalized Analytics only Availble for Logged in users

Analytics below shows your performance in various Mocks on PrepInsta

Your average Analytics for this Quiz

Rank

-

Percentile

0%

Get over 200+ Courses under One Subscription

mute

Don’t settle Learn from the Best with PrepInsta Prime Subscription

Learn from Top 1%

One Subscription, For Everything

The new cool way of learning and upskilling -

Limitless Learning

One Subscription access everything

Job Assistance

Get Access to PrepInsta Prime

Top Faculty

from FAANG/IITs/TOP MNC's

Get over 200+ course One Subscription

Courses like AI/ML, Cloud Computing, Ethical Hacking, C, C++, Java, Python, DSA (All Languages), Competitive Coding (All Languages), TCS, Infosys, Wipro, Amazon, DBMS, SQL and others.

Comments

29 comments on “Quiz-2”


  • Bablu

    for (int x = 10; x >= 0; x–) {

    int z = x & (x >> 1);

    if (z)

    printf(“%d “, x);
    ans:-10, 9,8


  • Bablu

    x=3

    y=90

    while(y>0):

    y=y//3

    x=x+6

    c=x+y

    while(c>30):

    if(c % 3 == 0):

    print(x)

    else:

    print (y)

    c=c//5

    print(c)
    sir in this how we get c value 33


  • Divya

    CAN ANYONE PLEASE EXPLAIN THIS
    #include

    using namespace std;

    int main()

    {

    for (int x = 10; x >= 0; x–) {

    int z = x & (x >> 1);

    if (z)

    printf(“%d “, x);

    }

    }


  • VINAYKUMAR

    #include
    using namespace std;
    int main()
    {
    for (int x = 10; x >= 0; x–) {
    int z = x & (x >> 1);
    if (z)
    printf(“%d “, x);
    }
    }
    please any one explain and x>>1 value


  • Sourik

    Please provide the detailed solution of this code:
    Integer x,y,z
    Set x=3
    Set y=90
    while(y is greater than 0);
    y=y/3
    x=x+6
    c=x+y
    while(c is greater than 30):
    if(c mod 3 is equals to 0):
    Write x
    else:
    Write y
    c=c/5
    Write c


    • ARNAB

      As their is no option to attach picture I will paste the code and output here, Just go through this you will understand. For better clarification you can execute the code by yourself.
      code:
      int main(){

      int x,y,z,c;
      x=3;
      y=90;

      while(y>0){

      y=y/3;
      printf(“y (1st while loop)=%d //understanding purpose\n”,y);

      x=x+6;
      printf(“x (1st while loop)=%d //understanding purpose\n”,x);

      c=x+y;
      printf(“c (1st while loop)=%d //understanding purpose\n”,c);

      while(c > 30){

      if(c % 3 == 0){

      printf(“x (2nd while loop)=%d // take as an final output\n”,x);}

      else{

      printf(“y (2nd while loop)=%d // take as an final output\n”,y);}

      c=c/5;}
      }
      printf(“c (final value)=%d // take as an final output”,c);
      return 0;}

      Output:
      y (1st while loop)=30 //understanding purpose
      x (1st while loop)=9 //understanding purpose
      c (1st while loop)=39 //understanding purpose
      x (2nd while loop)=9 // take as an final output
      y (1st while loop)=10 //understanding purpose
      x (1st while loop)=15 //understanding purpose
      c (1st while loop)=25 //understanding purpose
      y (1st while loop)=3 //understanding purpose
      x (1st while loop)=21 //understanding purpose
      c (1st while loop)=24 //understanding purpose
      y (1st while loop)=1 //understanding purpose
      x (1st while loop)=27 //understanding purpose
      c (1st while loop)=28 //understanding purpose
      y (1st while loop)=0 //understanding purpose
      x (1st while loop)=33 //understanding purpose
      c (1st while loop)=33 //understanding purpose
      x (2nd while loop)=33 // take as an final output
      c (final value)=6 // take as an final output

      *Just follow when which loop got executed.


  • prajakta

    Set x = 1
    Set n = 200
    while(n>100):
    x=x-n
    n=n-5
    end while
    Write x
    Is there any trick that could solve the problem faster?


    • Sagar

      Use the A.P summation formula , Sum = n/2(first term + Last term)…… where last term =200 and first term =105.
      n=20 bcoz there are total 20 nos. which are multiple of 5 between 100 and 200(exlcluding 100). Sum will come out to be 3050 and then subtract it by 1 bcoz x initial value was 1. The answer will be -3049


  • Sourik

    Please explain this code in details:
    Integer a,b,c
    Set a=6,b=84
    while(b>0)
    b=b/2
    a=a+6
    c=a+b
    while(c>40)
    if(c mod 2 IS EQUAL TO 0)
    Print a
    else
    Print b
    c=c/10
    End while
    End while
    Print c


    • HelpPrepInsta

      Hey Sourik, it’ll be a bit tricky, we’ll try to explain it step by step, lets start
      initially a=6 , b=84
      compiler will enter while loop
      1st iteration – b=42 , a=12, c= a+b = 54(compiler will enter 2nd while loop)
      (if condition gets true) – it will print a = 12
      2nd iteration – b=21, a=18, c= a+b = 39(compiler will not enter 2nd while loop)
      3rd iteration – b=10, a=24, c= a+b = 34(compiler will not enter 2nd while loop)
      4th iteration – b=5, a=10, c= a+b = 35(compiler will not enter 2nd while loop)
      5th iteration – b=2, a=36, c= a+b = 38(compiler will not enter 2nd while loop)
      6th iteration – b=1, a=42, c= a+b = 43(compiler will enter 2nd while loop)
      (if condition gets false), else will be executed and it will print b – 1
      now, c=c/10, that makes c=4
      7th iteration – b=0, a=48, c= a+b = 48(compiler will enter 2nd while loop)
      (if condition gets true), it will print a – 48
      now, c=c/10, that makes c=4
      compiler get out of both the while loops
      it will print c – that is 4
      Hence the output will be
      12 1 48 4
      We hope, this will solve out your queries


      • swarup

        In your given solution in the 7th iteration – b=0
        But according to the question the first loop can only run while (b>0) and hence it should not run in that case only, so how is the 7th iteration even possible?


        • HelpPrepInsta

          The value of b decreases to zero in the 7th iteration, that’s why there is no 8th iteration.


        • 27_Devyani

          x=3

          y=90

          while(y>0):

          y=y//3

          x=x+6

          c=x+y

          while(c>30):

          if(c % 3 == 0):

          print(x)

          else:

          print (y)

          c=c//5

          print(c)
          Plz explain the code solution in detail my answer is not matching with the given options


  • Riya

    Integer a,b,c
    Set a=6,b=84
    while(b>0)
    b=b/2
    a=a+6
    c=a+b
    while(c>40)
    if(c mod 2 IS EQUAL TO 0)
    Print a
    else
    Print b
    c=c/10
    End while
    End while
    Print c
    Can you provide the detailed solution?


    • HelpPrepInsta

      Hey Riya, lets start
      initially a=6 , b=84
      compiler will enter while loop
      1st iteration – b=42 , a=12, c= a+b = 54(compiler will enter 2nd while loop)
      (if condition gets true) – it will print a = 12
      2nd iteration – b=21, a=18, c= a+b = 39(compiler will not enter 2nd while loop)
      3rd iteration – b=10, a=24, c= a+b = 34(compiler will not enter 2nd while loop)
      4th iteration – b=5, a=10, c= a+b = 35(compiler will not enter 2nd while loop)
      5th iteration – b=2, a=36, c= a+b = 38(compiler will not enter 2nd while loop)
      6th iteration – b=1, a=42, c= a+b = 43(compiler will enter 2nd while loop)
      (if condition gets false), else will be executed and it will print b – 1
      now, c=c/10, that makes c=4
      7th iteration – b=0, a=48, c= a+b = 48(compiler will enter 2nd while loop)
      (if condition gets true), it will print a – 48
      now, c=c/10, that makes c=4
      compiler get out of both the while loops
      it will print c – that is 4
      Hence the output will be
      12 1 48 4
      We hope, this will solve out your queries


      • Tamaghna

        why i the output 12 1 48 4 hen only 4 should be printed right because on 7th iteration we are getting out of the while loops


  • Darshna

    Set x to 0;
    Set n to 1;
    while(n<=100)
    x=x+n;
    n=n+1;
    end while
    write x

    In the above question, counting the value of n = 1 to <= 100 will be a lot of time taking during the exam time, is there any trick that could solve the problem faster?


    • HelpPrepInsta

      Hey Darshna, yes sure there is an alternative method, you can use the formula n(n+1)/2, and get the value of x pretty much faster than the orthodox way


  • Kriti

    Please provide a detailed explanation of this code.
    Integer array1[10] = {2, 3, 56, 34}

    Integer k, a, j, n

    Set a = 3, n = 4

    for(each k from 0 to n-1)

    Set array1[n] = array1[0]

    for(each j from 0 to n-1)

    Set array1[j] = array1[j+1]

    End for

    End for

    for(each k from 0 to n-1)

    Print array1[k]

    End for


    • HelpPrepInsta

      Hey Kriti, this code is simply for confusing the students, but its output is pretty simple.
      There are two for loops in the program, the inner for loop is changing the order of the elements of the array everytime
      Like on executing the first time the array will be {3, 56, 34 , 2}
      On executing the second time the array will be {56, 34 , 2 , 3}
      On executing the third time the array will be {34 , 2 , 3, 56}
      On executing for the fourth and last time the array will be { 2 , 3, 56 , 34}
      Hence the array becomes the same after coming out both the for loops, and that’s why when you are printing the array for the final time, it will give you the same output, as the input


    • HelpPrepInsta

      Hey Kartheekh, each mock test consits of 10 questions, please try to open the other mock tests, there you’ll find more questions


  • Dinesh

    3-What will be the output of the following pseudocode?
    Integer a,b,c
    Set a=6,b=84
    while(b>0)
    b=b/2
    a=a+6
    c=a+b
    while(c>40)
    if(c mod 2 IS EQUAL TO 0)
    Print a
    else
    Print b
    c=c/10
    End while
    End while
    Print c
    Please explain this question