EMC Interview Question for Software Engineer in Tests


Team: RSA
Country: India
Interview Type: Written Test




Comment hidden because of low score. Click to expand.
5
of 5 vote

call as print(500)

void print(int a)
{
       if(a)
       {
             print(a-1);
             printf("%d\n",a);
       }
}

- bidhan.cstbesus June 02, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
4
of 6 vote

void func()
{ 
    static int a =1;
    cout<<a++<<" ";
    if(a<=500) func();
}

- Roshan Mangal June 02, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
-2
of 2 votes

Recursive calls are considered to be implicit loops, so this is not a solution that meets the constraints (w/o loops)

- ashot madatyan June 04, 2012 | Flag
Comment hidden because of low score. Click to expand.
1
of 1 vote

Just about everything is an implicit loop of some kind. What other solutions are we to offer? We could have a C++ constructor that increments a global variable each time it runs and then create an array of 500 such objects, like: public Foo() { i++; cout << i; cout << endl; } Foo myFoo[500]; That would also be an implicit loop. If we deny every "implicit loop", we're going to have to go with cout << 1; cout << 2; cout << 3; ... hehe

I think recursion was probably the expected solution.

- eugene.yarovoi June 14, 2012 | Flag
Comment hidden because of low score. Click to expand.
1
of 1 vote

public class Print1To500WithoutLoop {

	public static boolean printNums(int n)
	{
		System.out.println(n);
		n++;
		boolean a=n!=501 && printNums(n);
		return true;
	}
	
	public static void main(String[] args)
	{
		printNums(1);
	}
}

- teli.vaibhav July 01, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

for this u can write a recursive function

- Raunak June 02, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

use recursion
void func (int n) {
if (n==0) {
return;
func(n-1);
System.out.println(n);
}

- Achilles June 03, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

This is a double posted question. Please see my solution at the link below:
question?id=13786675

- ashot madatyan June 04, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

* Write a C++ class
* Declare a static variable say count=1
* In the constructor print count and increment it by 1

In the driver program just instantiate this class by assigning an array of N items
1 - N items will be printed automatically

- salvo4u June 04, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

#include<iostream>

using namespace std;
int check(int n)
{
int temp;
if(n==0)
{
return(0);
}
temp=n-1;
check(temp);
cout<<n<<endl;
return(0);
}
int main()
{
check(5);
return(0);
}

- Vineet Setia June 04, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

/**
* Without using loops, write a function to
* print 1 to 500 in serial order.
**/
public class RecursionExample {

public void recursion(int num) {
int i = 501-num;
System.out.print(i+" ");
if (num > 1) {
recursion(num-1);
}
}
public static void main(String[] args) {
// TODO Auto-generated method stub
RecursionExample re = new RecursionExample();
re.recursion(500);
}
}

- VSReddy July 02, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Use template metaprogramming.

- Aashish July 02, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

You and your template metaprogramming :)

- eugene.yarovoi July 08, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

public static void main(String[] args)
{
incrementVal(1);
}

private static void incrementVal(int i)
{
if(i <= 500)
{
System.out.println(i++);
incrementVal(i);
}
}

- Jacob March 24, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public class test {
public static void main(String[] args) {
int num = 500;
print(500);
}
public static void print(int n) {
if(n == 0) {
return;
}
System.out.println(n);
print(n-1);
}
}

- Anonymous April 06, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

int func1(int i) {
    printf("%d\n", i);
    return ((i++ > 499) ? 0 : func1(i));
}

func1(0);

- codedamo August 04, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Without loops, print 500 consecutive numbers? Recursion NOT allowed.

The answer is so simple :)

printf("1,2,3,4,5...498,499,500");

- devsathish August 12, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
-1
of 1 vote

Here is the pseudo code that works with the MPLAB v8.83 & XC16 Compiler from Microchip:

#include <p30fxxxx.h>
#include <stdint.h>
#include <stdio.h>
#include <string.h>

int functer (int z)
{
       while(z<=500)
       {
			printf("%d\n",z++);
			functer (z);
       }
		exit(0x0);
}

int main (void)
{
	volatile int ze; 
	functer(0x1);
	return ze; 
}

- amit.shali June 26, 2012 | Flag Reply


Add a Comment
Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More

Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More