#include <stdio.h>
#include <conio.h>
#define ARR_LEN 100 /*数组长度上限*/
/* 试除法判断素数 */
/* 大于1的自然数num,若其不能被2~num^1/2(num的平方根)之间的任一自然数整除,则其为素数 */
/* num是素数返回1,否则返回0 */
int isPrime (int num) {
int i;
if (num <= 1) /* 素数必须是大于1的自然数 */
return 0;
if (num%2==0 && num!=2) /* 除2之外的偶数显然不是素数 */
return 0;
for (i=2; i*i<=num; i++)
if (num%i == 0)
return 0;
return 1;
}
int main (void) {
char str[ARR_LEN], *p;
int i;
gets (str);
p = str;
while (*p) {
if (isPrime(p-str) && (*p>='a' && *p<='z') ) /* 字符数组下标是素数,且为小写字母 */
*p -= 32; /* 转为大写字母 */
p++;
}
puts (str);
getch (); /* 屏幕暂留 */
return 0;
}
![](https://video.ask-data.xyz/img.php?b=https://iknow-pic.cdn.bcebos.com/eac4b74543a98226ee18ce538482b9014b90ebed?x-bce-process=image%2Fresize%2Cm_lfit%2Cw_600%2Ch_800%2Climit_1%2Fquality%2Cq_85%2Fformat%2Cf_auto)