write an interactive program to generate the divisors of a
given integer.
Answer Posted / guest
Optimised!! :-) some extra condition added to avoid printing repeated numbers.
#include<stdio.h>
void dev(int n,int i)
{
if(n <= i) return;
while(i <= n){
if((n % i) == 0){
if(n!=i) printf("%d ",i);
printf("%d ",n/i);
break;
}
i++;
}
dev(n/i,i+1);
return;
}
main()
{
int n;
printf("Enter number:");
scanf("%d",&n);
dev(n,2);
printf("\n");
return 0;
}
| Is This Answer Correct ? | 2 Yes | 5 No |
Post New Answer View All Answers
Explain how are 16- and 32-bit numbers stored?
I have written a pro*C program to fetch data from the cursor. where in i have used the concept of BULK FETCH.... each FETCH statement is taking lots of time to fetch specified number of rows at...
What is binary tree in c?
What is the use of static variable in c?
What are the differences between new and malloc in C?
If the size of int data type is two bytes, what is the range of signed int data type?
What is difference between structure and union with example?
What are the different types of control structures?
Write a C/C++ program to add a user to MySQL. The user should be permitted to only "INSERT" into the given database.
Explain the difference between strcpy() and memcpy() function?
How can you avoid including a header more than once?
What are loops in c?
Which is the best website to learn c programming?
What do you mean by c what are the main characteristics of c language?
Can you explain the four storage classes in C?