Google Interview Question
Country: United States
Hmmm, the question says no for or while loops, but what about do-while? :-)
#include <stdio.h>
void printAscii() {
int i = 0x20;
do {
putchar(i++);
} while (i < 0x80);
putchar('\n');
}
// Use recursion
#include<iostream>
using namespace std;
void printAscii(int x){
if(x == 129)
return;
cout<< (char) x << " " ;
x = x+1;
printAscii(x);
}
int main(){
int x = 0;
printAscii(x);
return 0;
}
Same implementation as below in Java
}
- roshenw January 28, 2015