九、程序设计 共1题 (共计30分) 题目:主函数main()中字符串s为测试数据,首先将字符串s中的数字字符子串取出,转换成对应的十进制整数,并存入数组a中,然后找出数组a 中的所有素数。 素数是指,一个整数与其逆序数等值,且是素数。 例如:字符串s为" 17rose t131ar *d373monkey852y heo181c!#",处理后存入数组a中的整数为17,131,373,852,181。素数有131,373和181。 编写程序: 1 、编写int abstract(char s[],int a[])函数,取出s中的数字字符子串,转换成十进制整数,存入数组a,函数返回存入a中的整数个数。 2 、编写int pal_prime(int a[],int n,int b[])函数,找出数组a中所有的素数,存入数组b,参数n为数组a中整数个数,函数值为素数的个数。 #include
#include
#include
#include
#include
int abstract(char s[],int a[]) { /**********Program**********/ /********** End **********/ } int pal_prime(int a[],int n,int b[]) { /**********Program**********/ /********** End **********/ } void main() { char s[50]={" 17rose t131ar *d373monkey852y heo181c!#"}; int a[50],b[50]; int i,n; FILE *fp; if((fp=fopen("data.txt","w"))==NULL) { printf("File open error\n"); exit(0); } n=abstract(s,a); fprintf(fp,"Following are integers:\n"); printf("Following are integers:\n"); for(i=0;i