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
What are the characteristics of arrays in c?
What is the difference between printf and scanf )?
Why pointers are used?
What are lookup tables in c?
please explain every phase in the "SDLC" in the dotnet.
Explain what will the preprocessor do for a program?
Differentiate between functions getch() and getche().
What is void main () in c?
What are directives in c?
What functions are used in dynamic memory allocation in c?
Explain main function in c?
the number of measuring units from a arbitrary starting point in a record area or control block to some other point a) branching b) recording pointer c) none d) offset
Tell me can the size of an array be declared at runtime?
How can I sort a linked list?
How can I list all of the predefined identifiers?