#include "stdio.h"
int main()
{
int sum=0,i;
for (i=2;i<=100;i=i+2)
sum=sum+i;
printf("2+4+6...+100=%d\n",sum);
return 0;
}
#include "stdio.h"
#include "string.h"
int main()
{
char s1[6]={};
char s2[6]={'w','a','t','e','r','\0'};
int i;
printf("输入字符串: \n");
gets(s1);
for (i=0;i<5;i++)
{
if(s1[i]!=s2[i])
break;
}
if(i==5)
printf("This word is water\n");
else
printf("This word is not water\n");
return 0;
}
在c语言中,整数的除法得到的结果还是整数。在这个程序中,ans4=a/(a+a),ans4=12/24=0,因为12小于24,得到0,而不是0.5000000。
#include
int main()
{
int i=1,sum=0;
while(i<=100)
{
if(i%2==0)
sum+=i;
i++;
}
printf("%d",sum);
}
————————————————————
#include
#include
int main()
{
char a[6],b[6]="water";
char *q=b;
char *p=a;
int f=1;
gets(a);
while(*q)
{
if(*q!=*p)
f=0;
q++;
p++;
}
if(f==1)
printf("This word is water\n");
else
printf("This word is not water\n");
}