The Gateway to Computer Science Excellence
First time here? Checkout the FAQ!
x
672 views

Question 1: (8 marks)

Write a program to print the pattern below. Taking n as input, print n lines that print the pattern.

Sample input 1:
3

Sample output 1:
*    *
**  **
******

Sample input 2:
5

Sample output 2:
*        *
**      **
***    ***
****  ****
**********

 

Question 2: (12 marks)

The int datatype has a limitation of maximum value. It can only store values upto a certain limit. So what we want to do is take a very big integer and add 1 to it.

 

INPUT FORMAT:

First line contains number of digits in the integer, n. This is at maximum 50.

The next line consists of all the digits of the integer, separated by spaces.

You are required to add 1 to this integer and output the digits of the resulting integer (without spaces)

 

Sample input:
12
8 7 5 1 2 5 4 8 7 5 4 5

Sample output:
875125487546

 

Question 3: (8 marks)

Leap years are an interesting way of putting together lost time over the previous 4 years. These are those years when February has 29 days. One of your friends Raj was born on 29th of February. He wishes to know how many times till date he lived through his actual birthday (29th February). Take his birth year and present year as inputs and print the number of times he has experienced 29th of February. Note if present year is a leap year, do include its 29th of February as well. You may also display an error as “Birth Year is incorrect” if the birth year entered is not a leap year.

Note: Leap years are years which are multiples of 4 with the exception of years which are divisble by 100 but not by 400.

Sample input 1:
1996 2019

Sample output 1:
6

Sample input 2:
1997 2019

Sample output 2:
Birth year is incorrect

 

Question 4: (12 marks)

Sort an array in ascending order by flipping (exchanging) 2 adjacent integers not in the correct order until there is no such pair.

The leftmost swappable pair must be swapped first, i.e. the first pair encountered while going from left to right, which is in the opposite (descending order) should be swapped. Then the whole process should be repeated.

 

INPUT FORMAT:

First line contains 1 integer N denoting the number of integers in input. Next line contains N integers separated by spaces.

 

OUTPUT FORMAT:

For each flip performed, display the array in a line separated by spaces.

Sample input:
5
10 7 6 2 5

Sample output
10 7 6 2 5
7 10 6 2 5
7 6 10 2 5
6 7 10 2 5
6 7 2 10 5
6 2 7 10 5
2 6 7 10 5
2 6 7 5 10
2 6 5 7 10
2 5 6 7 10

 

Question 5: (12 marks)

In this question we’ll deal with Fibonacci series. The series is defined on whole numbers like fib(0), fib(1),… as follows:

fib(0) = 0

fib(1) = 1

fib(n) = fib(n-1) + fib(n-2), for n >= 2

 

INPUT FORMAT:

An integer N, 0 <= N <= 1000

 

OUTPUT FORMAT:

Add the unit digits of all the Fibonacci numbers from fib(0) to fib(N) and print only this sum

Sample Input:
8

Sample Output:
24

 

Question 6: (8 marks)

You are to write a program which takes 2 complex numbers as input and prints the sum and multiplication of the 2 complex numbers.

 

INPUT FORMAT:

The first and second lines contain 2 integers (the real and imaginary parts) for each complex number involved.

 

OUTPUT FORMAT:

The complex numbers sum and product on separate lines in the form a+bi or a-bi (depending on whether the complex part is negative or not).

Sample input:
1 2
1 3

Sample output:
2+5i
-5+5i
posted May 18 in Interview Experience by (149 points) | 672 views
6
Like
0
Love
0
Haha
0
Wow
0
Angry
0
Sad

11 Comments

For Question 1 Pattern Program 

#include<iostream>
using namespace std;
int main()
{
    int i,j,n;
    cin>>n;
    for(i=1;i<=n;i++)
       {

        for(j=1;j<=(2*n);j++)
    {
        if(j<=i||(j>=(2*n+1)-i))
            cout<<"*";
            else
            cout<<" ";
    }
    cout<<"\n";
    }
}

 

//question 6 sum and product of 2 complex number

#include <stdio.h>

int main(void) {
	 
    int r1,r2,i1,i2;
    
    scanf("%d",&r1);
    scanf("%d",&i1);
    scanf("%d",&r2);
    scanf("%d",&i2);
    
    //sum
    
    printf("%d+%di \n",r1+r2,i1+i2);
    
    
    //product
    int r=(r1*r2)-(i1*i2);
    int i=(r1*i2)+(r2*i1);
    printf("%d+%di",r,i);
    
	return 0;
}

 

//question 4 arrange by left swap first.
#include <stdio.h>
 
int main(void) {
	 
    int n,x[100],i,j,temp,k;
    scanf("%d",&n);
    
   for(i=0;i<n;i++)
   {
    scanf("%d",&x[i]);
    printf("%d ",x[i]);
   }
   
   printf("\n");
   
    
   for(k=1;k<=n-1;k++)
   {
     for(i=0;i<=k-1;i++)
      
      if(x[i]>x[i+1])
      {
          temp = x[i];
          x[i]=x[i+1];
          x[i+1]=temp;
          k--;
          
          for(j=0;j<n;j++)
          printf("%d ",x[j]);
          printf("\n");
         
          break;
      }
    }
    
    return 0;
}

 

This time questions were too easy. Many students got out of marks.
Allowed languages?

@toxicdesire Both C and C++ were allowed. I was there.

 

C and C++ were allowed (Compiler was g++ ). Only restriction was that STL was prohibited if C++ was used (atleast this is what they mentioned before they started the test, during the tutorial).
No such thing was mentioned to us. There was no restriction on the use of STL.
@kunal If you were in Software Lab 2, then you should have heard what that TA (who was wearing a Red and Blue striped Tshirt) mentioned: "You can use C++ but don't use Standard Template Library"
(To be honest, I have no idea how they would check whether someone used STL or not, but maybe few people who got 50+ didn't get shortlisted because they used STL (or maybe it was because of that bodhitree website's glitch) ? I don't know if this is the case though)
No restrictions. I did use vector at many places(although it wasn't needed). These problems didn't require STL anyway.

@d3ba If there would have been any restriction then they should have told so in all labs. However we were not told, that means STL is allowed. 

And many with 50+ were not selected bcoz the cutoff was too high (probably 55+ or maybe 60).. it has nothing to do with using of STL.

Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true
49,830 questions
54,806 answers
189,527 comments
80,817 users