read a number & print all its devisors using c-program?
Answers were Sorted based on User's Feedback
Answer / vclingisetty@gmail.com
#include<stdio.h>
#include<conio.h>
void main()
{
int n,i;
clrscr();
printf("enter a number\n");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
if(n%i==0)
printf("%d",i);
}
getch();
}
Is This Answer Correct ? | 3 Yes | 0 No |
Answer / 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 |
What's the best way to declare and define global variables?
why do we use pointer instead directly acessing the data?
Write a main() program that calls this function at least 10 times. Try implementing this function in two different ways. First, use an external variable to store the count. Second, use a local variable. Which is more appropriate?
Why is it that not all header files are declared in every C program?
with out using main how to execute the program?
size maximum allocated by calloc()
Define function ?Explain about arguments?
2 Answers Geometric Software, Infosys,
Explain what is wrong in this statement?
diff between exptected result and requirement?
What are the three constants used in c?
There are 21 people in a room. They have to form groups of 3 people each. How many combinations are possible? Write a C program to print the same.
What is oops c?