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
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
What do you mean by dynamic memory allocation in c? What functions are used?
What is int main () in c?
What is the importance of c in your views?
Explain union. What are its advantages?
What are identifiers in c?
what is the difference between north western polytechnique university and your applied colleges?? please give ur answers for this. :)
Why c is called free form language?
Why ca not I do something like this?
What is actual argument?
How can I manipulate individual bits?
a program that can input number of records and can view it again the record
What is the difference between break and continue?
What is the significance of c program algorithms?
Can we change the value of static variable in c?