Jump to content

Simple C problem

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
1 reply to this topic

#1
Minky

Minky

    Newbie

  • Members
  • Pip
  • 5 posts
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:
     

             *

            * *

          *     *

         *      *

          *    *

           *  *

             *

The code that I managed to make looks like this:

#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! :)

#2
Minky

Minky

    Newbie

  • Members
  • Pip
  • 5 posts
I've solved it, so no need for help anymore, thank you! :)