1
01
101
0101
#include <stdio.h>
int main()
{
int i, j;
for(i=1;i<=4;i++)
{
for(j=i;j>=1;j--)
{
printf("%d",j%2);
}
printf("\n");
}
return 0;
}
Related Links:
- More Number Pattern Programs
- Star Pattern Programs in C
- Alphabet Pattern Programs in C
- Series Programs in C
thnk u sir
ReplyDeleteI really appreciate your approach
ReplyDeletegud job sir
ReplyDeleteThank U!!Great job....got stuck here for 10days
ReplyDeleteThank you sir!!
ReplyDeletethis helped me a lot. thank you.
ReplyDelete1
ReplyDelete01
101
0101
#include
int main()
{
int i, j;
for(i=1;i<=4;i++)
{
for(j=i;j>=1;j--)
{
printf("%d",j%2);
}
printf("\n");
}
return 0;
}
this program use in (j--) why explain me please
Because he wants to print no. Of digits respective to count of rows only
DeleteIt is absolutely WRONG. Don't give such bulshit
Deleteits wrong
DeleteCheck this out (not tested)
ReplyDeleteFor(i=0;i<4;i++)
{
For(j=0;j<i;j++)
{
If(i+j%2=0)
{
Printf("1");
}
Else
{
Printf("0");
}
}
Printf("\n");
}
this programe is wrong .......
Delete#include
Deletevoid main()
{
int i,j;
for(i=1;i<=4;i++)
{
for(j=1;j<=4;j++)
{
if (i==j)
printf("1");
else if (i>j && (i+j)%2 != 0)
printf("0");
else if (i>j && (i+j)%2==0)
printf("1");
else
printf(" ");
}
printf("\n");
}
}
Thank you very very much Mr.Anonymous. I've been stuck with this program for weeks & felt very demotivated. This is a cool logic & I'm very thankful to you for posting the right program:).
DeleteSorry j<=i
ReplyDeleteplease explain that effect of k%2
ReplyDelete% is remainder, so 1%2 = 1 and 2%2=0.
Delete#include
ReplyDeleteint main()
{
int r,i,j;
printf("Enter the number of rows : ");
scanf("%d",&r);
for(i=1;i<=r;i++)
{
for(j=i;j>=1;j--)
{
printf("%d",j%2);
}
printf("\n");
}
return 0;
}
It is the same as the answered posted. Only difference is program is asking a number.
Delete#include
ReplyDeletevoid main()
{
for(int i=1;i<=4;i++)
{
for(int j=1;j<=i;j++)
printf("%d",(i+j-1)%2);
printf("\n");
}
}
I also thought same .But I did (I+j+1)%2
Deletesimple coding
ReplyDeletepublic static void main(String[] arr) {
ReplyDelete// Scanner sc = new Scanner(System.in);
//System.out.println("Enter anumber to check prime numbers");
int n = 5;
int t = n;
for (int i = 1; i <= n; i++) {
if (i % 2 != 0) {
for (int j = 1; j <= i; j++) {
if (j % 2 != 0) {
System.out.print(1);
} else {
System.out.print(0);
}
}
} else {
for (int j = 1; j <= i; j++) {
if (j % 2 != 0) {
System.out.print(0);
} else {
System.out.print(1);
}
}
}
System.out.println();
}
}
ReplyDelete#include
void main()
{
int i,j;
for(i=1;i<=4;i++)
{
for(j=1;j<=4;j++)
{
if (i==j)
printf("1");
else if (i>j && (i+j)%2 != 0)
printf("0");
else if (i>j && (i+j)%2==0)
printf("1");
else
printf(" ");
}
printf("\n");
}
}
#include
ReplyDeleteint main()
{
int i,j;
for(i=1;i<=4;i++)
{
for(j=1;j<=4;j++)
{
if(j==i)
printf("1");
if(i-j==2)
printf("1");
if(i-j==1)
printf("0");
if(j*4==i)
printf("0");
}
printf("\n");
}
return 0;
}
i got the output but can anyone please tell wheather my code is efficient or not?