输入6个字符串,输出最小串及最大串。
**输入格式要求:"%s" 提示信息:"请输入6行字符串:\n"
**输出格式要求:"The max string is: %s\n" "The min string is: %s\n"
程序示例运行如下:
请输入6行字符串:
hello,world
vb
vc
Java
c++
c#
The max string is: vc
The min string is: Java
#include <stdio.h>
#include <string.h>
#define N 6
#define N1 20
int main()
{
char str[N1], min[N1], max[N1];
int i;
printf("请输入6行字符串:\n");
gets(min); //假设第1个串最小
strcpy(max, min);//假设最大串的值也为min
//循环输入其它串,并与最小的串及最大的串比较
for (i = 2; i <= N; i++)
{
gets(str);
if (strcmp(str, min) < 0)
strcpy(min, str);
if (strcmp(str, max) > 0)
strcpy(max, str);
}
printf("The max string is: %s\n", max);
printf("The min string is: %s\n", min);
return 0;
}
编程判断输入的一个字符串是否是“回文”。所谓“回文”字符串就是左读和右读都一样的字符串。例如: "abcba"就是一个回文字符串。
输入提示信息:"Input a string:\n"
输入格式:gets()
判断是回文的输出提示信息:"This string is a plalindrome."
判断不是回文的输出提示信息:"This string is not a plalindrome."
程序运行示例1:
#include"stdio.h"
void main(void)
{
unsigned char l = 0, i, j, temp1[200];
printf("Input a string:\n");
gets(temp1);
while (temp1[l] != '\0') l++;
j = l / 2;
for (i = 0; i <= j; i++)
{
if (temp1[i] != temp1[l - 1 - i]) break;
}
if (i == (j + 1))
printf("This string is a plalindrome.");
else
printf("This string is not a plalindrome.");
}