Practice with loops
- Write a program that reads an integer, N, and computes N!
(e.g. for N=6 it would compute 6*5*4*3*2*1 => 720).
- Write a program that uses a loop to
prompt the user to enter any number except 7.
If they do enter 7 the program should respond
with "Sneaky!" and exit, otherwise it should repeat the
prompt until the user has tried 7 times, then it should
say "You win!" and exit.
- Write a program that
reads the username (3-8 lowercase alphabetic characters)
and mark (0-100) for each of 50 students. As it goes,
for each student it should
compute and display their lettergrade
(use the conversion scale from the CSCI 160 course outline).
Then modify the program to keep track of the student with the highest
mark and display that at the end of the program.
- Write a program that uses nested loops to read
5 words from the user and print each of them backwards.
(Hint: use a string to hold each word. The function
YOURSTRINGVARIABLENAME.length() returns the number
of characters in the word, then you can use
YOURSTRINGVARIABLENAME[i] to access the characters
in the word one at a time.)
- Write a program that reads an integer, m, and prints
it as the product of all its factors. E.g. if m was 36
it would print
36 = 2*2*3*3
- Write a program that reads two integers, m and n,
and generates all the prime numbers between them.
- Write a program that reads a string of characters
and finds the longest palindrome within the string.
(A palindrome is a sequence that reads the same
forwards as backwards.) E.g. for the string
"blahbobyuck" the longest palindrome is "bob".