read a number & print all its devisors using c-program?
Answer Posted / 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 View All Answers
Write a program to know whether the input number is an armstrong number.
How can I trap or ignore keyboard interrupts like control-c?
What is difference between array and pointer in c?
Does c have enums?
Why & is used in c?
Write a program with dynamically allocation of variable.
What are the different categories of functions in c?
What are types of preprocessor in c?
What does c in a circle mean?
What is union in c?
What would be an example of a structure analogous to structure c?
Can we assign string to char pointer?
What is #include conio h?
Explain how do you list a file’s date and time?
What do you understand by friend-functions? How are they used?