This is a C program to print your entered string in DIAMOND shape..... Check it!
The above shown output is expected..
#include"stdio.h" /*Pre processor directives */
#include"conio.h"
#include"conio.h"
main()
{
int i,j,l=0,k;
char str[20];
void fun(char *);
clrscr();
printf("Enter the string : ");
gets(str);
for(i=0;str[i]!='\0';i++)
l++;
for(i=0;i<l;i++)
{
k=l-i;
for(j=0;j<k;j++)
printf(" ");
for(j=0;j<=i;j++)
{
fun(&str[j]);
}
printf("\n");
}
for(i=l-1;i>0;i--)
{
k=l-i;
for(j=0;j<=k;j++)
printf(" ");
for(j=i;j>0;j--)
fun(&str[l-j]);
printf("\n");
}
getch();
return 0;
}
void fun(char *p)
{
printf(" %c ",*p);
}
0 comments:
Post a Comment