Determining coefficient in geometric progression For an assignment at Uni we had to code a program that takes numbers as input and determines the coefficient if they form a geometric progression once you declare EOF (ctrl+z). If the user inputs a number that doesn't belong to an already established progression the program breaks, telling us there's no geometric progression.

#include &lt;stdio.h&gt;
#include &lt;math.h&gt;

int main(){
int prevNum;
int Num;
scanf_s("%i", &amp;prevNum);
scanf_s("%i", &amp;Num);
int r = Num / prevNum;
prevNum = Num;
while ((scanf("%i", &amp;Num) != EOF))
{
    if (Num / prevNum != r)
    {
        printf("No progression \n");
        return 0;
    }

    else prevNum = Num;


}
    printf("Progression with r=%i \n", r);
    return 0;
}


What I'd like to ask is whether there's a better, more practical way to fulfill the same task.
In the if statement inside the while loop,
since the method returns when the condition is true,
you can drop the else.

In the condition of the while, you have pointless parentheses.

When printing stuff without variables,
I prefer puts instead of printf because it's shorter.

scanf_s doesn't compile with my compiler gcc.
I don't know what it is, but replacing with scanf seems to work fine for me.

Notice in your question that the syntax highlighter made Num have a different color from other variables.
It's because CamelCase is usually used for class names,
and camelCase for variable names.
So I'd rename this to num, or thisNum (to sort of harmonize with prevNum).

Pay attention to formatting. It makes the code more readable. For example:


You didn't indent the main body, then after the while loop you indented.
There are pointless blank lines in the while loop that just look strange.


With the above suggestions applied:

#include &lt;stdio.h&gt;
#include &lt;math.h&gt;

int main() {
    int prevNum;
    scanf("%i", &amp;prevNum);
    int thisNum;
    scanf("%i", &amp;thisNum);
    int r = thisNum / prevNum;
    prevNum = thisNum;
    while (scanf("%i", &amp;thisNum) != EOF)
    {
        if (thisNum / prevNum != r)
        {
            puts("No progression");
            return 0;
        }
        prevNum = thisNum;
    }
    printf("Progression with r=%i \n", r);
    return 0;
}