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 I open files mentioned on the command line, and parse option flags?
What are the header files used in c language?
Explain how do I determine whether a character is numeric, alphabetic, and so on?
What is the best way to store flag values in a program?
What does the message "automatic aggregate intialization is an ansi feature" mean?
What is the difference between char array and char pointer?
Explain how do you sort filenames in a directory?
What is static identifier?
find the value of y y = 1.5x+3 for x<=2 y = 2x+5 for x>2
Write a program of advanced Fibonacci series.
Difference between Function to pointer and pointer to function
What are the parts of c program?
What is the explanation for cyclic nature of data types in c?
Explain low-order bytes.
What is #error and use of it?