read a number & print all its devisors using c-program?

Answers were Sorted based on User's Feedback



read a number & print all its devisors using c-program? ..

Answer / karna

//all devisors of a number
#include<stdio.h>
#include<conio.h>
void main()
{
int n,i;
printf("Enter the number");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
if((n%i)==0)
{
printf("%d\n",i);
}
else;
}
getch();
}

Is This Answer Correct ?    6 Yes 0 No

read a number & print all its devisors using c-program? ..

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

read a number & print all its devisors using c-program? ..

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

Post New Answer

More C Interview Questions

If null and 0 are equivalent as null pointer constants, which should I use?

0 Answers  


How can you check to see whether a symbol is defined?

0 Answers  


What is const keyword in c?

0 Answers  


What is enumerated data type in c?

0 Answers  


what will be the output of" printf("%d%d",scanf("%d% d",&a&b));"

4 Answers  


Is c object oriented?

0 Answers  


Explain what is a static function?

0 Answers  


What is return in c programming?

0 Answers  


Differentiate between the expression “++a” and “a++”?

0 Answers  


What do you understand by friend-functions? How are they used?

0 Answers   iNautix,


what is the difference between NULL & NUL keywords in C?

3 Answers  


#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..

3 Answers  


Categories