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 |
If null and 0 are equivalent as null pointer constants, which should I use?
How can you check to see whether a symbol is defined?
What is const keyword in c?
What is enumerated data type in c?
what will be the output of" printf("%d%d",scanf("%d% d",&a&b));"
Is c object oriented?
Explain what is a static function?
What is return in c programming?
Differentiate between the expression “++a” and “a++”?
What do you understand by friend-functions? How are they used?
what is the difference between NULL & NUL keywords in C?
#include <stdio.h> int main() { if ("X" <"x") printf("X smaller than x "); } my question is whats the mistake in this program? find it and please tell me..