Problem: https://www.hackerrank.com/contests/spojklu/challenges/char-pat-sp-4
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
void fun(int c,int h,int w)
{
int i,j,k;
for(i=1;i<=h;i++)
{
for(j=1;j<=c;j++)
{
printf("*");
for(k=1;k<=w;k++)
printf(".");
}
printf("*");
printf("\n");
}
}
int main() {
/* Enter your code here. Read
input from STDIN. Print output to STDOUT */
int r,c,h,w,i,j,t;
scanf("%d",&t);
while(t--)
{
scanf("%d%d%d%d",&r,&c,&h,&w);
for (i=1; i<=((w+1)*c)+1;i++)
printf("*");
printf("\n");
for(i=1;i<=r;i++)
{
fun(c,h,w);
for(j=1;j<=((w+1)*c)+1;j++)
printf("*");
printf("\n");
}
printf("\n");
}
return 0;
}
=====================================================
#include<stdio.h>
main()
{
int i,j,k,c=4,d=0;
for(i=1;i<=5;i++)
{
for(k=1;k<=5-i;k++)
printf(" ");
for(j=1;j<=i+d;j++)
printf("*");
printf("\n");
d++;
}
for(i=5;i>=1;i--)
{
for(k=1;k<=5-i;k++)
printf(" ");
for(j=1;j<=i+c;j++)
printf("*");
printf("\n");
c--;
}
}
=====================================================
#include<stdio.h>
main()
{
int i,j,k,c=4,d=0;
for(i=1;i<=5;i++)
{
for(k=1;k<=5-i;k++)
printf(" ");
for(j=1;j<=i+d;j++)
printf("*");
printf("\n");
d++;
}
for(i=5;i>=1;i--)
{
for(k=1;k<=5-i;k++)
printf(" ");
for(j=1;j<=i+c;j++)
printf("*");
printf("\n");
c--;
}
}
No comments:
Post a Comment