Tweet
/* Program to print sequence
1
101
10101
1010101
10101
101
1
*/
#include<stdio.h>
#include<iostream>
main()
{
int i,p=4,a=1,k,j;
for(i=1;i<=4;i++)
{
a=1;
for(k=1;k<=p;k++)
std::cout<<" ";
p--;
for(j=1;j<=i;j++)
{
std::cout<<a;
if(a==0)
a=1;
else
a=0;
}
for(j=i-1;j>=1;j--)
{
std::cout<<a;
if(a==0)
a=1;
else
a=0;
}
std::cout<<"\n";
}
p=2;
for(i=3;i>=1;i--)
{
a=1;
for(k=1;k<=p;k++)
std::cout<<" ";
p++;
for(j=1;j<=i;j++)
{
std::cout<<a;
if(a==0)
a=1;
else
a=0;
}
for(j=i-1;j>=1;j--)
{
std::cout<<a;
if(a==0)
a=1;
else
a=0;
}
std::cout<<"\n";
}
}
Program to print number sequence in C++ (2)
Posted by
LAHAUL SETH
~
Program to print number sequence in C++ (2)
2012-05-01T12:22:00+05:30
LAHAUL SETH
C++
|
cplusplus
|
Comments
Program to print number sequence in C++ (2)
2012-05-01T12:22:00+05:30
LAHAUL SETH
C++
|
cplusplus
|