summation symbol in C++

Write your question here.
any one here can help me please....?
my question is that "how we can write summation symbol in C++......"
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <iostream>
#include <string>
using namespace std;

int main()
{
   const int  SIZE  = 10;
   const char SOLID = '*';
   const char SPACE = ' ';

   cout << string( SIZE, SOLID ) + '\n';
   for ( int i = 1       ; i <= SIZE - 1; i++ ) cout << string( i, SPACE ) + SOLID + '\n';
   for ( int i = SIZE - 2; i > 0        ; i-- ) cout << string( i, SPACE ) + SOLID + '\n';
   cout << string( SIZE, SOLID ) +'\n';
}

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include <iostream>
#include <string>
using namespace std;

const int  SIZE  = 10;
const char SOLID = '*';
const char SPACE = ' ';

void plot( int m, int n ) { cout << string( m, SPACE ) + string( n, SOLID ) + '\n'; }

int main()
{
   plot( 0, SIZE );
   for ( int i = 1       ; i <= SIZE - 1; i++ ) plot( i, 1 );
   for ( int i = SIZE - 2; i > 0        ; i-- ) plot( i, 1 );
   plot( 0, SIZE );
}


**********
 *
  *
   *
    *
     *
      *
       *
        *
         *
        *
       *
      *
     *
    *
   *
  *
 *
**********
Last edited on
friends,
can any one tell me the simplest way to write the code for summation....?
we need a better question.

I mean, with what you gave us, all we can say is:

int E = 0;
for(i = 0; i< something, i++)
E+=term;

Or, if you are trying to print the E /greek symbol, grab a unicode character that represents it and print it.

Well, I thought my answer was quite artistic! Presumably not what was intended though.

my question is that "how we can write summation symbol in C++......"


Did you mean ... +
Last edited on
Unix/Linux
1
2
3
4
5
6
7
8
9
10
#include <iostream>
#include <locale>

int main()
{
    const char sigma[] = u8"\u03A3" ; // U+03A3
    
    std::cout.imbue( std::locale( "C.UTF-8" ) ) ;
    std::cout << sigma << '\n' ;
}


Windows: with the console font set to something suitable (eg. Lucida Console)
1
2
3
4
5
6
7
8
9
10
11
#include <iostream>
#include <io.h>
#include <fcntl.h>

int main()
{
    const wchar_t sigma[] = L"\u03A3" ; // U+03A3

    ::_setmode( _fileno( stdout ), _O_WTEXT );
    std::wcout << sigma << '\n' ;
}
> std::cout.imbue

Not actually needed on Unix/Linux since you're using std::cout and not std::wcout: with utf-8 on the internal side (due to u8"..."), the default locale works just fine since it's non-converting for narrow I/O (same as the utf-8 locale actually)
Last edited on
Topic archived. No new replies allowed.