First work out the algorithm for what you want to do and then encode that using the C++ language.
Alternative Answer
In this case, the algorithm will consist of a loop that counts from 1 to 1000, testing each value to see if it can be divided by 3 or 5 without leaving a remainder. If so, it gets added to a running total. When the loop ends, the running total is the final answer.
To determine a remainder in C++, we use the modulo operator (%). That is; 9%5 is 4 because 9 divided by 5 is 1 remainder 4, whereas 9%3 is zero. Therefore if either operation evaluates to zero, the value can be added to the running total.
int DoSum( void )
{
int total=0;
for(int x=1; x<1000; ++x)
if( !(x%3) !(x%5) )
total+=x;
return(total);
}
An alternative (and more efficient) algorithm will perform the same loop twice, first in steps of 3 and then in steps of 5. Since we're no longer testing for invalid values, we simply sum every value.
int DoSum( void )
{
int total=0;
for(int y=0; y<2; ++y)
{
int step=y?5:3; // if y is 0, step is 3, otherwise step is 5
for(int x=step; x<1000; x+=step)
total+=x;
}
return(total);
}
Write a C program to Draw a RAINBOW and fill the suitable colors ...
you can use strstr()
Step 1. Learn the word "Fibonacci"...
You first learn how to program in C.
write a program that reads in the size of the side of square and then pints a hollow square of that size out of asterisks and blanks?
Write the first 6 Multiples of 12 and 14.
The prince has a lot of prints that he printed (iI don't know I know it's dumb)
65,130,195,260
give description of that then i will send the answer
Ask a local attorney.
4 and 6
14284256708498112126140CyberchiefIf this answer helped you and you appreciate the fact that time was taken out of somebody's personal day to write the answer to this question, please support the contributor by clicking "Recommend Contributor" button below at the bottom of this answer box.
Write a C program to Draw a RAINBOW and fill the suitable colors ...
Even multiples of 5 must end with a zero.
The first 3 multiples of 7 are: 7, 14, and 21.
write the first three common. multiples of 3,4,5
abhimanyu