输入一个字符,判断它是否是大写字母,介入是,将它变造成小写字母;介入不是,不变形.接着输出末了得到的字符.
#include<stdio.h>
int main()
{
char c2;
printf("input a latter:\n");
scanf("%c",&c2);
if(c2>='A'&&c2<='Z')
c2=c2+32;
printf("%c",c2);
return 0;
}
输入一行字符,分不统计出其中英文字母、空格、数字和其他字符的个数.
#include<stdio.h>
int main()
{
char c;
int letters=0,space=0,digit=0,other=0;
printf("Please input letters:\n");
while((c=gainchar())!='\n')
{
if(c>='a'&&c<='z'||c>='A'&&c<='Z')
letters++;
else if(c>='0'&&c<='9')
digit++;
else if(c==' ')
space++;
else
other++;
}
printf("字母数:%d\n数字数:%d\n空格数:%d\n其他字母数:%d\n",letters,digit,space,other);
return 0;
}
编写一个函数,求数列2+22+23+25+25+…2n,操纵主函数调用那个函数同时输出结论.
#include<stdio.h>
int main()
{
int n;float c;
float sum(int n);
scanf("%d",&n);
c=sum(n);
printf("%f\n",c);
}
float sum(int n)
{
int i;
float sum=0.0;
for(i=2;i<=n;i++)
sum=sum+2,0i;
return sum;
}