next up previous
Next: Chapter 2 Up: Challenge CS Problems Previous: Challenge CS Problems

Chapter 1

1.
Print all prime numbers less than a given integer M.

2.
Given the array A[M] of M pairwsie different integers. Print all permutations of these integers.

3.
Input a real number A and a positive integer k. Compute and output Ak (A to the power k). You must not use functions that take a number to a power (such as pow()). The number k may be so large that performing k multiplications is impossible.

4.
In the following expression change each symbol  ? to one of +, -,  X , / so that the value of the resulting expression is equal 35 (division / confirms to the C rules of integer division, that is, the fractional part is discarded).


(((( 1  ? 2)  ? 3)  ? 4)  ? 5)  ? 6


It's enough to find only one solution.

5.
Given the two-dimensional array of integers A[2][15]. It is known that two of its entries are equal, and that those are the only entries that are equal. Find and output their indices.

6.
Write a program that will input a positive integer M and determine if it can be written as a sum of two squares of positive integers (i.e. there exist such positive integers K, L such that M = K2 + L2).

7.
Given a positive integer M and an integer array A[M]. Output the number of different entries in this array. For instance, in the array { 5, 7, 5 } there are two different entries, 5, 7.

8.
Input an integer N between 1 and 27 and print out all three digit decimal numbers such that the sum of their digits is equal to M.

Example: For N = 3 the following numbers should be printed:

300, 210, 201, 120, 102, 111.

9.
Given the binary representation of a positive integer M by the array of its binary digits a[i], that is,


M = a[n] 2^n + a[n-1] 2^(n-1) + ... + a[1] 2 + a[0] .

where a[i] is either or 1. Output the array of binary digits of M+1.

Example: For M = 9 the array of its binary digits is


a[0]=1,  a[1]=0,  a[2]= 0 ,  a[3] = 1 .

The output for 9+1 = 10 should be { 0, 1, 0, 1 }.

10.
All entries of the array X[M][N] are different. In each row choose the smallest entry, then take the largest entry among those. Print the number of the row from which that number was taken.

11.
In the array X[N] each entry is equal to either , 1 or 2. Rearrange the entries so that first come the zeros, then the ones, than the twos. You are not allowed to use another array.


next up previous
Next: Chapter 2 Up: Challenge CS Problems Previous: Challenge CS Problems
Sergey Bratus
12/8/1997