Computing Basics Interview Questions

  1. Use recursion to write a function that determines the length of a string
    int strlen(char * str) {
      if (str[0] == 0)
        return 0;
      return 1 + strlen(str + 1);
    }
  2. What’s the number after F in hexadecimal?0x10
  3. Bitwise: what is 7 | 1? 7 & 1? ~7?

    7 (0111). 1 (0001). -8 (1000).

  4. Write a script that prints the numbers from 1 to 100. But for multiples of four print “Four” instead of the number and for the multiples of seven print “Seven”. For numbers which are multiples of both four and seven print “FourSeven”.
    for (int ii = 1; ii <= 100; ii++) {
    	boolean isMultipleOfFour = (ii % 4 == 0);
    	boolean isMultipleOfSeven = (ii % 7 == 0);
    	if (isMultipleOfFour && isMultipleOfSeven)
    		System.out.println("FourSeven");
     	else if (isMultipleOfFour)
    		System.out.println("Four");
     	else if (isMultipleOfSeven)
     		System.out.println("Seven");
    	else
    		System.out.println(ii);
    }

Leave a Reply

Your email address will not be published. Required fields are marked *