c code

i want to code of this values

1
2 4
8 16 32
Okay!
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include <cstdlib>
#include <iostream>

using namespace std;

int main(int argc, char *argv[])
{
int size = 5;
int list [] = { 1, 2, 4, 8, 16, 32 };

for(int i = 0; i<size;i++){
cout<<"Int "<<i+1<<"="<<list[i+1]<<endl;
}
   
    
    system("PAUSE");
    return EXIT_SUCCESS;
}
Last edited on
Alternatively:
1
2
3
4
5
6
7
8
#include <iostream>
using namespace std;

int main()
{
  cout << "1\n2 4\n8 16 32";
  return 0;
}
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
#include <iostream>
#include <cstdlib>
#include <windows.h>
using namespace std;

int main()
{
    int lines = 5; // amount of lines
    int a = 1; // the number to be displayed
    int b = 1; // amount of numbers per line

    do
    {
        for(int c = 0; c < b; c++) // make a new variable c and increment until its as big as b
        {
            cout << a << ' '; // print the number to the console as c is rising
            a = a*2;
        }
        cout << endl; // print a new line to the console
        b++; // increment b, the amount of numbers per line
        //Sleep(500); // remove the first 2 slashes and this line will make the program sleep for half of a second
    } while(lines-- > 0); // decrement amount of lines, repeat with increased b if the value is bigger than 0

    return 0;
}
Last edited on
a = a*2;
Real men shift bits!
Topic archived. No new replies allowed.