|
Spring 08 Problems
Circular Permutations. Generate all the circular permutations for a given N (ask for N, N > 1).
Input:
Enter N? 5
Output:
0 1 2 3 4
1 2 3 4 0
2 3 4 0 1
3 4 0 1 2
4 0 1 2 3
Check magic square. Enter a square of positive integers and check if it is magic. A magic square is a n*n array where the sum of lines and columns are equal. Assume (n=3).
Input:
Line 0? 7 3 5
Line 1? 6 8 1
Line 2? 2 4 9
Output:
YES, magic square (otherwise: NOT a magic square)
Display the first n=4 perfect numbers. A perfect number is the sum of its factors. Example: 6 = 1 + 2 + 3 and 28 = 1 + 2 + 4 + 7 + 14
Output:
6
28
?
?
Problem4.
Enter a word (without blanks) and display its letters on each row in increasing number. Last row contains the last letters that remain after you apply this algorithm.
Input:
Enter word? Mathematician
Output:
M
a t
h e m
a t i c
i a n
Display without repetitions all the Pythagorean triplets (a,b,c) (a, b, c integers, a>0,b>0,c>0 with a2 + b2 = c2 ) where a < 100, b < 100. The program should also have a counter and finally we can see how many they are, counter starts from 1.
Output:
#1 3 4 5
..
|