For this assignment, you must also write pseudocode, in addition to your C progr
ID: 3890565 • Letter: F
Question
For this assignment, you must also write pseudocode, in addition to your C program, and show correct operation for the following programs:
1) The first program will compute compounded interest. Suppose you invest $1000.00 at an interest rate of 2% per year. If the interest is computed at the end of each day, it is added to your account (i.e., the interest is compounded daily). Print what the account value will be at the end of each year for 20 years. Use data type double for money. For 365 days per year (ignore leap year), the daily interest rate is 2%/ 365. Your program should request the following numbers as input from the user with scanf():
Initial account balance (Start with $1000.00)
Then run and demonstrate it again with the last 6 digits of your Red ID# so 876123456 would be: 1234.56)
The annual interest rate in percent
Number of years: run it for at least 10 years
For a compounding period of 1 (daily), the interest must be computed 365 times and accumulated. For a compounding period of 30 (monthly), the interest would be computed 365/30 or 12 times.Print the amount in the account including accumulated interest for each of 20 years for the following compounding periods if you started with $1,000 dollars:
Daily (period 1)
Weekly (7)
Monthly (30)
Quarterly (90)
Annually (365)
Use DOUBLE variables for your calculations. Run your program again for daily compounding using FLOAT variables, and note the difference in the results. Output should be formatted in columns, by year number something like this:
Year Daily Weekly Monthly Quarterly Annually
---- ------- ------- ------- --------- --------
0 1000.00 1000.00 1000.00 1000.00 1000.00
1 100x.xx 100x.xx 100x.xx 100x.xx 100x.xx
2 10xx.xx ...
2) Write a program that asks for numeric input and indicates if the digits from an input value input are even or odd.
Use digits of your Red ID#.The program should print "odd" if that digit x is odd and "even" if x is even. Test and demonstrate with the digits of your Red ID# one per line. Print the digits of your red ID, one digit on each line, with the result next to each number like this:
Input your Red ID: 876123456
3) Write a program that indicates if a number input is a prime number or not. The program should repeat this until the user enters 0 to exit. For example, the input of 17 should print "prime", since 17 has no divisors other than 17 and 1 (hence 17 is a prime number). Input of 21 should print "not a prime" (3 and 7 are both divisors of 21, hence 21 is not a prime number).
Run the program using your own Red ID number to determine if it is a prime number.
The program should use the exhaustive search approach to finding a divisor for n. It should start by checking to see if 2 is a divisor, and then checking successive integers until it finds a divisor (in which case it returns 0) or it is certain that there are no divisors (in which case it returns 1). Give some thought to the question “ what is the highest number that needs to be checked?”. You might think initially that it is n/2, but it is smaller than that.
Explanation / Answer
//PROGRAM 2: program that asks for numeric input and indicates if the digits from an input value input are even or odd
#include <stdio.h>
#include <stdlib.h>
//function to check even or odd
int checkEvenOrOdd(int n)
{
return (n%2);
}
//function to print the digits and check even or odd
int printEvenOrOdd(int n)
{
if(n==0)
return 0;
else
{
int r=n%10;
if(checkEvenOrOdd(r))
{
printf("%d even ",r);
}
else
{
printf("%d odd ",r);
}
return printEvenOrOdd(n/10);
}
}
int main()
{
int n;
printf("Input your Red ID:");
scanf("%d",&n);
printEvenOrOdd(87612345);
return 0;
}
OUTPUT :
Input your Red ID:87612345
5 even
4 odd
3 even
2 odd
1 even
6 odd
7 even
8 odd
Process returned 0 (0x0) execution time : 8.455 s
Press any key to continue.
//PROGRAM 3: program that indicates if a number input is a prime number or not
#include <stdio.h>
#include <stdlib.h>
//function to check given n is prime or not
int checkPrimeNumber(int n)
{
int flag = 0;
int i;
for(i = 2; i <= n/2; ++i)
{
if(n%i == 0)
{
flag = 1;
break;
}
}
return flag;
}
int main()
{
int n;
do
{
printf("Input your Red ID:");
scanf("%d",&n);
if(n==0) break;
if(checkPrimeNumber(n))
printf("not a prime ");
else
printf("prime ");
}
while(1);
return 0;
}
OUTPUT:
Input your Red ID:21
not a prime
Input your Red ID:7
prime
Input your Red ID:13
prime
Input your Red ID:18
not a prime
Input your Red ID:0
Process returned 0 (0x0) execution time : 105.952 s
Press any key to continue.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.