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
what is uses of .net
which is conditional construct a) if statement b) switch statement c) while/for d) goto
How can I avoid the abort, retry, fail messages?
Explain heap and queue.
Can a variable be both constant and volatile?
What is static and auto variables in c?
Do you know the use of fflush() function?
How do I send escape sequences to control a terminal or other device?
What is string function c?
What is the difference between c &c++?
Given only putchar (no sprintf, itoa, etc.) write a routine putlong that prints out an unsigned long in decimal. [ I gave the obvious solution of taking % 10 and / 10, which gives us the decimal value in reverse order. This requires an array since we need to print it out in the correct order. The interviewer wasn't too pleased and asked me to give a solution which didn't need the array ].
Can you please explain the scope of static variables?
What is pointer in c?
How do I use void main?
What is the general form of function in c?