Subscribe

RSS Feed (xml)

Friday, May 22, 2009

Write a C program to find the factors of a given integer.

#include(stdio.h>
#include(conio.h)
void main( )
{
int no,x;
clrscr( );
printf("Enter the required number:");
scanf("%d",&no);
printf("\nThe factors are:");
for(x=1; x<=no; x++)
{
if(no%x==0)
printf("\n%d",x);
}
getch( );
}

Output:-
Enter the required number: 27
The factors are:
1
3
9
27

15 comments:

  1. superb boss....thanx.its working......write for other programs..vil be helpful for beginners....

    ReplyDelete
  2. hi can u write factors of a program by using while loop

    ReplyDelete
    Replies
    1. main()
      {
      int c=1,n;
      printf("Enter any number\n");
      scanf("%d",&n);
      while(c<=n/2)
      {
      if(n%c==0)printf("%d\t",c);
      c++;
      }
      }

      Delete
  3. wow thats cool programing concept .really i will become a software developer.

    ReplyDelete
  4. superrrrrrrrrrrrrrrrrbbbbbbbbbbbbbb bosssssssssssssssssss

    ReplyDelete
  5. for(x=1;x<=no/2;x++) this for loop also give the same output.

    ReplyDelete
  6. thanx a lot. nice trying

    ReplyDelete
  7. nice
    but what abt negative numbers

    ReplyDelete
  8. wt is presentation error plz tel me any one

    ReplyDelete
  9. Nice................
    Basic C Program for Computer Programmer who want to learn. If you have simple wish you may visit. To get all update stay with us.
    Outline:
    • Language: C and Simscript.
    • if (Condition) statement and Nested if statement is used to determine the given number is positive, negative, even or odd. Another way we solve this program using if-else-if ladder.
    • When the given condition or expression is true the statement associated with it executed.
    To know details:

    http://www.secufoon.com/write-a-c-program-for-determining-a-number-is-positive-negative-even-or-odd/

    ReplyDelete
  10. after the factor of no. then squaring and add the factor of the no.

    ReplyDelete
  11. can anyone send me the algorithm for c program to find factors of the give number ?

    ReplyDelete
  12. How to find for negative nmrs

    ReplyDelete