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

  • SEARCH
  • Home
  • 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 9232257
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T06:16:16+00:00 2026-06-18T06:16:16+00:00

I have an assignment to write a recursive program that gets an array (lets

  • 0

I have an assignment to write a recursive program that gets an array (lets call it arr1), the size of the array (n), and a value(s).
The program will check if there are two numbers in the array so that their summary is s.
example
if the array is {1,3,2,0,5} and s=7, then the function will print “yes” because 5+2=7.
if the array is {1,3,2,0,5} and s=9, then the function will print “no”. no summary of a pair is equal to 9.

My algorithm works like this:
i calculate the summary of the last spot in the array (arr1[n-1]), with every other spot. if i find a couple that their sum is s, great, print yes and leave.
if i dont find, then i do the same, but instead of arr1[n-1] i check arr1[n-2]. i delete the last spot.

Here’s my code:

#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
void input_array_dyn(int* a, int n);
void rec(int* a,int n, int s);
void main()
{
    int n=0,s=0;
    int* a;
    printf("Enter value S\n");
    scanf("%d",&s);
    printf("Enter the size of the array\n");
    scanf("%d",&n);
    a=(int*)calloc(n,sizeof(int));
    printf("Enter %d values for the array\n",n);
    input_array_dyn(a,n);
    rec(a,n,s);
    free(a);
    getch();
}
void input_array_dyn(int* a,int n)
{
    int i=0;
    for(i=0;i<n;i++)
        scanf("%d",a[i]);
}
void rec(int* a,int n, int s)
{
    int i;
    if(n==1)
    {
        printf("There are no 2 number whos summary yields S\n"); 
        return;
    }
    for(i=0;i<n-1;i++)
    {
        if(a[n-1]+a[i]==s)
        {
            printf("There are two numbers that give s\n");
            return;
        }
    }
    rec(a,n-1,s);
}

I get an error saying: “Unhandled exception at 0x5846e30e (msvcr100d.dll) in Test.exe: 0xC0000005: Access violation writing location 0x00000000.”

also: Does anyone have a better idea for an algorithm to do this? 🙂

  • 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-06-18T06:16:17+00:00Added an answer on June 18, 2026 at 6:16 am

    In input_array_dyn():

    scanf("%d", a[i]);
    

    You’ve forgotten a &.

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

Sidebar

Related Questions

For class I have an assignment: Write a C++ program that will output the
I have an assignment to Write a C program that allows a user to
I have an assignment to write a recursive function that writes the digits of
I have this assignment to read, write, enable cookies so that the username will
I have a programming assignment to write a program in C++ that finds all
I have an assignment/project to write a program that displays the integers between 1
I have the following assignment: Write a complete 8086 program to perform the calculator
I have an assignment that wants me to write an ternary search algorithm and
I have been asked to write a program using python for an assignment. I
My assignment was to write a Java class that creates an array of integers,

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.