Thread: Small problem with printing elements of an array

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    I am Diamond Dave
    Join Date
    Mar 2006
    Location
    You'll get some leg tonight for SURE!
    Posts
    34

    Small problem with printing elements of an array

    OK I'm horrible at this so bear with me. The user is supposed to enter a bunch of numbers that get stored in an array. Then it uses a function to print the elements of the array. I don't knwo how to set up the function parameters or whatever to get it to work but i'm pretty sure it should work other than that. Here's what I've got:

    Code:
    #include <stdio.h>
    
    
    void printset(int [], int);
    
    int main()
    {
    	int i = 0, a[25] = {0};
    
    	printf("elements in array are:\n");
    	for(i=0;i<25;i++)
    	{
    		scanf("%d",&a[i]);
    		 
    
    	
    	}
    printset();
    return 0;
    
    }
    	void printset(int b[25], int i)
    	{int i;
     for (i=0;i<25;i++)
     {
    
    	printf("{%d, ",b[i]);
    	printf(" }\n");
    
    	
    	
    	}
    	
    	
    }

  2. #2
    I am Diamond Dave
    Join Date
    Mar 2006
    Location
    You'll get some leg tonight for SURE!
    Posts
    34
    well i think i figured it out, but now i need some more help. This is it so far.
    Code:
    #include <stdio.h>
    
    
    void printset(int [] );
    
    int main()
    {
    	int i = 0, a[25] = {0};
    
    	printf("elements in array are:\n");
    	for(i=0;i<25;i++)
    	{
    		scanf("%d",&a[i]);
    		 
    
    	
    	}
    printset(a);
    return 0;
    
    }
    	void printset(int a[])
    	{int i;
    	printf("{");
     for (i=0;i<25;i++)
     {
    
    	printf("%d, ",a[i]);
    
    
    	
    	
    	}
    	
    		printf(" }\n");
    }
    now how would i go about making it so the user doesn't HAVE to enter 25 numbers...just somewhere between 0 and 25?

  3. #3
    Registered User
    Join Date
    Feb 2006
    Posts
    17
    Your formatting is horrible

    Well, you could ask the user to enter a negative number when he or she is done inputing the other numbers.

  4. #4
    I am Diamond Dave
    Join Date
    Mar 2006
    Location
    You'll get some leg tonight for SURE!
    Posts
    34
    Quote Originally Posted by tcpl
    Your formatting is horrible

    Well, you could ask the user to enter a negative number when he or she is done inputing the other numbers.
    i'll do that

    i know my formatting is horrible this is just a rough draft i'm trying to get done quickly....I don't really care. Now my computer decided to crash and visual C++ is being worthless and i can't use it anymore so i'm screwed since my assignment is due in 15 minutes.

  5. #5
    Registered User
    Join Date
    Mar 2006
    Posts
    150

    umm

    ok, maybe im just missing it, but is there anywhere in this code where youre acutally having your user enter numbers? I could just be overlooking it, but...

  6. #6
    I am Diamond Dave
    Join Date
    Mar 2006
    Location
    You'll get some leg tonight for SURE!
    Posts
    34
    Quote Originally Posted by xixpsychoxix
    ok, maybe im just missing it, but is there anywhere in this code where youre acutally having your user enter numbers? I could just be overlooking it, but...
    Code:
    	for(i=0;i<5;i++)
    	{
    		scanf("%d",&a[i]);
    		 
    
    	
    	}

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. using realloc for a dynamically growing array
    By broli86 in forum C Programming
    Replies: 10
    Last Post: 06-27-2008, 05:37 AM
  2. problem copy from array to another
    By s-men in forum C Programming
    Replies: 3
    Last Post: 09-07-2007, 01:51 PM
  3. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 02:51 PM
  4. C Filling and Printing a 2-d array
    By Smoot in forum C Programming
    Replies: 3
    Last Post: 11-13-2003, 08:42 PM
  5. Replies: 2
    Last Post: 08-03-2003, 10:01 AM