java program for pattern
Answers
1) Creational Pattern. Factory Method Pattern Abstract Factory Pattern Singleton Pattern Prototype Pattern Builder Pattern Object Pool Pattern.
2) Structural Pattern. Adapter Pattern Bridge Pattern Composite Pattern Decorator Pattern Facade Pattern Flyweight Pattern proxy Pattern.
3) Behavioral Pattern
Answer:
See your ans
Explanation:
=>Notice:Read what is written in 2nd pic before going to the program.
#include<stdio.h>
void main()
{
int row=0,rnum=0,col=0,cnum=1;
int CD=0,spc=0,a=1,slr=0,val1=0,val2=0;
//slr => number of objects present in last row
//CD =>Difference of objects in every row
printf("enter number of rows and CD");
printf("\n");
scanf("%d %d",&rnum,&CD);
slr=(rnum*CD)-(CD-1); //formula
for(row=1;row<=rnum;row++)
{
for(spc=a;spc<(slr+1)/2;spc++) //trailing space
{
printf(" ");
}
for(col=1;col<=cnum;col++)
{
if(col<=(cnum+1)/2)
{
val1=val1+1;
val2=val1%10;
printf("%d",val2);
}
else
{
val1=val1-1;
val2=val1%10;
printf("%d",val2);
}
}
a=a+CD/2;
cnum=cnum+CD;
printf("\n");
}
}