I wrote the following program, but every time I run it, for loops do not work until I enter a different number. Then for loops are executed using the second number entered. Why is this happening? no one seems to have encountered 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; }
Your problem is here:
scanf ("%f", &limit); while (scanf ("%f", &limit) == 1)
The while loop will execute this scanf every time it starts, so just lose the first scanf.
When you run the while while while (scanf ("%f", &limit) == 1) , it starts scanf ("%f", &limit) == 1 again after you have already started it. Try setting the first scanf to print the variable and run the variable in a while loop.
while (scanf ("%f", &limit) == 1)
scanf ("%f", &limit) == 1
scanf
Source: https://habr.com/ru/post/1445382/More articles:Using Beautiful Soup Python module to replace tags with plain text - pythonReading lines by lines from multiple byte arrays in Java - javahttps://translate.googleusercontent.com/translate_c?depth=1&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/1445379/using-sqlite-in-windows-8-desktop-app&usg=ALkJrhhuCIAHQs7b_fOA75BSBV3ASmo9iAThe specified weight of the ListView reduces the size when the item is deleted - androidSearch for duplicates in a list, including permutations - listHow to configure spring source code for debugging in eclipse - javaWhat is the difference between SharePoint Web and a site - sharepoint-2010AppDelegate for UIViewController - iosPython - get slice index - pythonhttps://translate.googleusercontent.com/translate_c?depth=1&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/1445387/best-practice-approach-to-relating-mysql-join-queries-to-oop-and-objects&usg=ALkJrhiT65_7UuIkMCKj_Ii8NrqZrIn-zgAll Articles