Thread: help with code!

  1. #1
    Registered User
    Join Date
    Nov 2020
    Posts
    4

    help with code!

    i'm working on a program to receive a word of 6 letters max. then organise it like this.
    exemple: (ps.: just used - to organise the words the way i want)
    --------------------Test
    ---------------Test Test
    ----------Test Test Test
    -----Test Test Test Test
    Test Test Test Test Test

    all that i've got atm is the reverse of this, could som1 help me with this code?
    thanks!!

    Code:
    
    
    Code:
    #include<stdio.h>
    #include <stdlib.h>
    #include <math.h>
    #include <string.h>
    
    main()
    {
      int x, y, size;
    
      char name[6];
    
      printf("Type a word: ");
    
      gets(name);
      size = strlen(name);
    
      for (x = 1; x <= size; x++)
      {
        for (y = 1; y <= x; y++)
    
          printf("%s\t", name);
    
        printf("\n");
      }
    
      return 0;
    }
    

  2. #2
    Registered User
    Join Date
    May 2012
    Posts
    491
    You just ned some more complicated logic in your inner for loop.
    The outer for loop iterates over the size of the input.
    The inner for loop needs to output a series of dashes, followed by a varying number of copies of the
    input string.

    You've got the copy count correct. As a hint, it might be easiest to have a thhird nested loop to output
    the dashes.
    I'm the author of MiniBasic: How to write a script interpreter and Basic Algorithms
    Visit my website for lots of associated C programming resources.
    https://github.com/MalcolmMcLean


  3. #3
    Registered User
    Join Date
    Nov 2020
    Posts
    4
    Quote Originally Posted by Malcolm McLean View Post
    You just ned some more complicated logic in your inner for loop.
    The outer for loop iterates over the size of the input.
    The inner for loop needs to output a series of dashes, followed by a varying number of copies of the
    input string.

    You've got the copy count correct. As a hint, it might be easiest to have a thhird nested loop to output
    the dashes.
    could u create the code for me to get the example? thanks m8

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    38,543
    Same as before.
    Help w/ my code
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  5. #5
    Registered User
    Join Date
    May 2012
    Posts
    491
    Quote Originally Posted by oxypult View Post
    could u create the code for me to get the example? thanks m8
    We're not a free homework-doing service for people who have difficulty with their assignments.
    I'm the author of MiniBasic: How to write a script interpreter and Basic Algorithms
    Visit my website for lots of associated C programming resources.
    https://github.com/MalcolmMcLean


  6. #6
    Registered User Sir Galahad's Avatar
    Join Date
    Nov 2016
    Location
    The Round Table
    Posts
    216
    Quote Originally Posted by oxypult View Post
    could u create the code for me to get the example? thanks m8
    Unless you're unwilling to make a sincere effort, don't expect help from anyone here.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 1
    Last Post: 03-10-2010, 11:28 AM
  2. Replies: 14
    Last Post: 04-01-2008, 02:23 AM
  3. producing c/c++ code from flowcharts,pseudo code , algorithims
    By rohit83.ken in forum C++ Programming
    Replies: 3
    Last Post: 02-20-2008, 07:09 AM
  4. Having trouble translating psudeo-code to real-code.
    By Lithorien in forum C++ Programming
    Replies: 13
    Last Post: 10-05-2004, 07:51 PM
  5. Replies: 0
    Last Post: 02-21-2002, 06:05 PM

Tags for this Thread