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

Write a program to swap two numbers without using the third variable?

0 Answers  


How to find the given no is odd or even without checking of any condition and loops. (Hint: Using array)

4 Answers  


advantages of pointers?

3 Answers  


Write a program in c to print * * * * * *******

1 Answers  


wat s the meaning of (int *)p +4;

2 Answers  


code for find determinent of amatrix

0 Answers  


Subtract Two Number Without Using Subtraction Operator

0 Answers  


What is the function of this pointer?

0 Answers   Agilent, ZS Associates,


convert 0.9375 to binary

2 Answers   CTS, TANCET,


write a program to swap two variables a=5 , b= 10 without using third variable

5 Answers  


Stimulate calculator using Switch-case-default statement for two numbers

0 Answers   Wipro,


There are N egg baskets and the number of eggs in each basket is a known quantity. Two players take turns to remove these eggs from the baskets. On each turn, a player must remove at least one egg, and may remove any number of eggs provided they all belong to the same basket. The player picking the last egg(s) wins the game. If you are allowed to decide who is going to start first, what mathematical function would you use to decide so that you end up on the winning side? Upload a C program to demonstrate the behaviour of the game.

2 Answers  


Categories