answersLogoWhite

0


Best Answer

Hey, It is not the exact logic for a given program.

Here i m giving the code with minimum number of executing steps.

also i m sure that there doesn't exist any other way to print the same Diamond such that code executing steps will be less than mine.

It is not copied from any website, book etc.

#include

void main()

{

int n,i,s,k,flagReverce=0;

printf("Enter the no. of rows\n");

scanf("%d", &n);

for (i=1; i>=1; i++)

{

for (s=n; s>i; s-)

printf(" ");

for(k=1; k<(i*2)-1; k++)

printf("*")

printf("\n")

if (i == n)

flagReverce = 1

if (flagReverce = 1)

i-=2

}

}

User Avatar

Wiki User

11y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

12y ago

#include<stdio.h>

main()

{

int i,j,k,n,a,b,c,x;

printf("enter the # of rows of graphical output");

scanf("%d",&n);

/* UPPER HALF OF KITE */

for(i=1;i<=n;i++)

{

printf("\t");

for (k=1;k<=(n-i);k++)

{

printf(" ");

}

for(j=0;j<i;j++)

{

printf("*");

printf(" ");

}

for(k=1;k<=(n-i-1);k++)

{

printf(" ");

}

printf("\n");

}

/* LOWER PART OF KITE */

for(i=(n-1);i>0;i--)

{

printf("\t");

for (k=(n-i);k>0;k--)

{

printf(" ");

}

for(j=i;j>0;j--)

{

printf("*");

printf(" ");

}

for(k=(n-i-1);k>0;k--)

{

printf(" ");

}

printf("\n");

}

getch();

}

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Write a program in c language to draw a diamond shaped if you give the number?
Write your answer...
Submit
Still have questions?
magnify glass
imp