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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T02:48:46+00:00 2026-06-14T02:48:46+00:00

i have written the following program however every time i run it, the for

  • 0

i have written the following program however every time i run it, the for loops do not work until i enter another number. The for loops then run, using the second number entered. why is this happening? no one seems to be having this problem… here is the program:

#include <stdio.h>
#include <math.h>

int main(void)
{

float limit;
float count;
float series1, series2;

printf("Enter a limit for the series ");
scanf ("%f", &limit);
while (scanf ("%f", &limit) == 1) 
{
    for (series1 = 1, count = 2; count <= limit; count++)
            series1 += 1.0/count;
            printf ("\nThe sum of the first infinite series is %.4f", series1);
    for (series2 = 1, count = 2; count <= limit; count++)
            series2 += (1.0/count) * pow ((-1),(count - 1));
            printf ("\nThe sum of the second infinite series is %.4f", series2);

        printf("\n\nEnter a limit for the series (q to quit) ");
        scanf ("%f", &limit);
}
return 0;

}
  • 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-14T02:48:48+00:00Added an answer on June 14, 2026 at 2:48 am

    Your problem is right here:

    scanf ("%f", &limit);
    while (scanf ("%f", &limit) == 1)
    

    The while loop is going to execute that scanf everytime it starts, so just lose the first scanf.

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

Sidebar

Related Questions

I have written the following very simple Java program to ask user enter a
I have written the following C program. The output is 32. Why is this?
i have written the following code class Program { static void Main(string[] args) {
I have written down the following program that uses the quicksort algorithm to sort
I have the following method for my android program, written in Java. The method
I have just written a program to run as a Windows Service Application, GasMeterMonitoring;
I am a newbie in Python. I have written following program and expecting all
I have written a program to calculate roots of a Weyl group. However, I
I have written following code to attach gesture recogniser to multiple imageviews. [imageview1 setUserInteractionEnabled:YES];
I am trying my hands on WPF MVVM. I have written following code in

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.