top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

How to generate following series in C++ : -1 1 -1 1 -1 1

0 votes
214 views
How to generate following series in C++ : -1 1 -1 1 -1 1
posted Sep 28, 2016 by anonymous

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

+1 vote
#include<iostream.h>
main()
{
    int i,count=0;
    for(i=0;i<10;i++)
    {
        if(count==0)
        {
            cout<<'-1 ';
            count=1;
        }
        if(count==1)
        {
            cout<<'1 ';
            count=0;
        }
    }         
}
answer Sep 29, 2016 by Devendra Bohre
Similar Questions
+1 vote

I want to generate the following series in C language, please help.

1
2 3
3 4 5
4 5 6 7
5 6 7 8 9
6 7 8 9 10 11
+6 votes

Generate random number form 1 - 100 with probability of 1/100.You are not allowed to used rand() function.
Any simple way of achieving above with using any complex implementation of random number generators algorithm.

...