0
#include<iostream>
using namespace std;
int main(){
    int n;
    cin>>n;
    int arr[n];
    arr[0]=1;
    arr[1]=1;
    if(1<=n&&n<=1000)
    {
        return 0;
    }
    for(int i=2;i<n;i++)
    {
        arr[i]=arr[i-1]+arr[i-2];
    }
    for(int i=0;i<n;i++)
    {
        cout<<arr[i];
    }
    cout<<arr[n-1];
    return 0;
}

The program asks user to enter 'n' and then the program ends without any output.

Output:

6


...Program finished with exit code 0 Press ENTER to exit console.
Adrian Mole
  • 49,934
  • 160
  • 51
  • 83
Vedant Joshi
  • 31
  • 1
  • 2
  • 2
    Variable length arrays (`int arr[n]`) are not standard C++ https://stackoverflow.com/questions/7812566/why-no-variable-size-array-in-stack – ShadowMitia Sep 27 '21 at 16:45
  • Be aware of that `int arr[n];` when `n` isn't `constexpr` is not supported by standard C++. Use `std::vector arr(n);` instead. – Ted Lyngmo Sep 27 '21 at 16:45
  • 2
    Terminology: ***Compiler** asks user to enter 'n'* -> ***Program** asks user to enter 'n'*. The compiler has long since finished its job by the time you run the program. – user4581301 Sep 27 '21 at 16:50
  • 3
    Fibonacci 1000 = 43466557686937456435688527675040625802564660517371780402481729089536555417949051890403879840079255169295922593080322634775209689623239873322471161642996440906533187938298969649928516003704476137795166849228875 I'm curious where you're going to store that. – Pepijn Kramer Sep 27 '21 at 16:54
  • 1
    Your program only accepts inputs less than 1 or greater than 1000. Did you mean `if (n < 1 || n > 1000) { return 0; }`? – molbdnilo Sep 27 '21 at 17:00

1 Answers1

3

It exits here:

    if(1<=n&&n<=1000)
    {
        return 0;
    }

because 6 is greater than 0 and less than 1000

Vlad Feinstein
  • 10,960
  • 1
  • 12
  • 27
  • Or in OP:s notation: `1 <= 6 && 6 <= 1000` (1 is less than or equal to 6) and (6 is less than or equal to 1000). – Ted Lyngmo Sep 27 '21 at 16:53