Thread: Help with code

  1. #1
    Registered User
    Join Date
    Nov 2012
    Posts
    6

    Help with code

    I have to code this: I ask for input from user and output should indicate how mant times user made that input:

    some code:
    Code:
    #include <stdio.h>#include <stdlib.h>
    
    
    int main()
    {
    int size, i, sum = 0, *number;
        printf("How many numbers you want to input?");
        scanf("%d", &size);
        number = malloc(size * sizeof(int));
        for (i = 0; i < size; ++i)
        {
            printf("\nEnter number %d:", i + 1);
            scanf("%d", &number[i]);
    
            printf("");
        }
    
    
        puts("\nBelow are the entered numbers");
        for(i = 0; i < size; ++i)
        {
            printf("%d\t", number[i]);
        }
        //still thinking for code that would do this
        // example: user input 1,2,3,3
        // output 1 is seen 1 time/s.
        // output 2 is seen 2 time/s.
        // output 3 is seen 2 time/s.
        
    free(number);
    return 0;
    }
    Last edited by sakuraleaf; 11-25-2012 at 10:51 PM.

  2. #2
    TEIAM - problem solved
    Join Date
    Apr 2012
    Location
    Melbourne Australia
    Posts
    1,907
    Do you want to add the inputs up and display the total?
    Fact - Beethoven wrote his first symphony in C

  3. #3
    Registered User
    Join Date
    Nov 2012
    Posts
    6
    sorry that was not really the problem, I re-editted my quotes so I can show which one i haven't figured out.

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    If the user inputs
    1 2 3 3 2 1

    Then sorting the numbers to give you
    1 1 2 2 3 3
    makes it easier to count each number, as they are now all together in the array.
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 09-19-2012, 01:58 PM
  2. Replies: 1
    Last Post: 03-10-2010, 11:28 AM
  3. Replies: 14
    Last Post: 04-01-2008, 02:23 AM
  4. 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
  5. Replies: 0
    Last Post: 02-21-2002, 06:05 PM