Write a C Program to print all first N elements of binary
numbers series.
For N = 3, output is 0,1,10
For N = 5, output is 0,1,10, 11, 100
CODE:
#include<stdio.h>
main()
{
int i,j,num=0;
printf("enter no:");
scanf("%d",&num);
printf("1\n");
num=num-1;
for(i=1;i<=num;i++)
{
for(j=1;j<=i;j++)
{
if((i+j)%2==0){
printf("0");
}
else{
printf("1");
}
}
printf("\n");
}
return 0;
}
Program Output:
For more problems click here
No comments:
Post a Comment