May 14, 2020 at 10:14pm UTC
Hello,
I want to print the below numbers. I wrote a program but I should delete 32.
How can I fix my program?
Goal:
1---64
2---16
4---8
8---4
16---2
64---1
My result:
1---64
2---32
4---16
8---8
16---4
32---2
64---1
1 2 3 4 5 6 7 8 9 10
#include <iostream>
using namespace std;
int main()
{
for (int i = 0; i <= 6; i++)
{
cout << pow(2, i) << "\t" << pow(2, 6 - i) << endl;
}
}
Last edited on May 14, 2020 at 10:16pm UTC
May 15, 2020 at 9:49am UTC
What exactly is the purpose? If you really want to, you can simply make the condition that if pow(...) == 32, and then plug in the number you want to out instead and change a few conditions around.
May 15, 2020 at 10:10am UTC
1 2 3 4 5 6 7
#include <iostream>
using namespace std;
int main()
{
for (int i = 0; i < 6; i++) cout << ( 1 << ( i + ( i == 5 ) ) ) << "\t" << ( 1 << ( 5 - i + !i ) ) << '\n' ;
}
Last edited on May 15, 2020 at 10:13am UTC