write an interactive program to generate the divisors of a
given integer.

Answers were Sorted based on User's Feedback



write an interactive program to generate the divisors of a given integer...

Answer / neo

#include <stdio.h>

void div(int n){
int i=2;
while(n%i!=0 && i!=n){
i++;
}
printf("%d ",i);
if(i!=n){
div(n/i);
}

}

main(){
int i;
printf("Enter number:");scanf("%d",&i);
printf("1 ");
div(i);
}

Is This Answer Correct ?    25 Yes 11 No

write an interactive program to generate the divisors of a given integer...

Answer / rakesh ranjan

#include<conio.h>
#include<stdio.h>
main()
{
int n,i;
printf("entre the number");
scanf("%d",&n);
for(i=2;i<n;i++)
{
if(n%i==0)
printf("%d\n",i);
}
getch();
}

Is This Answer Correct ?    15 Yes 2 No

write an interactive program to generate the divisors of a given integer...

Answer / dally

#include<stdio.h>
int main()
{
int n,i=1;
printf("Value for n\n");
scanf("%d\n",&n);
while(i<=n)
{
if(n%i == 0)
printf("%d\n",i);

i++;
}
}

Is This Answer Correct ?    8 Yes 5 No

write an interactive program to generate the divisors of a given integer...

Answer / tamil

void div(int n){
static int i=1;
while(i<=n){
if(!(n%i))printf(" %d",i);
i++;
}
}

main(){
int i;
clrscr();
printf("Enter number:");scanf("%d",&i);
div(i);
getch();
}

Is This Answer Correct ?    11 Yes 9 No

write an interactive program to generate the divisors of a given integer...

Answer / 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

write an interactive program to generate the divisors of a given integer...

Answer / pradeep

same program as above, optimising it a little bit.

#include<stdio.h>
int main()
{
int n,i=1;
printf("Value for n\n");
scanf("%d\n",&n);
while(i <= n/2)
{
if(n%i == 0)
printf("%d\n",i);

i++;
}
printf("%d\n",n);
}

Is This Answer Correct ?    2 Yes 7 No

write an interactive program to generate the divisors of a given integer...

Answer / buya

111,111,111*111,111,111=12345678910987654321

Is This Answer Correct ?    2 Yes 8 No

Post New Answer

More C Interview Questions

read the folllowing code # define MAX 100 # define MIN 100 .... .... if(x>MAX) x=1; else if(x<MIN) x=-1; x=50; if the initial value of x=200,what is the vlaue after executing this code? a.200 b.1 c.-1 d.50

4 Answers   TCS,


What is a char c?

0 Answers  


How do you use a 'Local Block'?

0 Answers   Ericsson,


Describe wild pointers in c?

0 Answers  


What are the different pointer models in c?

4 Answers  






What is array of structure in c programming?

0 Answers  


2.main { int x,j,k; j=k=6;x=2; x=j*k; printf("%d", x);

9 Answers   HCL, Tech Mahindra,


to print the salary of an employee according to follwing calculation: Allowances:HRA-20% of BASIC,DA-45% of BASIC,TA-10%. Deductions:EPF-8% of BASIC,LIC-Rs.200/-Prof.Tax:Rs.200/- create c language program?

0 Answers  


How does sizeof know array size?

0 Answers  


What is meant by int fun const(int a, int b) { .... ... }

1 Answers  


Can you please explain the difference between syntax vs logical error?

0 Answers  


Write a progarm to find the length of string using switch case?

0 Answers   TCS,


Categories