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

a character or group of characters that defines a register,or a part of storage a) memory b) byte c) address d) linear list

0 Answers  


Why do we need arrays in c?

0 Answers  


application areas a 'c' a) operating system b) graphics, interpreter, assembler c) program evalution, communication softwares d) all the above

0 Answers  


What does & mean in scanf?

0 Answers  


Write a program to generate the first n terms in the series --- 2,3,5,7,11,...,17

0 Answers  






If jack lies on Mon, Tue Wed and jill lies on Thursday, Friday and Saturday. If both together tell they lied yesterday. So c the given options and then c cos in the given dates one will be saying the truth and one will be lying. I got Thursday as option because jack is saying the truth he lied yest but jill is lying again as he lies on that day.

0 Answers   TCS,


typedef struct { int i:8; char c:9; float f:20; }st_temp; int getdata(st_temp *stptr) { stptr->i = 99; return stptr->i; } main() { st_temp local; int i; local.c = 'v'; local.i = 9; local.f = 23.65; printf(" %d %c %f",local.i,local.c,local.f); i = getdata(&local); printf("\n %d",i); getch(); } why there there is an error during compiling the above program?

1 Answers  


Explain what is wrong with this program statement? Void = 10;

0 Answers  


size maximum allocated by calloc()

3 Answers   DELL,


If input is 123 then how to print 100 and 20 and 3 seperately?

4 Answers  


Explain the use of bit fieild.

0 Answers  


#include<std.h> int main() { char *str[]={"Frogs","Do","Not","Die","They","Croak!"}; printf("%d %d\n",sizeof(str),strlen(str)); ...return 0; } what will the output of the above program?

6 Answers  


Categories