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
How can you invoke another program from within a C program?
Explain what is operator promotion?
What is 'bus error'?
what is the function of pragma directive in c?
Is flag a keyword in c?
In a switch statement, explain what will happen if a break statement is omitted?
What is indirection?
What is volatile c?
What are the string functions? List some string functions available in c.
What does dm mean sexually?
What do you mean by scope of a variable in c?
Is c weakly typed?
What is integer constants?
Why do we need a structure?
What are the restrictions of a modulus operator?