Get the following output:
1 0 1 0 1
0 1 0 1 0
1 0 1 0 1
0 1 0 1 0
1 0 1 0 1
Source code : Using for loop
#include<stdio.h> int main() { int i,j,k; for(i=1;i<=5;i++) { if(i%2==0) k=0; else k=1; for(j=1;j<=5;j++) { printf("%d ",k); if(k==0) k=1; else k=0; } printf("\n"); } return(0); }
Source code : Using while loop
#include<stdio.h> int main() { int i=1,j,k; while(i<=5) { if(i%2==0) k=0; else k=1; j=1; while(j<=5) { printf("%d ",k); if(k==0) k=1; else k=0; j++; } printf("\n"); i++; } return(0); }
Get the following output:
0 1 0 1 0
1 0 1 0 1
0 1 0 1 0
1 0 1 0 1
1 0 1 0 1
Source code : Using for loop
#include<stdio.h> int main() { int i,j,k; for(i=1;i<=5;i++) { if(i%2==1) k=0; else k=1; for(j=1;j<=5;j++) { printf("%d ",k); if(k==0) k=1; else k=0; } printf("\n"); } return(0); }
Source code : Using while loop
#include<stdio.h> int main() { int i=1,j,k; while(i<=5) { if(i%2==1) k=0; else k=1; j=1; while(j<=5) { printf("%d ",k); if(k==0) k=1; else k=0; j++; } printf("\n"); i++; } return(0); }
Get the following output:
1
0 1
1 0 1
0 1 0 1
1 0 1 0 1
Source code : Using for loop
#include<stdio.h> int main() { int i,j,k; for(i=1;i<=5;i++) { if(i%2==0) k=0; else k=1; for(j=1;j<=i;j++) { printf("%d ",k); if(k==0) k=1; else k=0; } printf("\n"); } return(0); }
Source code : Using while loop
#include<stdio.h> int main() { int i=1,j,k; while(i<=5) { if(i%2==0) k=0; else k=1; j=1; while(j<=i) { printf("%d ",k); if(k==0) k=1; else k=0; j++; } printf("\n"); i++; } return(0); }