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 7686649
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T19:31:39+00:00 2026-05-31T19:31:39+00:00

This is what I made: #include <stdio.h> #include <stdlib.h> int betweenArray(int a, int b){

  • 0

This is what I made:

#include <stdio.h>
#include <stdlib.h>

int betweenArray(int a, int b){
    int *arr,i,range;
    range = b - a + 1;
    arr = (int *)malloc(range*sizeof(int));
    for(i=0;i<range;i++){
        arr[i] = a++;
    }
return * arr;

int main (int argc, const char * argv[]) {
    int a,b,i;
    int range;

    printf("Give numbers: ");
    scanf("%d %d",&a,&b);
    range = b - a + 1;


    for(i=0;i<range;i++)
        printf("%d\n",betweenArray(a,b)); 
    return 0;
}

So when I run this and give for example 2 and 5 as arguments I get as a result: 2 2 2 2 instead of 2 3 4 5. I can’t find where I made my mistake.

  • 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-31T19:31:40+00:00Added an answer on May 31, 2026 at 7:31 pm

    The problem is that you’re calculating the sequence, but you only return the first number of it.

    The return value of betweenArray is int instead of int * and you do return * arr; instead of return arr;. After fixing that, in main, you would need to do:

    int *sequence = betweenArray(a,b);
    for (i=0;i<range;i++)
        printf("%d", sequence[i];
    

    But it would be better if the function would return the array and the number of elements in it, for example like that:

    int *betweenArray(int a, int b, int *numElements){
        int *arr,i,range;
        range = b - a + 1;
        arr = (int *)malloc(range*sizeof(int));
        for(i=0;i<range;i++){
            arr[i] = a++;
        }
        if (numElements) {
            *numElements = range;
        }
        return arr;
    }
    
    int main (int argc, const char * argv[]) {
        int a,b,i;
        int *sequence;
        int range;
    
        printf("Give numbers: ");
        scanf("%d %d",&a,&b);
    
        sequence = betweenArray(a,b,&range);
    
        for(i=0;i<range;i++)
            printf("%d\n",sequence[i]);
    
        free(sequence); // Be nice, clean up.
        return 0;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I made this program to print up time in hours,minutes and seconds #include<stdio.h> int
This is the code #include <stdbool.h> #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <string.h>
Source: #include <stdio.h> void main() { int i, j, tree_Size, spaces, total_Spaces, x; char
#include <stdio.h> #include <stdlib.h> typedef int element; struct cell { element e; struct cell
I made this implementation for this problem : http://www.spoj.pl/problems/SHOP/ #include<iostream> #include<stdio.h> #include<queue> #include<conio.h> #include<string.h>
#include<stdio.h> int main() { int x = 1,*t; float y = 1.50,*u; char k
#include <stdio.h> char converter(char input[]); char getInformation (char input[]); int main(){ char c[99]; int
I want to include Flip view in my project. I made it like this
I made this method + (CGFloat) round: (CGFloat)f { int a = f; CGFloat
This was the question asked to me in an interview in c: #include<stdio.h> void

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.