Author Topic: C Program for possible divisors for a number  (Read 1058 times)

kathir

  • Administrator
  • Sr. Member
  • *****
  • Posts: 283
C Program for possible divisors for a number
« on: November 19, 2011, 06:43:47 am »
Write a program that prompts the user to insert a number and prints all the numbers that are divisible with it.(by using do-while statement)

Please insert a number: 24
The divisors are:
2 3 4 6 8 12


Code:
//Source Code Listing

#include <stdio.h>

void main()
{
   int i, n;
   printf("\nProgram for divisors");
   printf("\nEnter a Number : ");
   scanf("%d", &n);
   printf("\nThe divisors for %d : ", n);
   i = 1;
   do
   {
      if( (n%i) == 0)
         printf("%d ", i);
      i++;
   }
   while(i <= n/2);
   return;
}

 


Disclaimer: This web site is for educational and informational purposes only. Click here to read the Disclaimer.
Content copyright 2010-2014. Kathiresan. All rights reserved.
This page is using SMF version 2.0.1