作业:
习题3
今天学习了新的编程软件,听懂了一些,这个软件大部分都是建立在C语言基础之上的,
之前C语言没有好好学,虽然听是可以听懂,但是要自己写的话还是有些困难,不过今
天教的这些简单的程序都是可以跟着老师的步骤一步一步写出来的。希望后面几天能学
到更多东西吧,最后答辩的时候能完美答辩。
作业
#include<stdio.h>
#include<string.h>
int fun(char *a, char *b)
{
int len_b;
int count = 0;
int num = 0;
char *temp = b;
len_b = strlen(b);
while (*a != '\0')
{
if (*a == *temp)
{
while ((*a == *temp) && (*a != '\0') && (*temp != '\0'))
{
num++;
a++;
temp++;
}
if (num == len_b)
{
count++;
}
num = 0;
temp = b;
}
else
{
a++;
}
}
return count;
}
int main()
{
char a[100];
char b[10];
int num;
printf("Enter the main string(<=100)!\n");
scanf("%s",a);
printf("Enter the substring(<=10)!\n");
scanf("%s",b);
num = fun(a,b);
printf("The number is:%d\n",num);
return 0;
}习题4:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void fun(char *s,char *t)
{
}
int main()
{
char str[] = "I am from Shanghai";
char *p1 = str;
char *p2 = str+strlen(str)-1;
char temp;
char *p3 = NULL;
while(p1<p2)
{
temp = *p1;
*(p1++) = *p2;
*(p2--) = temp;
}
puts(str);
p1 = str;
p2 = str;
while(*p2)
{
if(*p2 == ' ')
{
p3 = p2 - 1;
while(p1<p3)
{
temp = *p1;
*(p1++) = *p3;
*(p3--) = temp;
}
p1 = p2 + 1;
}
p2++;
}
p3 = p2-1;
while(p1<p3)
{
temp = *p1;
*(p1++) = *p3;
*(p3--) = temp;
}
printf("%s",str);
return 0;
}
刘师成 15电信转本2 学号15091510
最新推荐文章于 2022-02-13 19:16:03 发布