K. Divisors Using C

πŸ” Problem Solving from Codeforces using C language

This is a problem-solving post from Codeforces. Below is the problem with a short explanation and its solution.

This example is solved using C language.

🧩 Main Problem:Given a number N. Print all the divisors of N in ascending order.

πŸ”— Problem Link: Codeforces Problem

πŸ’‘ Solution:

#include<stdio.h>
int main()
{
    int n;
    scanf("%d", &n);
    for (int i =1; i<=n; i++)
    {
        if (n%i==0) // here, input n is checking by all numbers of "i" is that divisible or not
        {
            printf("%d\n", i);
        }
    }
    return 0;
}

βœ… This solution reads an integers “n” from user and then find the divisors of “n” in ascending order.

πŸ“ Input:

6

πŸ“„ Output:

1
2
3
6

πŸ“ Input:

7

πŸ“„ Output:

1
7

πŸ”— Find Similar Problems from Codeforces– Click Here

πŸ€” More Problem Solving – Click Here

πŸ“˜ Learn C Programming β€“ Click Here

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top