请编写函数 fun ,它的功能是:求出能整除形参 x 且不是偶数的各整数 , 并按从小到大的顺序放在 pp 所指的数组中 , 这些除数的个数通过形参 n 返回。 例如,若 x 中的值为 : 35 ,则有 4 个数符合要求,它们是 : 1, 5, 7, 35 。 #include
void fun(int x,int *aa,int *y) {
int i; *y=0;
for(i=1;i<=x;i++)
if(x%i==0&&i%2!=0) {
*aa=i; aa++; (*y)++; } }
void main( )
{ int x, aa[1000], n, i ; scanf(\ fun(x, aa, &n ) ;
for( i = 0 ; i < n ; i++ )
printf(\ printf(\}
7.14 求最大值及其下标 请编写函数 fun ,其功能是求出数组的最大元素在数组中的下标并存放在 k 所指的存储单元中。
例如 , 输入如下整数 : 876 675 896 101 301 401 980 431 451 777 则输出结果为 : 6, 980 #include
void fun(int *a,int m,int *k) {
int i; *k=0;
for(i=1;i if(*(a+i)>*(a+*k)) *k=i; } } void main( ) { int a[10], k ,i; for(i=0;i<10;i++) scanf(\ fun(a, 10, &k) ; printf(\} 8.1 字符转换 描述 提取一个字符串中的所有数字字符(?0?...?9?)将其转换为一个整数输出。 输入 一个以回车符为结束标志的字符串(少于80个字符)。 输出 把字符串中的所有数字字符(?0?...?9?)转换为一个整数并输出。 # include for(i=0;i 8.2合并字符串 输入两个已经按从小到大顺序排列好的字符串,编写一个合并两个字符串的函数,使合并后的字符串,仍然是从小到大排列。 输入: 两个已经排好顺序(升序)的两个字符串 输出: 一个合并在一起的有序(升序)的字符串 #include char a[100],b[100];int i,j,k,t; gets(a); gets(b); strcat(a,b); k=strlen(a); for(j=1;j for(i=0;i t=a[i]; a[i]=a[i+1]; a[i+1]=t; } puts(a); } 8.3 删除重复字符 背景: 输入一个长度不超过 100 的字符串,删除串中的重复字符。 输入: 输入要检查的字符串,长度不超过100个字符。例如:abacaeedabcdcd。 输出: 删除重复字符后的字符串。例如:abced #include char a[100]; int i,j,flag; gets(a); for(i=1;a[i]!='\\0';i++) { flag=1; for(j=0;j for(i=0;a[i]!='\\0';i++) if(a[i]!='0') printf(\ printf(\ } 8.4 删除字符串中指定字符 输入两个字符串 s1 和 s2 ,在 s1 中删除任何 s2 中有的字符。例如, s1 :“ abc123ad ”, s2 :“ a1 ” ,则输出“bc23d ”。 输入:两个字符串 s1 和 s2 输出:删除后的字符串 s1 #include 8.5 单词有多少 用空格或换行分开的字符串称为单词。输入多行字符串,直到遇到了单词 \时才停止。最后输出单词的数量。用于分割单词的空格或换行可能多于1个。 输入:多个字符串 输出:单词的数量 #include 8.6 在指定位置插入字符串 输入两个字符串 s1 、 s2 和 s1 中任意字符 k ,在 s1 中的指定字符 k 第一次出现的位置处插入字符串 s2 并输出。 输入:两个字符串 s1 、 s2 和 s1 中任意字符 k 输出:插入后的字符串 s1 #include for(i=0; i for(i=c; i for(i=c+m; i<=m+n; i++) s3[i]=s1[i-m]; puts(s3); } 8.7 Your Ride Is Here It is a well-known fact that behind every good comet is a UFO. These UFOs often come to collect loyal supporters from here on Earth. Unfortunately, they only have room to pick up one group of followers on each trip. They do, however, let the groups know ahead of time which will be picked up for each comet by a clever scheme: they pick a name for the comet which, along with the name of the group, can be used to determine if it is a particular group's turn to go (who do you think names the comets?). The details of the matching scheme are given below; your job is to write a program which takes the names of a group and a comet and then determines whether the group should go with the UFO behind that comet. Both the name of the group and the name of the comet are converted into a number in the following manner: the final number is just the product of all the letters in the name, where \* 1 * 3 * 15 = 17955. If the group's number mod 47 is the same as the comet's number mod 47, then you need to tell the group to get ready! (Remember that \the remainder left over after dividing a by b; 34 mod 10 is 4.) Write a program which reads in the name of the comet and the name of the group and figures out whether according to the above scheme the names are a match, printing \ 百度搜索“77cn”或“免费范文网”即可找到本站免费阅读全部范文。收藏本站方便下次阅读,免费范文网,提供经典小说教育文库中国石油大学C语言上机题答案(2013版)答案 最全最详细(9)在线全文阅读。
相关推荐: