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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T17:59:28+00:00 2026-06-08T17:59:28+00:00

I am solving a problem of adding the last digits of numbers lying between

  • 0

I am solving a problem of adding the last digits of numbers lying between a range (for ex. between ‘m’ and ‘n’ where m < n).I have coded this

 #include <stdio.h>

 int main()
 {
 int t=0;
 long int m=0,n=0,num=0,sum=0,lsum=0,i=0;
 scanf("%d",&t);
 while(t--){
    scanf("%ld%ld",&m,&n);
    i=m;
    while(i<=n){
       while(i!=0){
          num=i%10;
          i/=10;
       }
       lsum=lsum+(sum%10);
       i++;
    }
}
printf("\n%ld",lsum);
return 0;
}

Here t=No of Test Cases. m and n is the range. I don’t know why it is running infinitely in the terminal. I am using gcc(4.3.2) compiler.How can I optimize it for speed ,or is it the case where the while conditions are never terminated, but why?

  • 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-08T17:59:29+00:00Added an answer on June 8, 2026 at 5:59 pm

    You are dividing the i: i/=10. This means that i is always set back to 1 at the end of the loop. You should use a temporary variable for the dividing.
    Like this:

        while(i<=n){
           int temp = i;
           while(temp !=0){
              num=temp %10;
              temp /=10;
           }
           lsum=lsum+(sum%10);
           i++;
        }
    

    P.S. There are many other errors in your code. But they are not connected with the infinite looping.

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

Sidebar

Related Questions

I need some help in solving this problem. We have a large amount of
I have tried solving this problem by posting other related questions here that focused
I'm trying to work out a graceful way of solving this problem. I have
Am stuck on solving this problem. Say I have 2 ipads placed as shown
I've been problem solving this for the past few hours and frustratingly can't find
This question is more about guidance than actually solving my problem: I need to
I was practising the algorithm based programming problem.I am having difficulty,in solving this problem.I
Can anyone please help me by solving problem in my application.I have three input
I'm solving a problem that consist in generate the first n<1000000 lucky numbers, but
Any advice on solving this problem?

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.