Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

Como hacer un programa con un bucle infinito que muestre los tres primeros divisores de un número?

0 votes
asked Oct 29, 2019 by Franz Angulo Rioja (120 points)

1 Answer

0 votes
answered Aug 6, 2025 by Jerry Jeremiah (2,040 points)
What if the number is 2? Then there is only one divisor.  How do you display 3 divisors?

Also, why do you need an infinite loop since numbers are not infinitely large?  You only need a loop from 1 to n/2.

You could write it like this (this one displays all the divisors - not just three...):

https://onlinegdb.com/YJPVoIzyW3

#include <stdio.h>
#include <stdlib.h>

int main(int argc,char *argv[]) {
    if (argc==1) return 1;
    int n=atoi(argv[1]);
    for (int i=1;i<=n/2;i++)
        if (!(n%i))
            printf("%d\n",i);
    return 0;
}
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and receive answers from other members of the community.
...