C语言问题解释

来源:百度知道 编辑:UC知道 时间:2024/05/16 04:59:48
.#include "stdio.h"
main()
{int a,n,s,i;
s=0;
printf("Enter: a=%d,n=%d",a,n);
for(i=1;i<=n;i++)
{ s=s+a;
a=a+a*10;}
printf("%d",s);
}

.#include<stdio.h>
main()
{
char c;
int letter=0,space=0,digit=0,other=0;
printf("input characters:\n");
while((c=getchar( ))!='\n')
{
if(c>='a'&&c<='z'||c>'a'&&c<='z')
letter++;
else if(c==' ')space++;
else if(c>='0'&&c<='9')digit++;
else other++;}
printf("%d %d %d %d",letter,space,digit,other)
getch();}

请对照检查吧:
#include<stdio.h>
void main()
{
int a,n,s,i;
s=0;
printf("输入a,n的值分别为:");
scanf("%d%d",&a,&n);
for(i=1;i<=n;i++)
{
s=s+a;
a=a+a*10;
printf("%d\n",s);
}

}

#include<stdio.h>
main()
{
char c;
int letter=0,space=0,digit=0,other=0;
printf("input characters:\n");
while((c=getchar( ))!='\n')
{
if(c>='a'&&c<='z'||c>'a'&&c<='z')
letter++;
else if(c==' ')space++;
else if(c>='0'&&c<='9')digit++;
else other++;}
printf("%d %d %d %d",letter,space,digit,other);//此处忘了分号
getchar();} //此处改为getchar()

都是小错误,以后写程序时注意点就OK了。

第一个中的a,n没赋初值
第二个最后第二行少一个分号,最后的getch()应是getchar()判断字母时后面的c>'a'中的a应该大写

第一个a,n没输入值,计算机会随机赋值<