½âÌâ˼·
1.ÎÊÌâÓÅ»¯
¢Ù³éÏóÎÊÌ⣬¾ßÌ廯
¢Ú¸´ÔÓÎÊÌ⣬¼òµ¥»¯
2.·ÖÎöÎÊÌâ
¢Ù´ÓÎÊÌâ×ÔÉíÌØÐÔÈëÊÖ
¢Ú¶à¾ÙʵÀý£¬ÕÒµ½Ò»Ð©¹æÂÉ
3.Éè¼ÆËã·¨
ҪôѡÔñ£¬ÒªÃ´Ñ»·
Ñ¡Ôñ£º×öÒ»¼þÊÂÇéÓкܶà¿ÉÄÜÐÔ
¶àÖÖ×ö·¨Ñ¡ÔñÒ»ÖÖ£¬×öÒ»´Î
Ñ»·£ºÖظ´×öÒ»¼þÊ£¬×öºÜ¶à´Î
ÒªËØ£ºÌõ¼þ£¬ÊÂÇé
----------------------------
Ñ¡Ôñ£ºif
Ñ»·£º
ÖªµÀ½á¹û£¬´ÎÊý²»¿ÉÖª£ºwhile
ÖªµÀ´ÎÊý£¬²»ÖªµÀ½á¹û£ºfor
1.Êä³ö 1---n Ö®¼äµÄËùÓÐËØÊý
ËØÊý£ºÃ»ÓÐÔ¼Êý
Ö»Äܱ» 1 ºÍ ×Ô¼ºÕû³ý
int main()
{
int i;
int j;
int n;
int gs = 0; //ËØÊýµÄ¸öÊý
int js = 0;//¼ÆÊýÒ»¹²¶àÉÙ´Î
printf("ÇëÊäÈënµÄÖµ£º");
scanf("%d", &n);
for(i = 1; i <= n; i++)
{
//16 (2 - 15) 17 (2 - 16) µ±j = i Ìø³öÑ»·
for(j = 2; j < i; j++)
{
js++;
if(i % j == 0)
{
break;
}
}
if(i == j)
{
gs++;
printf("%d ", i);
if(gs % 10 == 0)
{
printf("\n");
}
}
}
printf("\n");
printf("1- %dÖ®¼äÒ»¹²ÓÐ %d ¸öËØÊý£¬Ò»¹²¼ÆÊý%d ´Î\n", n, gs, js);
return 0;
}
2.½«Ò»¸öÕýÕûÊý·Ö½âÖÊÒòÊý¡£ÀýÈ磺ÊäÈë90£¬´òÓ¡³ö90=2*3*3*5¡£
//90 = 2 * 3 * 3 * 5
//ËØÊý£º²»¿É·Ö½â
//·ÇËØÊý£º¿ÉÒÔ·Ö½â
//16 = 2 * 2 * 2 * 2
#include <stdio.h>
int isPrime(int n);
int main()
{
int d;
int i;
printf("ÇëÊäÈëÒª·Ö½âµÄÊý£º");
scanf("%d", &d);
if(isPrime(d) == 1)
{
printf("%dÊÇËØÊý£¬²»¿É·Ö½â\n");
return -1;
}
printf("%d = ", d);
for(i = 2; i <= d; i++)
{
if(d % i == 0)
{
if(d == i)
{
printf("%d ", i);
}
else
{
printf("%d * ", i);
}
d = d / i;
i--;
}
}
return 0;
}
int isPrime(int n)
{
int i;
if(n <= 1)
{
return 0;
}
for(i = 2; i < n; i++)
{
if(n % i == 0)
{
return 0;
}
}
return 1;
}