Thread: Printing a pattern reminiscing a sin(x) wave

  1. #1
    Registered User
    Join Date
    Aug 2018
    Posts
    3

    Question Printing a pattern reminiscing a sin(x) wave

    I have written the code below and I don't think there are any syntax errors, but it doesn't print out anything.

    Code:
    #include <stdio.h>
    #include <math.h>
    
    
    int main()
    {
        int x = 0, a;
    
    
        while(x<=1)
        {
            x = x + 0.0175;
            a = sin(x);
            printf("%i", a);
            a = 1/a-20;
            for ( ; a>0; a--)
            {
                printf("*");
            }
            printf("\n");
        }
        return 0;
    }
    I'm sure it won't look nice even if it works, but for now, I just need to make it work.

    I am required to get a result similar to this:
    Attached Images Attached Images Printing a pattern reminiscing a sin(x) wave-wave-png 

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    Try using floats instead of integers.
    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.

  3. #3
    Registered User
    Join Date
    Feb 2018
    Location
    San Diego, CA
    Posts
    123
    Why didn't you use

    Code:
    x += 0.0175;
    instead

  4. #4
    Registered User
    Join Date
    Aug 2018
    Posts
    3
    Because it is easier for me to understand as I wrote and it doesn't really change the outcome.

  5. #5
    Registered User
    Join Date
    Aug 2018
    Posts
    3
    This worked! Thanks a lot.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Printing a pattern to the screen
    By PhantomJoe in forum C Programming
    Replies: 17
    Last Post: 10-22-2017, 10:14 AM
  2. Pattern Printing
    By sunny` in forum C Programming
    Replies: 2
    Last Post: 03-18-2012, 09:11 PM
  3. need help printing this pattern
    By Blimpy325 in forum C Programming
    Replies: 4
    Last Post: 03-04-2006, 06:40 AM
  4. Printing a pattern correctly???
    By Basia in forum C Programming
    Replies: 1
    Last Post: 07-01-2002, 04:34 PM
  5. Printing a Pattern of Stars
    By ProgrammingDlux in forum C++ Programming
    Replies: 13
    Last Post: 03-01-2002, 08:38 AM

Tags for this Thread