Thread: array

  1. #1
    Registered User CASHOUT's Avatar
    Join Date
    Jul 2011
    Location
    Florida
    Posts
    88

    array

    Okay new submission for my last question. I was a little mixed up before. Honestly I kinda still am.

    If the user puts in a 6. I need the array to display the even number from 0 - 6.

    Right now what it does is it displays the first six even numbers.
    Okay as I'm writing this I'm starting to see where my problem might be..


    Code:
    void sumIntegers ()
    {
    int arr[50];
    int i = 0;
    int num = 0;
    int sum = 0;
    
    	
    		printf("\nI want to sum up even integers <= 50.\n\n");
    	
    
    	do
    	{
    		printf("\nPlease enter a positive integer:\n\n\t\t\t");
    			scanf(" %d", &num);
    			
    	
    			if(num < 0)
    				printf("\n*** Negative numbers are invalid! ***\n\n\n");
    
    	
    			
    	for (i = 1; i < num; i++)
    	{
    		arr[i] = 2 * i;
    	}
    	
    	
    	for (i = 1; i < num; i += 1)
    	{
    		printf("%d\n", arr[i]);
    	}
    
    
    	for(i = 1; i < num; i++)
    	{
    		if (arr[i] % 2 == 0)
    		sum += arr[i];
    	}
    	}
    	while(num <= 0);
    
    	printf("\n\nThe sum of the even numbers from 0 to %d = %d\n\n\n", num, sum);
    
    	return;
    }

  2. #2
    Registered User CASHOUT's Avatar
    Join Date
    Jul 2011
    Location
    Florida
    Posts
    88
    Time for some codelab. I'll come back to this

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 10
    Last Post: 09-09-2012, 02:29 PM
  2. Replies: 2
    Last Post: 03-20-2012, 08:41 AM
  3. Replies: 9
    Last Post: 08-23-2010, 02:31 PM
  4. Replies: 6
    Last Post: 11-09-2006, 03:28 AM
  5. Replies: 1
    Last Post: 04-25-2006, 12:14 AM