Write a programs to print following paterns
#
#0
#0#
#0#0
#0#0#
Answers
Answered by
2
Okay I don't know that in which language so I am giving in 2 programming language :-
Java -
public class pattern
{
public static void main()
{
for(int i = 0; i <= 5 ;i++)
for(int j = 0; j <= I; j++)
{
if (j % 2 == 0)
System.out.print("0");
else
System.out.print("#");
}
System.out.println();
}
}
C -
#include<stdio.h>
int main(){
for(int i = 0; i <= 5 ;i++)
{
for(int j = 0; j <= I; j++)
{
if (j % 2 == 0)
printf("0");
else
printf("#");
}
printf("\n");
}
}
Answered by
17
Question:-
Write a program to print the following pattern.
#
#0
#0#0
#0#0#
Code:-
class Pattern
{
public static void main(String args[])
{
for(int i=1;i<=5;i++)
{
for(int j=1;j<=i;j++)
{
String s=(j%2!=0)?"#":"0";
System.out.print(s+" ");
}
System.out.println();
}
}
}
Similar questions