Hi, I am kind of new to C and I have run into some basic problems. I am trying to create a diamond in asterixes and I’ve managed to create a filled diamond with asterixes. But the problem I have is that I need it to look something like this:
Code:
*
* *
* *
* *
* *
* *
*
The code that I managed to make presents the diamond like this:
Code:
*
***
*****
*******
********
******
****
**
*
And this is the code that makes it:
Code:
#include <stdio.h>
#include <stdlib.h>
void pyramid(){
int bredd,center,a,b,c;
printf("Lines: ");
scanf("%d",&bredd);
if(bredd%2!=0){ //Check if enterd number is odd or not
center = (bredd/2 + bredd%2);
for(a=1;a<=bredd;a+=2)
{
for(c=0;c<=center;c++)
printf(" ");
for(b=0;b<a;b++)
printf("*");
printf("\n");
center--;
}
center+=2;
for(a-=4;a>=1;a-=2)
{
for(c=center;c>=0;c--)
printf(" ");
for(b=0;b<a;b++)
printf("*");
printf("\n");
center++;
}
}
else{
printf("Fel!\n");
}
}
int main(void)
{
pyramid();
system("PAUSE");
return 0;
}
Any feedback would be appreciated!