what am i doing wrong?
hey guys i need help with my code. i need help with how do i print out with 8 integers per line or any number?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
|
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
int i, count = 0, factorial = 1, number = 4;
// I am assuming you mean inclusive
// (a)
for (i = 2; i <= 100; i++ )
{
count++;
if (count <= 8)
{
if (i % 2 == 0)
cout << " " << i << "\t";
}
else
{
if (i % 2 == 0)
cout << " " << i << "\t";
count = 0;
}
}
cout << endl << endl;
// (b)
i = 99;
while (i >= 3)
{
count++;
if (count <= 8)
{
if (i % 3 == 0)
cout << " " << i << "\t";
i--;
}
else
{
count = 0;
}
}
cout << endl << endl;
// (c)
i = 2;
while (i <= 1048576)
{
count++;
if (count <= 8)
{
cout << " " << i << "\t";
i <<= 1;
}
else
{
cout << endl;
count = 0;
}
}
cout << endl << endl;
// (d)
do
{
count++;
if (count <= 8)
{
cout << " " << i << "\t";
i >>= 1;
}
else
{
cout << endl;
count = 1;
}
} while (i >= 2);
cout << endl << endl;
// e
for (i = 1; i <= number; i++)
{
factorial = factorial * i;
}
cout << factorial << endl;
system("pause");
return 0;
}
| |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
|
#include <iostream>
int main() {
int ar[12] ={1,2,3,4,5,6,7,8,9,10,11,12};
int count=0;
for(int i=0;i<4; i++)
{
for(int j=0; j<3; j++)
{
std::cout << ar[count] << " ";
count++;
}
std::cout << "\n";
}
return 0;
}
| |
Topic archived. No new replies allowed.