Skip to content

Instantly share code, notes, and snippets.

@cenrak
Created November 20, 2013 21:30
Show Gist options
  • Save cenrak/7571414 to your computer and use it in GitHub Desktop.
Save cenrak/7571414 to your computer and use it in GitHub Desktop.
#include <iostream>
int main()
{
int num = 0;
int count = 0, sum = 0, i, j, p;
char c;
printf("Enter a number :\n ");
c = getchar();
while (c != '\n')
{
num *= 10;
num += c - '0';
if ((int)c < 48 || (int)c > 57)
{
printf("wrong input");
return 0;
}
c = getchar();
}
if (num>30000 || num<1)
{
printf("wrong input");
return 0;
}
printf("the number is : %d\n", num);
if (num == 1)
{
printf("There is 0 divids");
return 0;
}
for (i = 2; i<num; i++)
{
if (num%i == 0)
{
p = 1;
for (j = 2; j<i; j++)
if (i%j == 0)
p++;
if (p = 1)
{
count++;
sum = sum + i;
num = num / i;
i = 2;
}
if (num == 1)
{
count++;
sum = sum + i;
num = num / i;
}
}
}
if (count >= 1)
{
count += 1;
sum = sum + num;
}
if (count == 0)
{
printf("num is prime");
return 0;
}
else
{
printf("there are %d divdes\n", count);
printf("the sum is %d", sum);
return 0;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment