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 |
what is the difference between embedded c and turbo c ?
1. Can we use the for loop this way? for(;i>5;) 2. What is the use of pointers? 3. what is array of pointer? 4. What is the difference between file and database? 5. Define data structure?
Write a program to generate the first n terms in the series --- 9,11,20,31,...,82
Write a program to find the smallest and largest element in a given array in c language
what is pointer
Write a Program to find whether the given number or string is palindrome.
main() { printf(5+"Vidyarthi Computers"); }
Look at the Code: main() { int a[]={1,2,3},i; for(i=0;i<3;i++) { printf("%d",*a); a++; } } Which Statement is/are True w.r.t the above code? I.Executes Successfully & Prints the contents of the array II.Gives the Error:Lvalue Required III.The address of the array should not be changed IV.None of the Above. A)Only I B)Only II C)II & III D)IV
Why is extern used in c?
What are actual arguments?
With the help of using classes, write a program to add two numbers.
What is data structure in c and its types?