Thread: Help with my C Program

  1. #1
    Registered User
    Join Date
    Oct 2017
    Posts
    2

    Lightbulb Help with my C Program

    Here is what I have so far.


    Code:
        #include <stdio.h>
    
    
        #define N 10
    
    
        int inner_product(int a[], int b[], int n);
        int inner_product_reverse(int a[], int b[], int n);
    
    
        int main (void)
        {
        int a[N], b[N], i;
    
        printf("Enter the first array of size 10: ")
        for(i=0; i<N; i++)
        scanf("%d", &a[i]);
    
        printf("Enter the second array of size 10: ")
        for(i=0; i<N; i++)
        scanf("%d", &b[i]);
    
    
        printf("Inner product is: %d\n", inner_product(a, b, i));
        printf("Inner product reverse is: %d\n", inner_product_reverse(a,b, i));
    
        return 0;
        }
    
        int inner_product(int a[], int b[], int n)
        {
    
        int sum = 0, i;
        for (i = 0; i<N; i++)
        sum += (a[i] * b[i]);
        return sum;
        {
    
        int inner_product_reverse(int a[], int b[], int n)
        {
        int sum = 0, i;
        for (i = 0; i<N; i++)
        sum += (a[i] * b[N-i]-i);
        return sum;
        }
    Attached Images Attached Images Help with my C Program-screen-shot-2017-10-04-4-09-13-pm-jpg 
    Last edited by Salem; 10-05-2017 at 10:26 AM. Reason: put the original code back

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    37,533
    Your brace at line 38 is open, not close.
    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.

  3. #3
    Registered User
    Join Date
    Oct 2017
    Posts
    2
    thanks fix it but I still have an issue with Inner product reverse is: not showing -254?

  4. #4
    Registered User
    Join Date
    Jun 2011
    Posts
    4,509
    Please don't delete your code as you've done. This renders the thread useless, as the context is no longer present.

    If you're still having a problem, re-post your updated code and we can go from there.

  5. #5
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    37,533
    Put the original code back for site posterity.
    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: 5
    Last Post: 03-15-2016, 03:29 PM
  2. Replies: 7
    Last Post: 03-15-2016, 06:35 AM
  3. Replies: 2
    Last Post: 09-09-2014, 02:36 PM
  4. Replies: 2
    Last Post: 12-11-2012, 12:25 AM
  5. Replies: 1
    Last Post: 03-03-2009, 04:47 PM

Tags for this Thread