Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4097662
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T20:12:08+00:00 2026-05-20T20:12:08+00:00

I need a recursive function in C , that checks/compare the sum of values(integers)

  • 0

I need a recursive function in C, that checks/compare the sum of values(integers) in odd positions, with the sum of values in even positions of an array. Also print(inside the function) the bigger sum!

Like:

printf("\nThe bigger sum is %d. \n evensum = %d , oddsum = %d \n",bigger, evensum, oddsum);

Suppose that array has 8 positions and we fill it from main() with random values.

This is what I have so far:

#include <stdio.h>
#define N 4


int checksum(int matrix[], int position, int sum1, int sum2); 

int main(void)
{
    int mat[N];
    int i,j;

    printf("\nEnter the %d numbers:\n", N); 

      for(i = 0; i < N; i++)
      {
        printf("%2d> ",i);
        scanf("%d", &mat[i]);
      }

      checksum(mat, 0, 0, 0);       


}

int checksum(int m[], int pos, int s1, int s2){

if(pos<N){
    if(pos==0){
            s1 = m[pos];    
            checksum(m, pos+1, s1, s2);         
        }else{
            if(pos%2){
                return s1 + checksum(m, pos+1, s1, s2);     

            }else{
                return s2 + checksum(m, pos+1, s1, s2);                         
            }

        }

    }

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T20:12:09+00:00Added an answer on May 20, 2026 at 8:12 pm

    Besides all the fun they picked at you, I understand you was honest tagging “homework”. What I’m about to show you is your solution. To make the most of this, you should understand it. If not, you are just fooling yourself. I really hope this can help you in other ways than just a homework done.

    You still need to fulfill the vector with random values, and to print the bigger. But this is piece of cake. The recursion can be made like this:

    #include <stdio.h>
    #define MAX 10
    
    int sum(int *x, int n, int odd)
    {
    
        if(odd==-1)
        {
            printf("odd = %d, even = %d\n", sum(x, n, 1), sum(x, n, 0));
            return 0;
        }
    
        if(n%2!=odd)
            return sum(x, n+1, odd);
    
        if(n>=MAX)
            return 0;
    
        return x[n]+sum(x, n+1, odd);
    }
    
    
    
    int main(void)
    {
        int x[MAX]={0,1,2,3,4,5,6,7,8,9};
    
        sum(x, 0, -1);
    
        return 0;
    }
    

    For one thing your question lacks… If you read the definition pausing your mouse cursor at the tag homework, you will read “and show sufficient effort”.

    So, please, after adapting the code as you need, how about you show the final answer here as a token of your effort to learn c language? 😉

    Take care!
    Beco.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How do you verify an array contains only values that are integers? I'd like
for testing purposes i need an recursive directory with some files, that comes to
Need a function that takes a character as a parameter and returns true if
Need a function like: function isGoogleURL(url) { ... } that returns true iff URL
Need to an expression that returns only things with an I followed by either
I have a multi-thread C# application that uses some recursive functions in a dll.
Is there a built in function in jQuery that would allow me to get
I have an array that lists folders in a directory. Until now, I've been
Wondering if I'm barking up the wrong tree. I'd like a recursive function to
I need to get all controls on a form that are of type x.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.