Welcome to Dream.In.Code
Getting C++ Help is Easy!

Join 132,273 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,152 people online right now. Registration is fast and FREE... Join Now!




Shape using 0 and 1 alternatively...

 
Reply to this topicStart new topic

Shape using 0 and 1 alternatively...

bivunlim
post 12 Mar, 2008 - 11:12 PM
Post #1


New D.I.C Head

*
Joined: 12 Mar, 2008
Posts: 1

Well...
Let me show u...
CODE

#include<stdio.h>
#include<conio.h>
void main()
{
int i,n,j,k;
clrscr();
printf("Plz enter the height of the Shape::");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
    for(j=1;j<=i;j++)
    printf("*");
    printf("\n");
}
getch();
}


Using this code I can generate a shape like this...
0
00
000
0000
00000


But I wanna make a shape like this...
1
01
010
1010
10101


Thats means insted of each 0 I want to use 1 and 0 alternatively.

I want to know how...

Cud it be possible to introduce an array with 0 and 1 in it and print those value alternatively???
If yes, plz guide me how...
I'm a really novice in this language...
User is offlineProfile CardPM

Go to the top of the page

no2pencil
post 12 Mar, 2008 - 11:20 PM
Post #2


My fridge be runnin OH NOEZ!

Group Icon
Joined: 10 May, 2007
Posts: 6,328



Thanked 57 times

Dream Kudos: 2375

Expert In: Goofing Off

My Contributions


I would do something like the following:
cpp

int prn=0;
for(j=1;j<=i;j++) {
printf("%d",prn); // will print the current number
if(prn==0) prn++; // if it's zero, make it 1
else prn--; // otherwise, it's 1, so make it zero
}
printf("\n")
User is offlineProfile CardPM

Go to the top of the page

Reply to this topicStart new topic
Time is now: 11/22/08 12:25AM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month