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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T04:20:30+00:00 2026-05-31T04:20:30+00:00

So I have the code #include <iostream> using namespace::std; int main() { int a

  • 0

So I have the code

#include <iostream>
using namespace::std;
int main() {
    int a = 1;
    int b = 1;
    while (a < 100) {
        a = a + b; 
        b = a + b;
        cout << a << endl;
        cout << b << endl;
    }
}

What it does is print the fibonacci sequence up to 100. But, when I make “a” bigger, say, (OVER 9000!!!) 10 billion, it just prints out random numbers it seems. Why does it 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-05-31T04:20:31+00:00Added an answer on May 31, 2026 at 4:20 am

    This probably happens when you exceed the range of an integer (probably 2,147,483,647 on Windows 32-bit). Try changing the types to long long and see if you get more accurate results to a larger range. Alternatively, you could change add unsigned to the type because the fib. sequence is strictly positive, so that’ll double the range of values.

    This is architecture dependent, but using ranges from http://msdn.microsoft.com/en-us/library/s3f49ktz(v=vs.80).aspx, your ranges would be:

    int: [–2,147,483,648, 2,147,483,647]
    unsigned int: [0, 4,294,967,295]
    long long: [–9,223,372,036,854,775,808, 9,223,372,036,854,775,807]
    unsigned long long: [0, 18,446,744,073,709,551,615]
    

    Edit: totally off-topic, but thanks for putting me over 1k you glorious voting bastards!

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

Sidebar

Related Questions

I have this code #include <iostream> using namespace std; int main(int argc,char **argv) {
I have this simple code: #include <iostream> #include <fstream> using namespace std; int main(void)
I have the following code #include <iostream> #include <vector> using namespace std; int distance(vector<int>&
i have following code for heapsort #include <iostream> using namespace std; void exch(int a[],int
I have the following code compiled by gcc: #include <iostream> using namespace std; class
I have the following code : #include <cstdarg> #include <iostream> using namespace std; class
I've try to compile this code: #include <iostream> #include <cstdlib> using namespace std; #define
I was just wondering something. I have the following code: #include <iostream> using namespace
#include <iostream> #include <vector> using namespace std; int in; bool isPrime(int n) { for
I have following code to accomplish prefix sum task: #include <iostream> #include<math.h> using namespace

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.