C语言程序题 从键盘输入不多于100个字符长度的字符串,将其中的小写字母改成大写字母后输出

如题所述

#include <stdio.h>
void main()
{
char str[101];
int i;
printf("请输入不多于100个字符的字符串:\n");
gets(str); //可读入空格等
for (i=0;str[i];i++)
{
if (str[i] >= 'a' && str[i] <= 'z') //如果是小写字符
str[i] -= 32; //转为大写字符
}
printf("转换后的字符串为:\n");
puts(str);
}
温馨提示:答案为网友推荐,仅供参考
第1个回答  2010-11-05
#include <stdio.h>
#include<stdlib.h>
//#include<iostream>
// using namespace std;

int main ()
{
int i,n,m;
char st[100];
char str[10];
scanf("%d",&n);
gets(str);
for(i=0;i<n;i++)
scanf("%c",&st[i]);
//m=sizeof(st);
//printf("%d",m);
for(i=0;i<n;i++)
printf("%c ",st[i]);
printf("\n********************\n");
for(i=0;i<n;i++)
{if(97<=st[i]&&st[i]<=122)
st[i]=st[i]-32;}
for(i=0;i<n;i++)
printf("%c",st[i]);
system("pause");

}
第2个回答  2010-11-13
#include<stdio.h>
#include<string.h>
main()
{ int i;
char s[100];
gets(s);
for(i=0;;i++)
{
if(s[i]=='\0')break;
else if(s[i]>=65&&s[i]<=90)printf(
第3个回答  2010-11-06
#include"stdio.h"
#include"ctype.h"
main()
{
char s[101];
int i=0;
fgets(s,101,stdin);
for(;s[i];i++)
if(islower(s[i]))
s[i]=toupper(s[i]);
printf("%s",s);
}
相似回答