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
Program will then find the largest of three numbers using nested if-else statements. User is prompted to enter three numbers. Program will find the largest number and display it on the screen. All three numbers entered by the user are also displayed. If user enters 21, 33, and 5, the output should be as follows: You entered: 21, 33 and 5. The largest number is 33.
the maximum length of a character constant can be a) 1 character b) 8 characters c) 256 chaacters d) 125 characters
What is sizeof array?
What is malloc() function?
What is c definition?
What is an array? What the different types of arrays in 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 anyone suggest some site name..where i can get some good data structure puzzles???
Hi can anyone tell what is a start up code?
What is the difference between break and continue?
What is wrong with this initialization?
Why doesn't C support function overloading?
Why c is a procedural language?
How arrays can be passed to a user defined function
What is the purpose of realloc()?