8 Replies - 228 Views - Last Post: 02 October 2012 - 10:21 AM Rate Topic: -----

#1 Ms.R  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 02-October 12

Hi, I have a task to make a program Like this (see attachments below)

Posted 02 October 2012 - 07:17 AM

/*Here is my Code so far but it doesnt print like on my attach files, Any Suggestions or code is very much appreciated.. THANKS !!*/

#include <stdio.h>
 
int main()
{
  int n, c, k, space = 1;
 
  printf("Enter number of rows\n");
  scanf("%d", &n);
 
  space = n - 1;
 
  for (k = 1; k <= n; k++)
  {
    for (c = 1; c <= space; c++)
      printf(" ");
 
    space--;
 
    for (c = 1; c <= 2*k-1; c++)
      printf("*");
 
    printf("\n");
  }
 
  space = 1;
 
  for (k = 1; k <= n - 1; k++)
  {
    for (c = 1; c <= space; c++)
      printf(" ");
 
    space++;
  for (c = 1 ; c <= 2*(n-k)-1; c++)
      printf("*");
 
    printf("\n");
  }
 
  getch();
}

This post has been edited by Salem_c: 02 October 2012 - 07:19 AM
Reason for edit:: added [code][/code] tags - learn to use them yourself


Is This A Good Question/Topic? 0
  • +

Replies To: Hi, I have a task to make a program Like this (see attachments below)

#2 Salem_c  Icon User is offline

  • void main'ers are DOOMED
  • member icon

Reputation: 1628
  • View blog
  • Posts: 3,090
  • Joined: 30-May 10

Re: Hi, I have a task to make a program Like this (see attachments below)

Posted 02 October 2012 - 07:22 AM

What pattern (no attachment).

Assuming this is the usual diamond pattern exercise, it seems OK here.
$ gcc foo.c
$ ./a.out 
Enter number of rows
5
    *
   ***
  *****
 *******
*********
 *******
  *****
   ***
    *


Was This Post Helpful? 0
  • +
  • -

#3 Ms.R  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 02-October 12

Re: Hi, I have a task to make a program Like this (see attachments below)

Posted 02 October 2012 - 07:46 AM

To :

View PostSalem_c, on 02 October 2012 - 07:22 AM, said:

/*This is the pattern that I'm trying to make..But my output is just a diamond
no Lines/dash(-) Sorry for the unseen attached the image files I'll fix it as soon as possible*/
Enter number of rows
5
  ---*---
  --***--
 --*****--
--*******--
-*********--
--*******--
---*****---
 -- *** --
 --- * ---


Was This Post Helpful? 0
  • +
  • -

#4 baavgai  Icon User is offline

  • Dreaming Coder
  • member icon

Reputation: 5780
  • View blog
  • Posts: 12,595
  • Joined: 16-October 07

Re: Hi, I have a task to make a program Like this (see attachments below)

Posted 02 October 2012 - 07:49 AM

Change printf(" "); to printf("_"); ?
Was This Post Helpful? 0
  • +
  • -

#5 Ms.R  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 02-October 12

Re: Hi, I have a task to make a program Like this (see attachments below)

Posted 02 October 2012 - 07:54 AM

d1.png
Was This Post Helpful? 0
  • +
  • -

#6 Ms.R  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 02-October 12

Re: Hi, I have a task to make a program Like this (see attachments below)

Posted 02 October 2012 - 08:58 AM

/*This is my Code so far ,any Suggestion,correction will be most appreciated.. THANKS!!*/
/*Enter number of rows
5
  ---*---
  --***--
 --*****--
--*******--
-*********--
--*******--
---*****---
 -- *** --
 --- * ---

This is my desired output*/

/* AND THIS MY OUTPUT SO FAR*/
Enter number of rows
5
  ---*
  --***
 --*****
--*******
-*********
--*******
---*****
 -- *** 
 --- * 



#include <stdio.h>
 
int main()
{
  int n, c, k, space = 1;
 
  printf("Enter number of rows\n");
  scanf("%d", &n);
 
  space = n - 1;
 
  for (k = 1; k <= n; k++)
  {
    for (c = 1; c <= space; c++)
      printf("-");
 
    space--;
 
    for (c = 1; c <= 2*k-1; c++)
      printf("*");
      printf("\n");
      
   
 
  }
  
 
  space = 1;
 
  for (k = 1; k <= n - 1; k++)
  {
    for (c = 1; c <= space; c++)
      printf("-");
 
    space++;
  for (c = 1 ; c <= 2*(n-k)-1; c++)
      printf("*");
 
    printf("\n");
  }
 
  getch();
}


ANY SUGGESTION,IDEA,COMMENTS IS VERY MUCH APPRECIATED ;D !!

This post has been edited by jimblumberg: 02 October 2012 - 09:01 AM

Was This Post Helpful? 0
  • +
  • -

#7 jimblumberg  Icon User is online

  • member icon


Reputation: 3993
  • View blog
  • Posts: 12,321
  • Joined: 25-December 09

Re: Hi, I have a task to make a program Like this (see attachments below)

Posted 02 October 2012 - 09:01 AM

Please don't open a new topic for the same problem. Topics merged.

Also you should enclose your output inside code tags to preserve the spacing.

Jim
Was This Post Helpful? 1
  • +
  • -

#8 Ms.R  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 02-October 12

Re: Hi, I have a task to make a program Like this (see attachments below)

Posted 02 October 2012 - 09:40 AM

TO :

View Postjimblumberg, on 02 October 2012 - 09:01 AM, said:

Please don't open a new topic for the same problem. Topics merged.

Also you should enclose your output inside code tags to preserve the spacing.

Jim


Sir, I'm SORRY FOR POSTING 2 SAME TOPICS I JUST NEED A BRIEF EXPLANATION,SUGGESTION(S)
IN SOLVING MY PROGRAM..

[quote name='Ms.R' date='02 October 2012 - 09:37 AM' timestamp='1349195868' post='1713967']
TO :

View Postjimblumberg, on 02 October 2012 - 09:01 AM, said:

Please don't open a new topic for the same problem. Topics merged.

Also you should enclose your output inside code tags to preserve the spacing.

Jim


THANK YOU SO MUCH FOR THE HELP Sir,..
Was This Post Helpful? 0
  • +
  • -

#9 baavgai  Icon User is offline

  • Dreaming Coder
  • member icon

Reputation: 5780
  • View blog
  • Posts: 12,595
  • Joined: 16-October 07

Re: Hi, I have a task to make a program Like this (see attachments below)

Posted 02 October 2012 - 10:21 AM

I'm confused. You're printing on one side. You can't do the same thing again because...?
for (k = 1; k <= n; k++) {
	for (c = 0; c < space; c++) { printf("-"); }
	for (c = 0; c < 2*k-1; c++) { printf("*"); }
	// guess what goes here!
	printf("\n");
	space--;
}


Was This Post Helpful? 0
  • +
  • -

Page 1 of 1