1题
编写函数返回子串在字符串中出现的次数
2题
请阅读下面的程序,在横线处填写正确的代码,该程序的功能是:求1-10的奇数和。
#include <stdio.h>
int main()
{
int x, s;
s=0;
for (x=1; x<=10; _______)
{
}
printf("奇数和为:%d", s);
return 0;
}
1题
编写函数返回子串在字符串中出现的次数
2题
请阅读下面的程序,在横线处填写正确的代码,该程序的功能是:求1-10的奇数和。
#include <stdio.h>
int main()
{
int x, s;
s=0;
for (x=1; x<=10; _______)
{
}
printf("奇数和为:%d", s);
return 0;
}
1.
#include <stdio.h>
#include <string.h>
int find(char *str1, char *str2)
{
int i, j;
int str1len = strlen(str1), str2len = strlen(str2);
int count = 0;
for (i = 0; i < str1len - str2len + 1; i++)
{
for (j = 0; j < str2len; j++)
{
if (str2[j] != str1[i + j])
break;
}
if (j == str2len)
count++;
}
return count;
}
int main()
{
char a[200], b[200], *g;
int c = 0;
printf("请输入主串:");
gets(a);
printf("请输入子串:");
gets(b);
c = find(a, b);
printf("出现的次数:%d\n", c);
return 0;
}
2.
x ++
if(x%2!=0)
s+=x;