Thread: Array

  1. #1
    Registered User
    Join Date
    Nov 2016
    Posts
    1

    Question Array

    Hi, I'm new at C Programming. I need to find even numbers that are inserted by the user then to select the numbers which can be diveded by 6 and then to multiply those numbers.

    Array-qixjcmz-png

    As you can see I need to multiply 12 and 18, but i dont know how. ( Sorry for a foreign language in the image). Can someone tell me how?

    Code:
    #include <stdio.h>
    
    int main()
    {
        int a[50], i, n, p;
    
    
    //  Vector size
        printf("Introduceti marimea vectorului:\n");
        scanf ("%d", &n);
        printf("\n");
    
    
    //  Elements added by the user
        printf("Introduceti valorile elementelor:\n");
        for   (i=0; i<n; i++)
        {
            scanf("%d", &a[i]);
        }
        printf("\n");
    
    
    //  Even numbers
        printf("Numerele pare din vector sunt:\n\n");
        for (i=0; i<n; i++)
        {
            if (a[i] % 2 == 0)
            {
                printf("%d\t", a[i]);
            }
        }
    
    
    //  Even numbers that can be divided by 6 ( + i need to multiply those numbers)
        printf("\n\nNumerele pare care se impart la 6 fara rest sunt:\n\n");
        for (i=0; i<n; i++)
        {
            if (a[i] % 6 == 0)
            {
                printf("%d\t", a[i]);
            }
        }
    
    
    
    
    
    
        printf("\n\n\n");
    
    
    
    
        return 0;
    }
    p.s. And I am sorry for my english. Have a nice day!

  2. #2
    Registered User
    Join Date
    Jun 2011
    Posts
    4,513
    I would suggest creating a variable to keep a running product. Whenever an array value is divisible by 6, multiply the product variable by that array value. Be sure the product variable is initialized, and to a sensible value.

Popular pages Recent additions subscribe to a feed

Similar Threads

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

Tags for this Thread