Create a program that uses a while loop to sum only the odd numbers from 1 up to
ID: 3666636 • Letter: C
Question
Create a program that uses a while loop to sum only the odd numbers from 1 up to 50. Display the total sum of these odd numbers. Make sure you have appropriate comments and output to explain the program's function. After completion and testing, zip the folder and submit via the Assignments link in BlackBoard. You should browse and attach the folder via the local file button and then select the submit button. The final date/time to submit this assignment is Friday, Feb. 12th at midnight. Your friend Joe saves pennies in a jar. Each month he empties the jar and goes to the bank. Create a program that allows Joe to enter the number of pennies he has in the jar and returns/displays the number of dollars, quarters, dimes, nickels and pennies Joe should receive back from the bank. Example - 2311 pennies should display 23 dollars, 0 quarters, 1 dime, 0 nickels and a penny back from the bank. Example 2 - 7333 pennies should display 73 dollars, 1 quarter, 0 dimes, 1 nickel, and 3 pennies back from the bank. Make sure you have appropriate comments and output to explain the program's function. After completion and testing, zip the folder and submit via the Assignments link in BlackBoard. You should browse and attach the folder via the local file button and then select the submit button. The final date/time to submit this assignment is Friday, Feb. 12th at midnight.Explanation / Answer
#include<iostream.h>
#include<conio.h>
void main()
{
int sum=0,i=1; //declaring and initalizing variables
while(i<=50) // this loop iterates from 1 to 50
{
sum=sum+i; //adding sum with value of i
i++; //incrementing value of i
}
cout<<"Sum of Odd numbers from 1 to 50 is "<<sum;
getch();
}
Penny Jar
#include<iostream.h>
#include<conio.h>
void main()
{
int p=0,d=0,q=0,di=0,n=0,re=0; //declaring and initalizing
variables
cout<<"Enter Pennies";
cin>>p;
d=p/100;
re=p%100;
if(re>=25)
{
q=re/25;
re=re%25;
}
if(re>=10)
{
di=re/10;
re=re%10;
}
if(re>=5)
{
n=re/5;
re=re%5;
}
if(re>=1)
{
p=re;
}
cout<<d<<" Dollars, "<<q<<" quarter, "<<di<<" dime, "<<n<<
"nickel, "<<p<<" pennies";
getch();
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.