Prints 'x' every 8 columns, demonstrate conditional operator - C++ Operator

C++ examples for Operator:Conditional Operator

Description

Prints 'x' every 8 columns, demonstrate conditional operator

Demo Code

#include <iostream>
using namespace std;
int main()/*from  w  ww  . j  av  a2 s . c  om*/
{
   for(int j=0; j<80; j++)          //for every column,
   {                             //ch is 'x' if column is
       char ch = (j%8) ? ' ' : 'x';  //multiple of 8, and
       cout << ch;                   //' ' (space) otherwise
   }
   return 0;
}

Result


Related Tutorials