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 |
which is faster execution: loops or recursion?
how do you write a function that takes a variable number of arguments? What is the prototype of printf () function?
Explain what would happen to x in this expression: x += 15; (assuming the value of x is 5)
Write a C program to remove the repeated characters in the entered expression or in entered characters(i.e) removing duplicates
In c programming typeing to occupy the variables in memory space. if not useing the variable the memory space is wasted.ok, how to avoid the situation..? (the variable is used & notused)
I need a help with a program: Write a C program that uses data input in determining the whole of points A and a whole of circles B. Find two points in A so that the line which passes through them, cut through the maximum number of circles.
C program to read the integer and calculate sum and average using single dimensional array
Which is best book for data structures in c?
What does the characters “r” and “w” mean when writing programs that will make use of files?
logic for x=y^n
Why is c not oop?
What is the purpose of the fflush() function in C?