#include <iostream>
using namespace std;
void main()
{
int a ,b,total;
for(a=1;a<=5;a++)
{
total=1;
for(b=1;b<=a;b++)
{
total=total*a;
if(a!=b)
{
cout<<total<<"x";
}
else
cout<<total<<" ";
}
cout<<endl;
}
}
I want to print out the odd number as 0 and the even number as 1, so I think you can use value%2=1 I've been trying, but I can'tHelp me Should I put an if clause in the if clause? The value I want is
0
1x1
0x0x0
1x1x1x1
That's it.
c++
using namespace std; void main()
{
int a, b, total;
for (a = 1; a <= 5; a++)
{
total = 1;
for (b = 1; b <= a; b++)
{
total = total * a;
if (a != b)
{
cout << total%2 << "x";
}
else
cout << total%2 << " ";
}
cout << endl;
}
} This is how I printed out the value I wanted.
© 2024 OneMinuteCode. All rights reserved.