1
01
101
0101
Example
#include<stdio.h>
#include<conio.h>
void main()
{
int i,j,n;
clrscr();
printf("Enter the value of n:");
scanf("%d",&n);
for(i=0;i<=n;i++)
{
for(j=1;j<i;j++)
{
if((i+j)%2==0)
{
printf("0");
}
else
{
printf("1");
}
}
printf("\n");
}
getch();
}
/*=====================================================================
OUTPUT
Enter the value of n:5
1
01
101
01010
*/
Thank you for helping us
ReplyDeleteThank you for helping us
ReplyDeletejust after scanf do one thing.. increse the value of n by 1...like just write n++.. and it will run 5 times
ReplyDeleteThank u for helping us vasanta & aparna
ReplyDeleteRaipur CHHATTISGARH
in 1st loop use i<=n+1 for correct times loop
ReplyDeletesuch as if u enter 5 then 5 lines will print
Java code:
ReplyDeletepackage _1_10;
import java.util.Scanner; ;
public class Bin {
static Scanner in = new Scanner(System.in);
public static void main(String[] args) {
int n = in.nextInt() ;
for( int i = 1 ; i <= n ; i ++ )
{
for( int j = 1 ; j <=i ; j ++ )
{
if((i+j)%2==0)
System.out.print(1+" ");
else
System.out.print(0+" ");
}
System.out.println();
}
}
}
In c++
DeleteNikal bhsdk
ReplyDeleteThank you for your help at the right moments
ReplyDelete