int product = 1;
//for loop structure
//for(initialize ; condition for the loop to execute ; manipulation)
for(int i = 3; i <= 11; i++) //go from i = 3 to 11 inclusive
{
product = product * i; //multiply product by i and assign result back to product
/*
when i = 3, product = 1 * 3 = 3,
when i = 4, product = 3 * 4 = 12
wehen i = 5, product = 12 * 5 = 60
and so on...
*/
}
cout<<"The prodcut is "<<product<<endl;
//while loop structure
/*
intialize
while(condition for the loop to execute)
{
.....
manipulation
}
*/
int product = 1;
int i = 3; //initializer_list
while(i <= 11) //conditional
{
product = product * i;
i++; //manipulate
}
cout<<"The product is "<<product<<endl;
//more info: http://www.cplusplus.com/doc/tutorial/control/
#include <stdio.h>
//#include <iostream>
int main()
{
long product = 1, i;
//for loop structure
//for(initialize ; condition for the loop to execute ; manipulation)
for(i = 3; i <= 11; i++) //go from i = 3 to 11 inclusive
{
product = product * i; //multiply product by i and assign result back to product
printf("the product is %lu\n", product); // display after each multiply
/*
when i = 3, product = 1 * 3 = 3,
when i = 4, product = 3 * 4 = 12
wehen i = 5, product = 12 * 5 = 60
and so on...
*/
}
//printf("the product is %d\n\n", product);
//cout << "The prodcut is "<< product;
//while loop structure
/*
intialize
while(condition for the loop to execute)
{
.....
manipulation
}
*/
product = 1;
i = 3; //initializer_list
while(i <= 11) //conditional
{
product = product * i;
printf("2nd loop product is %lu\n", product);
i++; //manipulate
}
//printf("the product is %d\n\n", product);
//cout << "The product is " << product;
return 0;
}