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


Please Help Members By Posting Answers For Below Questions

any function have arguments one or more OR not . it is compulsary a) any function compulsary have one or more arguments b) any function did not have arguments. It is not compulsary c) it is optional it is not compulsary d) none of the above

858


What do you mean by dynamic memory allocation in c? What functions are used?

887


What is int main () in c?

859


What is the importance of c in your views?

809


Explain union. What are its advantages?

817


What are identifiers in c?

882


what is the difference between north western polytechnique university and your applied colleges?? please give ur answers for this. :)

2127


Why c is called free form language?

764


Why ca not I do something like this?

782


What is actual argument?

819


How can I manipulate individual bits?

801


a program that can input number of records and can view it again the record

1695


What is the difference between break and continue?

943


What is the significance of c program algorithms?

872


Can we change the value of static variable in c?

750