Computer Science, asked by kanishk200775, 4 months ago

write a program in c++ to print divisors of a given number.

guidelines:
1. include appropriate header files and write the main() function.
2. accept a number from the user and save it in the variable n.
3. declare one iteration variable for numbers 1 to n, say i.
4. check whether n is divisible by i or not.
5. if it is divisible then print i as a factor of a number n.
6. using the looping and conditional statements, find all the divisors of number n.

please write correct I will make you brainliest .​

Answers

Answered by nishthajaiswal
1

Answer:

C++ is a general-purpose programming language created by Bjarne Stroustrup as an extension of the C programming language, or "C with Classes"

Answered by ItzMissKomal
1

Answer:

Input : n = 10

Output: 1 2 5 10

Input: n = 100

Output: 1 2 4 5 10 20 25 50 100

Input: n = 125

Output: 1 5 25 125

// C++ implementation of Naive method to print all

// divisors

#include <bits/stdc++.h>

// function to print the divisors

void printDivisors(int n)

{

for (int i=1;i<=n;i++)

if (n%i==0)

printf("%d ",i);

}

/* Driver program to test above function */

int main()

{

printf("The divisors of 100 are: \n");

printDivisors(100);

return 0;

}

The divisors of 100 are:

1 2 4 5 10 20 25 50 100

Similar questions