while(str[i]!='\n')就可以了
带下划线的为程序修改部分,已运行通过。如下:
#include <stdio.h>
main()
{
char str[50];
int i;
int letter_sum=0,
number_sum=0,
space_sum=0,
other_sum=0;
printf("Please input a string of characters:\n");
for(i=0;str[i-1]!='\n';i++)
scanf("%c",&str[i]);
str[i-1]='\0';
for(i=0;str[i]!='\0';i++)
{
if((str[i]>='a'&&str[i]<='z')||(str[i]>='A'&&str[i]<='Z'))
letter_sum++;
else if(str[i]>='0'&&str[i]<='9')
number_sum++;
else if(str[i]==' ')
space_sum++;
else
other_sum++;
}
printf("There are %d letters in the string.\n",letter_sum);
printf("There are %d numbers in the string.\n",number_sum);
printf("There are %d spaces in the string.\n",space_sum);
printf("There are %d other characters in the string.",other_sum);
getch();
return(0);
}
/*两个数的最大公约数和最小公倍数*/
#include<stdio.h>
#include<conio.h>
void main(void)
{
int number1,number2;
int temp,temp1,temp2;
clrscr();/*清屏*/
printf("Input two number:\n");
scanf("%d,%d",&number1,&number2);
temp1=number1;temp2=number2;
if(number1<number2)/*保证:number1存放较大的数,number2存放较小的数*/
{
temp=number1;number1=number2;number1=temp;
}
while(number2!=0)
{
temp=number1%number2;
number1=number2;
number2=temp;
}
printf("最大公约数:%d\n",number1);
/*最小公倍数=(两个数之积)/最大公约数*/
printf("最小公倍数:%d",((temp1*temp2)/number1));
getch();/*暂停*/
}