read a number & print all its devisors using c-program?

Answers were Sorted based on User's Feedback



read a number & print all its devisors using c-program? ..

Answer / karna

//all devisors of a number
#include<stdio.h>
#include<conio.h>
void main()
{
int n,i;
printf("Enter the number");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
if((n%i)==0)
{
printf("%d\n",i);
}
else;
}
getch();
}

Is This Answer Correct ?    6 Yes 0 No

read a number & print all its devisors using c-program? ..

Answer / vclingisetty@gmail.com

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

Is This Answer Correct ?    3 Yes 0 No

read a number & print all its devisors using c-program? ..

Answer / veluri.haritha

BETTER CODE:


void main()
{
int i,n;
clrscr();
printf("Enter the number:");
scanf("%d",&n);
printf("\n\n The divisor's of %d are:",n);
for(i=1;i<=n/2;i++)
{
if(n%i==0)
printf(" %d ",i);
}
printf(" %d ",n);
getch();
}

This is better logic than the above program's.
For any number all factors will exit up to n/2 after n/2
only n is the factor.So, it is enough to execute the loop
for n/2 cycles . By this speed of execution increases.

EVEN BETTER LOGIC IS AVAILABLE 'U' TRY THIS...........
BY
V.HARITHA, B.TECH 1st YEAR..
student of "MADHAVI INFOTECH SOFTWARE TRAINING"
ANANTHAPUR,A.P,INDIA.

Is This Answer Correct ?    1 Yes 0 No

Post New Answer

More C Interview Questions

What's the best way to declare and define global variables?

7 Answers  


why do we use pointer instead directly acessing the data?

2 Answers  


Write a main() program that calls this function at least 10 times. Try implementing this function in two different ways. First, use an external variable to store the count. Second, use a local variable. Which is more appropriate?

2 Answers  


Why is it that not all header files are declared in every C program?

0 Answers  


with out using main how to execute the program?

2 Answers  


size maximum allocated by calloc()

3 Answers   DELL,


Define function ?Explain about arguments?

2 Answers   Geometric Software, Infosys,


Explain what is wrong in this statement?

0 Answers  


diff between exptected result and requirement?

0 Answers   HCL,


What are the three constants used in c?

0 Answers  


There are 21 people in a room. They have to form groups of 3 people each. How many combinations are possible? Write a C program to print the same.

1 Answers   HCL, iGate,


What is oops c?

0 Answers  


Categories