C语言作业不会做。。。
发布网友
发布时间:2022-04-23 06:22
我来回答
共2个回答
热心网友
时间:2023-05-26 13:06
这不是一个问题逐个回答吧。
1.
#include <stdio.h>main()
{char a[80],b[80];int i;printf("输入一个字符串:");gets(a);for(i=0;a[i]!='0';i++){b[i]=a[i];if(b[i]>='a'&&b[i]<='z')b[i]=toupper(b[i]);}puts(b);}
2.
#include <stdio.h>
#include <string.h>
int main(void)
{
char str_a[200], str_b[200];
char *pa, *pb;
printf("请输入字符串一: ");
gets(str_a);
printf("请输入字符串二: ");
gets(str_b);
if (strlen(str_b) > 5)
str_b[5] = '\0';
pb = str_b;
pa = str_a + strlen(str_a);
while (*pb != '\0')
*pa++ = *pb++;
*pa = '\0';
puts(str_a);
return 0;
}
3.
#include "stdio.h"
#define MAXLEN 80
int main(void)
{
char ch;
char str[MAXLEN];
int count, i;
int repeat, ri;
scanf("%d", &repeat);
getchar();
for(ri = 1; ri <= repeat; ri++){
i = 0;
while((ch = getchar()) != '\n'){
str[i++]=ch;
}
str[i] = 0;
此处填空
printf("count = %d\n", count);
}
}
4.
#include <stdio.h>
#include <conio.h>
void main()
{
int a[52]={NULL},i,max=0;char chr;
printf("please input the string: \n");
chr=getch();
printf("%c",chr);
while(chr!=13)
{ if((chr>='a')&&(chr<='z'))
a[chr-'a']++; else if((chr>='A')&&(chr<='Z')) a[chr-'A'+25]++; chr=getch(); printf("%c",chr);
}
printf("\n");
for(i=0;i<52;i++)
if(a[i]>a[max]) max=i; printf("该字符串中出现次数最多的字符为: %c\n",(max>25)?(max-25+'A'):(max+'a'));printf("它共出现了%d次\n",a[max]);getch();
}
5.
#include<stdio.h>main(){char i;int c=0;int a=0,sum;scanf("%c",&i);while(i!='\n'){{if('a'<=i&&i<='z')printf("%c ",i);if('A'<=i&&i<='Y')i=i+33,printf("%c ",i);}if(i=='Z')i=i+32-25,printf("%c ",i);;scanf("%c",&i);}printf("\n");}
6.
#include "stdio.h"#define MAXLEN 80int main(void){ char cc, ch; char str[MAXLEN]; int count, flag, i, index; int repeat, ri; scanf("%d", &repeat); getchar(); for(ri = 1; ri <= repeat; ri++){ cc = getchar(); getchar(); i = 0; while((ch = getchar()) != '\n'){ str[i++] = ch; } str[i] = 0;flag=0;count=0;for(i=0;str[i]!='0';i++){if(str[i]==cc){flag=1;index=i;}} if(flag != 0) printf("index = %d\n", index); else printf("No Found\n");
}
}
7.
#include <stdio,h.>
viod main()
{
int d=0,b=0,c=0,f;
char str_1 [80] ,str_2[80];
printf ("请出入一个字符串");
gets (str_1);
for(;d<=79;i++)
{ if (a<=str_1[d]&&str_1[d]<=z) b+=1;
else (
if(A<=str_1[d]&&str_1[d]<=Z) b+=1;
}
for(;c<=b-1;c++)
{str_2[c]=str_1[b-1-c];}
for(f=0;f<=b-1;f++)
{
printf("倒序输出结果为:%s",str_2[f]);
}
}
我只写到这了,累死我了!最后一题的原理和前面的一样,看了前面的你自然就知道了。
希望你不是直接复制粘贴回去交作业。
热心网友
时间:2023-05-26 13:07
第一题
#include<stdio.h>
int mystrcpy(char *dest,char *src)
{
while(*src!='\0')
{
if(*src>='a' && *src<='z')
{
*dest++=*src+'A'-'a';
src++;
}
else
*dest++=*src++;
}
return 0;
}
int main()
{
char a[100]={0};
char *b="hello world";
mystrcpy(a,b);
printf("%s\n",a);
}
第二题:
#include<stdio.h>
int mystrcat(char *dest,char *src)
{
char *p=dest;
int i;
while(*p!='\0') p++;
for(i=0;i<5;i++)
{
if(*src!='\0')
{
*p++=*src++;
}
}
return 0;
}
int main()
{
char a[100]="hello world!";
char *b="Go";
mystrcat(a,b);
printf("%s\n",a);
return 0;
}
第三题:
#include<stdio.h>
#include<string.h>
int main()
{
char a[100]={0};
char ch;
int count=0;
int i=0;
printf("请输入字符串,enter键结束:\n");
gets(a);
printf("请输入指定字符:");
scanf("%c",&ch);
for(i=0;i<strlen(a);i++)
{
if(a[i]==ch)
count++;
}
printf("指定字符%c含有%d个\n",ch,count);
printf("%s\n",a);
return 0;
}