Thread: passing values in array

  1. #1
    Registered User
    Join Date
    Feb 2003
    Posts
    17

    passing values in array

    trying to take values at i, if x is moded by i and equals 0 then scan factor into array, then print value of factored array,,, problem is it loops permanently or gives me a whole bunch of garbage, if anyone can point me in the right direction it would be appreciated,,,,
    thnx



    Code:
    int Factor ()
    	{
    	
    	int i=0, x=0, num1 , j=0;
    	int n[50];
    	x=GetNum(num1);
    	printf("The Factors are:\n");
    	for ( i = x; i > 0; i--)
    	{
    	
    		if (x % i == 0)
    		for(j=i; j > 0; j++)
    		{
    		scanf(" %d",&n[j]);
    		
    		for(j=0; j>=50; j++)
    		{
    		printf("%d ",&n[j]);
    		}
    	}
    }
    printf("\n\n");         
    }

  2. #2
    Registered User Azuth's Avatar
    Join Date
    Feb 2002
    Posts
    236
    OK. I've just thrown this together, it may just compile without the use of duct-tape.

    Code:
    #include <stdio.h> 
    
    int main(int argc, char* argv[])
    {
    
    		
    	int i=0, j=0;
    	int x=54;
    	int n[50];
    	
    	printf("The Factors are:\n");
    	
    	for (i=1;i < (x/2);i++)
    	{
    		if (x % i == 0)
    		{
    			n[j]=i;
    			j++;
    		}
    					
    	}
    		
    
    	for(i=0; i<j; i++)
    		printf("%d ",n[i]);
    	
    	printf("%d ",x);
    	printf(" are all factors of %d\n",x);
    		
    	return 0;
    
    }
    I hope that's along the lines of what you're trying to accomplish.
    Demonographic rhinology is not the only possible outcome, but why take the chance

  3. #3
    Registered User
    Join Date
    Feb 2003
    Posts
    17
    your code compiles execpt there is no printed output, i guess there is an error in logic somewhere thnx for the help

  4. #4
    Registered User
    Join Date
    Feb 2003
    Posts
    17
    this worx thnx man
    Code:
    int Factor ()
    	{
    	
    	int i=0, x=0, num1 , j=0;
    	int n[50];
    	x=GetNum(num1);
    	printf("The Factors are:\n");
    	for ( i=x; i > 0; i--)
    	{
    	
    		if (x % i == 0)
    		{
    			n[j]=i;
    			j++;
    		}
    	}
    		for(i=0; i<j; i++)
    		{
    		printf("%d ",n[i]);
    		}
    		printf(" are all factors of %d\n",x);
    	                printf("\n\n");         
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help passing nxn array to 2d array.
    By beglaryanh in forum C Programming
    Replies: 2
    Last Post: 06-06-2009, 05:23 PM
  2. Passing a double array from main to another function
    By Loctan in forum C++ Programming
    Replies: 2
    Last Post: 01-04-2005, 05:19 PM
  3. Passing my array to function
    By pooty tang in forum C Programming
    Replies: 8
    Last Post: 09-15-2004, 12:19 PM
  4. accessing array of structs values
    By WaterNut in forum C++ Programming
    Replies: 12
    Last Post: 07-08-2004, 08:47 PM
  5. Passing pointers between functions
    By heygirls_uk in forum C Programming
    Replies: 5
    Last Post: 01-09-2004, 06:58 PM