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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T22:46:38+00:00 2026-06-13T22:46:38+00:00

Currently I am trying to build a program that prints all armstrongnumbers till a

  • 0

Currently I am trying to build a program that prints all armstrongnumbers till a certain number. I am getting some odd error when trying to run this. It says bufferoverflow.
The part causing it seems to be in main(). Thanks for any help.

#include <stdio.h>
#define MAXIMUM 1000000

int ipow(int x, int power){ 
int z,t;
t = 0;
z = x;
for (t = 0; t < (power - 1); t++) {
    z = z * x; }
return z;
}


int getLength(int x) { 
    int a;
    a = 1;
    for (a=1;1;a++) { if (x < ipow(10,a) && x >= ipow(10,(a-1))) return a; }
}

int getExpSum(int x) { 
    int summe,r,s,t;
    int digit[8]={0,0,0,0,0,0,0,0};
    summe=0;
    s = getLength(x);
    t = x;
    r = 1;
    for (s=getLength(x);s!=0;s--){
        digit[s] = t % 10;
        t = t / 10;
    }
    for(r=1;r<(getLength(x)+1);r++)
    {
        summe = summe + ipow(digit[r],getLength(x));
    }
    return summe;
}

int Armstrong (int x) {
    if (getExpSum(x)==x) {
        printf("%d ist eine Armstrongzahl\n", x);
        return 1;
    }
    return 0;
}

void main(){
    int z;
    z = 0;
    for (z=0;z<MAXIMUM;z++){
        Armstrong(z+1);
    }
}
  • 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-13T22:46:39+00:00Added an answer on June 13, 2026 at 10:46 pm

    There is a problem in your “getLength” Function (actually ipow)

    pass getLength(1) and you get result as 13 because
    ipow(10, 1) and ipow(10, 0) returns 10 so the “getLength” condition fails and it goes for next iteration and goes on.. until the ipow returns a negative number thats 10^13 because of the integer size.

    And inside getExpSum the array digit is of size 8 and it tries to acces the 13th element of it. Hence it crashes

    Add the condition to the ipow function

    int ipow(int x, int power){ 
    int z,t;
    t = 0;
    z = x;
     if (power == 0) //<-----add this condition to your code
         return 1;
    
    for (t = 0; t < (power - 1); t++) {
        z = z * x; }
    return z;
    }
    

    After adding this condition I get the correct result.

    1 ist eine Armstrongzahl
    2 ist eine Armstrongzahl
    3 ist eine Armstrongzahl
    4 ist eine Armstrongzahl
    5 ist eine Armstrongzahl
    6 ist eine Armstrongzahl
    7 ist eine Armstrongzahl
    8 ist eine Armstrongzahl
    9 ist eine Armstrongzahl
    153 ist eine Armstrongzahl
    370 ist eine Armstrongzahl
    371 ist eine Armstrongzahl
    407 ist eine Armstrongzahl
    1634 ist eine Armstrongzahl
    8208 ist eine Armstrongzahl
    9474 ist eine Armstrongzahl
    54748 ist eine Armstrongzahl
    92727 ist eine Armstrongzahl
    93084 ist eine Armstrongzahl
    548834 ist eine Armstrongzahl
    

    BTW the solution can be improved.

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

Sidebar

Related Questions

I am currently trying to build a program where I have a recursive function
I am currently trying to build a little widget that will retrieve a list
I'm trying to build firefox but I'm having some problems. I currently have Visual
I'm currently trying to get a program to compile on a system that I
I am currently trying to develop a small simulation program in xna that takes
I am trying to build a program that parses and lists the content of
I am currently trying to build a small system that read's in a bunch
I am currently trying to build myself a nice few classes to build my
I'm currently trying to build a provisioning service of a kind for a local
I'm currently trying to build a more or less complete set of unit tests

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.