c语言提目 输入50个英文单词,输出其中最长的英文单词

作者&投稿:沙马 (若有异议请与网页底部的电邮联系)
C语言编程求一个英文句子中的单词数和最长单词的位置、长度及输出这个单词。~

我刚做了一关于英文句子里面每个单词平均字长的。与你问题很近。
#include "stdio.h"
#include
#include "ctype.h"
#define MAX 1000000
char buf[MAX],s[MAX];
char p[MAX];
int main(){
int n = 0;
int m = 1;
int cout = 0;
float ave = 0;
int i;
fgets(buf,sizeof(s),stdin);
n = strlen(buf)-1;//字符串的末尾有一个结束字符
for( i =0;i < n; i++)
if(isalpha(buf[i]) == 0 && isalpha(buf[i+1])!=0)
{
m ++;
}
printf("%d

",m);
for(i = 0; i < n; i++)
{
if(isalpha(buf[i]) !=0)
cout++;
}
printf("%d

",cout);
ave = cout /m;
printf("%f",ave);
return 0;
}

#include #include #include #define N 100char *maxlenword(char statement[],char maxword[]) {int i = 0,j;char word[N];maxword[0] = '\0';for(i = 0; statement[i]; i++) {if(!isalpha(statement[i++])) continue;--i;j = 0;while(statement[i] && isalpha(statement[i]))word[j++] = statement[i++];word[j] = '\0';if(strlen(maxword) < strlen(word))strcpy(maxword,word);}return maxword;}int main() {char a[N] = {'\0'};char b[N] = {'\0'};printf("请输入字符串:
");gets(a);maxlenword(a,b);printf("最长单词长为:%d
",strlen(b));printf("最长单词为:\"%s\"
",b);return 0;}

#include <stdio.h>
#include <string.h>
int main(){
    char s[100];
    char t[100];
    int x;
    scanf("%s",s);
    int len =  strlen(s);
    strcpy(t,s);
    int z;
    for(x=0;x<49;x++){
        scanf("%s",s);
        z = strlen(s);
        
        if(z>len){
            len = z;
             strcpy(t,s);
        }
    }
    
    printf("%s",t);
    return 0;
}


如果不要求保存输入数据的话,可以用2个数组,一个存输入,一个存当前的最长单词。


嘉定区13156144937: c语言提目 输入50个英文单词,输出其中最长的英文单词 -
胥怀复方: #include int main(){ char s[100]; char t[100]; int x; scanf("%s",s); int len = strlen(s); strcpy(t,s); int z; for(x=0;x scanf("%s",s); z = strlen(s); if(z>len){ len = z; strcpy(t,s); } } printf("%s",t); return 0; }

嘉定区13156144937: C语言编程题:输入N个英文单词,建立字符串数组,按字典顺序输出这些英文单词,要求用指针实现. -
胥怀复方: #include #defineN5 voidswap(char*p1,char*p2){ chartemp[100]; strcpy(temp,p1); strcpy(p1,p2); strcpy(p2,temp); } intmain(){ inti,j; charstr1[N][100],*str[N]; for(i=0;iscanf("%s",*(str1+i)); } for(i=0;istr[i]=*(str1+i); } for(i=0;ifor(j=i+1;jif(strcmp(str[i],str[j])>...

嘉定区13156144937: 度 C语言编程序:用数组的方法实现程序,从键盘输入不超过50个字符,统计其中英文字母.空 -
胥怀复方: #include <stdio.h> void main() { char c,str[51]; int i=0,letters=0,space=0,digit=0,others=0; printf("请输入不超过50个字符\n"); gets(str); while((c=str[i++])!=0) { if(c>='a'&&c<='z'||c>='A'&&c<='Z') letters++; else if(c==' ') space++; else if(c>='0'&&c<...

嘉定区13156144937: C语言编程:输入一行字符,至少50个,统计其中英文字母,数字,其他字母个数 -
胥怀复方: 楼上那个不能统计空格个数,我这个可以 #include <stdio.h> #include <stdlib.h>int main() {int cnt_c=0,cnt_n=0,cnt_o=0;char ch; while(ch=getchar(),ch!='\n'){if(ch>='a' && ch<='z' || ch>='A' && ch<='Z') cnt_c++;else if(ch>='0' && ch<='9') cnt_n...

嘉定区13156144937: C语言编程:从键盘输入若干英文单词,以”@@@”字符串作为结束,统计单词出现的频数. -
胥怀复方: #include<stdio.h> #include<string.h> /********************************************/ struct word_num {char ws[21];int count; }; typedef struct word_num WRD; int find(WRD a[], char *t,int n); /********************************************/ int main() { WRD s[MAX]...

嘉定区13156144937: 输入一行字符,统计输入单词个数的C语言程序 -
胥怀复方: 刚帮别人改好的,你试试,借鉴一下吧 #include <stdio.h> #include <stdlib.h> int main() { char a[80]; int i,num=0; gets(a); for(i=0;a[i]!='\0';i++) { if ( (a[i] >='a' && a[i] <='z') || (a[i] >='A' && a[i] <='Z') ) { do { i++ ; } while ( (a[i] >='a' && a[i] <='z') || (a[i] >='A' &&...

嘉定区13156144937: 怎么用c语言输出英文单词啊? -
胥怀复方: 存储成字符数组 然后用printf或者puts输出 比如1 2 3chars[100] = "English"; printf("%s",s); puts(s); 都可以.

嘉定区13156144937: (c语言)输入一组英文单词,按字典顺序排序后输出
胥怀复方: main() { int i,j,x; char s; scanf(%s,s); for(i=0;i全部

嘉定区13156144937: c语言.由键盘输入任意一个数字(0 - 5),输出它对应的英文单词 -
胥怀复方: 根据题意得如下代码: #include <stdio.h> int main() {int n;scanf ("%d", &n);//输入字if (n == 0){printf ("zero\n");}else if (n == 1){//1printf ("one\n");}else if (n == 2){//2printf ("two\n");}else if (n == 3){//3printf ("three\n");}...

嘉定区13156144937: 用c语言如何编写一段英文单词 -
胥怀复方: 存储成字符数组 然后用printf或者puts输出 比如char s[100] = "English"; printf("%s",s); puts(s);都可以.

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 星空见康网