Wednesday, January 19, 2011

pattern






/****************************
* Umang B Bhatt *
* bhatt.umang7@gmail.com *
*****************************/

/**
* program for pattern
*/


/**
* input: 18
* output: 21 11 1
*
* 18 = 1 2 3 6 9
* now sum of 1 2 3 6 9 is 21
* 21 = 1 3 7
* now sum of 1 3 7 is 11
* 11 = 1
* // we stop at 1
*
*/



#include<stdio.h>


int
fun(int n)
{

int
sum = 0;

int
i;

for
(i = 1; i < n; i++)
{


if
(n % i == 0)
{

sum = sum + i;
}
}


return
sum;

}


void
main()
{

int
n;

int
temp;
printf("\nEnter number: ");
scanf("%d", &n);

/* n is greater than 0*/

temp = n;
while
(temp > 1)
{


temp = fun(temp);
printf("%d ", temp);
}


printf("\n");
}

No comments:

Post a Comment