Program 333: Number Diamond Pattern 2 for given pattern
Method I:
Method II:
Explanation:
//Coming Soon...
Output:
Method I:
// 11
// 1221
// 123321
// 12344321
//1234554321
// 12344321
// 123321
// 1221
// 11
#include<stdio.h>
main()
{
int i,j,k,count,number;
printf("Enter number of rows\n");
scanf("%d",&number);
count=number-1;
for(i=1;i<=number;i++)
{
for(k=1;k<=count;k++)
{
printf(" ");
}
count--;
for(j=1;j<=i;j++)
{
printf("%d",j);
}
for(j=i;j>=1;j--){
printf("%d",j);
}
printf("\n");
}
count=1;
for(i=number-1;i>=1;i--)
{
if(i!=(2*(number)-1))
{
for(k=1;k<=count;k++)
{
printf(" ");
}
count++;
for(j=1;j<=i;j++)
{
printf("%d",j);
}
for(j=i;j>=1;j--){
printf("%d",j);
}
printf("\n");
}
}
}
Method II:
#include<stdio.h>
main()
{
int i,j,rows,k,space,num=1;
printf("Enter number of rows\n");
scanf("%d",&rows);
space=rows-1;
for(i=1;i<=2*rows-1;i++)
{
for(j=1;j<=space;j++)
printf(" ");
for(k=1;k<=num;k++)
printf("%d",k);
for(k=num;k>=1;k--)
printf("%d",k);
if(i<=rows-1)
{
num++;
space--;
}
else
{
space++;
num--;
}
printf("\n");
}
}
Explanation:
Output:


