2. Write a program that repeatedly (until end-of-file) reads
in a character from the input stream. For all characters other
than the tab character, write the character unchanged to the
output stream. When a tab character is read in, write out N
space characters. N is an int constant declared at the top of
the program and is easily changed. (Hard-coding a particular
N is not good.)
Use getchar() for input, Use putchar() for output, and use
input redirection for connecting the input file to the program
(see page 16 of Quickstart).
C:\> lowerCase < anyOldTextFile.txt > newOutputFile.txt
You will need an if-statement nested inside a while loop for this. Of course,
the program will work with any size of text file and makes no assumptions
about line length.
3. An amicable pair of numbers consists of two different integers where the
sum of the divisors of the first integer is equal to the second integer, and the
sum of the divisors of the second integer is equal to the first integer. For
example, (220, 284) is an amicable pair because
284 is divisible by 1, 2, 4, 71, and 142 and the sum of those is 220
220 is divisible by 1, 2, 4, 5, 10, 11, 20, 22, 44, 55, 110 and the sum of those is 284
Write a program that asks for a lower limit and an upper limit. The program
finds all pairs of amicable numbers between the limits. Use data type long
for the numbers. To do this sensibly, write a function
long sumDivisors( long n );
that returns the sum of all the divisors of n. The main program will look at
each number between the limits. For each number n, compute the sum s of
its divisors. Then check if the sum of the divisors of s is the original number
n. If n and s are the same number, then n is perfect. The program will write
out amicable pairs and perfect numbers that it finds, one per line. Write out
just one number if it is perfect.
Write sumDivisors()as a loop that checks each integer from 1 up to n/2
and sums the ones that divide n without leaving a remainder.
This post was edited by captaindookiefrankwest71 on Sep 14 2014 03:21pm