9. Write a program to display the following pattern on the screen.
10101
01010
10101
01010
10101
Answers
C PROGRAMING
Answer:
#include <stdio.h>
int main()
{
int rows, cols, i, j, k;
printf("Enter number of rows: ");
scanf("%d", &rows);
printf("Enter number of columns: ");
scanf("%d", &cols);
k = 1;
for(i=1; i<=rows; i++)
{
for(j=1; j<=cols; j++)
{
if(k == 1)
{
printf("1");
}
else
{
printf("0");
}
k *= -1;
}
if(cols % 2 == 0)
{
k *= -1;
}
printf("\n");
}
return 0;
}
output:
10101
01010
10101
01010
10101
TO KNOW MORE ON PYTHON PROGRAM
1.Write python program that accepts marks in 5 subjects and outputs average marks ..
brainly.in/question/13526149
2.Write a Python program to find person is senior citizen or not input page
brainly.in/question/12150015
Answer:
- please mark me brain list
- please mark me brain list
- please mark me brain list
Explanation:
*
* C program to print box number pattern with cross center
* www.atnyla.com
*/
#include
int main()
{
int rows, cols, i, j, k;
/* Input rows and columns from user */
printf("Enter number of rows: ");
scanf("%d", &rows);
printf("Enter number of columns: ");
scanf("%d", &cols);
k = 1;
for(i=1; i<=rows; i++)
{
for(j=1; j<=cols; j++)
{
if(k == 1)
{
printf("1");
}
else
{
printf("0");
}
// If k = 1 then k *= -1 => -1
// If k = -1 then k *= -1 => 1
k *= -1;
}
if(cols % 2 == 0)
{
k *= -1;
}
printf("\n");
}
return 0;
}
Output