用c语言编写一个程序,从键盘上输入3个字符串,输出其中的最大者 从键盘上输入3个字符串后原样输出,并要求找出其中最大者进行输...

作者&投稿:别柄 (若有异议请与网页底部的电邮联系)

1. int strcmp( const char *str1, const char *str2 );

功能:比较字符串str1 and str2, 返回值如下:

返回值

< 0    str1 < str2

= 0    str1 == str2

> 0    str1 > str2

#include <stdio.h>
#include <string.h>

int main()
{
    char a[100], b[100], c[100];
    printf("input 3 string :
");
    gets(a);
    gets(b);
    gets(c);
    char* p = strcmp(a, b) >= 0 ? a : b;
    printf("greater string :%s
", strcmp(p, c) >= 0 ? p : c);
    return 0;
}



#include <stdio.h>
#include <string.h>

#define LONGTH 10 //定义字符串最大长度
void main()
{
char a[LONGTH],b[LONGTH],c[LONGTH];
char *max;
printf("请输入三个字符串,以空格隔开:");
scanf("%s %s %s",a,b,c);
printf("输入的三个字符串为:\n");
printf("a=%s\n",a);
printf("b=%s\n",b);
printf("c=%s\n",c);
max=a;
if(strcmp(max,b)<0) max=b;
if(strcmp(max,b)<0) max=c;
printf("\nmax=%s\n",max);
}
我以前写的,可以运行,希望有帮助

#include "stdio.h"
void main()
{int a,b,c,max;
printf("请输入三个数字:");
scanf("%d%d%d",&a,&b,&c);
max=a;
if(max<b) max=b;
if(max<c)max=c;
printf("max=%d\n",max);
}

一楼的稍微修改一下就行了。
#include <stdio.h>
#include <string.h>
#define MAXLEN 1024
#define NUM 3
int main(int argc,char **argv)
{
char arr[NUM][MAXLEN];
char maxChar[MAXLEN];
memset(maxChar,0,MAXLEN);
int iCount=0;
for (iCount=0;iCount<NUM;iCount++)
memset(arr[iCount],0,MAXLEN);
for (iCount=0;iCount<NUM;iCount++)
{
printf("Input strings:");
scanf("%s",arr[iCount]);
}
strcpy(maxChar,arr[0]);
for (iCount=0;iCount<NUM;iCount++)
{
if(strcmp(maxChar,arr[iCount])<0) strcpy(maxChar,arr[iCount]);
}
printf("%s\n",maxChar);
return 0;
}

C:\>gcc -g test.c -o test

C:\>test
Input strings:abcd
Input strings:acdd
Input strings:btest
btest

C:\>

编写一个C++程序,从键盘输入3个字符串,在屏幕上输出其中最大者。~

#include
#include
using namespace std;
string comp (string &s1, string &s2);
int main()
{
string s1, s2, s3, s4;
cout << "请输入第一个字符串:" <<endl;
cin >> s1;
cout << "请输入第二个字符串" <<endl;
cin >> s2;
cout << "请输入第三个字符串" <<endl;
cin >> s3;
s4 = comp(comp(s1,s2), s3);
cout << "最大的字符串为: "<< s4 <<endl;
return 0;
}
string comp (string &s1, string &s2)
{
if (s1 >= s2)
return s1;
else
return s2;
}

#include
#include
main()
{
char x[128][128]={0};
char ch[4096]={0};
int t[10];
int i=0;
int w=0,p=0;
int len=0,max=0,top=0;
gets(ch);
puts(ch);//有空格输入要这个函数
while(ch[i]!='\0' && i<4096)
{
if(ch[i]==' ')
{
w++;
p=0;
i++;
continue;
} //一个空格表示一个单词分隔
else
x[w][p]=ch[i];
p++;
i++;
}
//w 就是单词的个数了
for(int j=0;j<=w;j++)
{
len=strlen(x[j]);
if(max<len)
{
max=len;
top=j;
}
}
i=0;
for( j=0;j<=w;j++)
{
len=strlen(x[j]);
if(max==len)
{
t[i]=j;
i++;
}
}
for(w=0;w<i;w++)
{
printf("%s 最长
",x[t[w]]);
}

}
希望对你有帮助!网上有几个答案不太完美,因为如果我输入 hello world hi 的话,只输出hello而不输出world,其实稍加改动在下边再加一个循环就可以解决了

用C语言编写一个程序,从键盘上输入一个小写字母,将其本身及对应的大写字...
答:{ char c; //声明变量 scanf("%c",&c); //键盘上取值 printf("%c %c",c,ch-'a'+'A');//本身和大写输出 }

用C语言编写一完整源程序,从键盘输入一个字符串Str1,在新的一行输入一...
答:void deleteChar(char *a,char c)//从特定字符串中删除特定字符{ int i; char *d=NULL;if((d=strchr(a,c))!=NULL)//找到这个字符,从后一位向前移位,将其覆盖,达到删除的目的 { for(i=0;*(d+i)!=0;i++)(d+i)=*(d+i+1);} }int main(){ char Str1[100]={0};cha...

用c语言编写一个程序,从键盘上输入两个字符给字符变量a,b,并输出变...
答:程序代码如下:include <stdio.h> //编译预处理命令 int main(int argc, char *argv[]) //主函数,字符的声明 { char a,b; //定义字符a,b scanf("%c %c",&a,&b); //输入字符a,b printf("%c %c\n",a,b);//打印字符a,b return 0; //返回并且输出a,b } 扩展...

C语言编写一个程序,是其完成如下功能:从键盘上输入一个十进制的数,用...
答:while(px>=0) printf("%c",str[a[px--]]);printf("\n");system("pause");}

C语言+从键盘输入一个英文单词,实现在指定位置删除英文字母的编程...
答:str[len - 1] = '\0';printf("删除后的字符串为:%s\n", str);return 0;} ```该程序使用了fgets函数从键盘读入一个英文字符串,使用scanf函数读入要删除的第几个I字符的位置n。然后使用一个循环将第n个字符之后的所有字符往前移动一个位置,最后将字符串的长度减一,即删除了...

c语言题目:写出程序 要求从键盘上输入一个十到十万之间的整数,将其最...
答:include <stdio.h>int main(void){ int n,t,f; printf("Input n(int 9<n<100001)...\nn="); if(scanf("%d",&n)!=1 || n<10 || n>100000){ printf("Input error, exit...\n"); return 0; } for(t=n,f=1;t>9;f*=10,t/=10); printf("T...

C语言:编写摄氏温度、华氏温度转换程序。要求:从键盘输入一个摄氏温度...
答:include<stdio.h>voidmain(){floatF,C;printf("请输入您需要转换的摄氏温度:");scanf("%f",&C);F=(C+32)*9/5.0;printf("其对应的华氏温度为:%.2f\n",F);} main(){float C,F;scanf("%f",&F);C=5.0/9*(F-32);printf("%8.2f",C);} include <stdio.h>int main(void...

在C语言中编写一程序,实现从键盘输入一个大写字母,要求改用小写字母输...
答:实现从键盘输入一个大写字母,改用小写字母输出,可以使用下面的方法:include<stdio.h>int main(){char a;scanf("%c",&a);printf("%c",a+32);}执行效果如下:

设计一个C语言程序, 从键盘上输入a,b,c三个整数,输出其中的最小者
答:void main(){ int a,b,c;scanf("%d%d%d",&a,&b,&c);//从键盘上输入a,b,c三个整数 if(a<b){ if(a<c)printf("%d",a);//输出其中的最小者 else printf("%d",c);//输出其中的最小者 } else { if(b<c)printf("%d",b);//输出其中的最小者 else printf("%d",c);//...

编写C语言程序:从键盘上输入两个整型数据,分别存放在整型变量a 和b 中...
答:include <stdio.h> int main(){ int a,b;scanf("%d %d", &a,&b );printf("%d/%d=%d\n", a,b,a/b );printf("%d%%%d=%d\n", a,b,a%b );return 0;}