#include<stdio.h> int main(void)
{ int mynumber=38; int yournumber; printf("Input your number:"); scanf("%d",&yournumber); if(yournumber==mynumber) printf("OK!you are right! "); else if(yournumber>mynumber) printf("Sorry!your number is bigger than my number! "); else printf("Sorry!your number is smaller than my number! "); return 0; }
#include<stdio.h> int main(void) { int number; printf("Enter a number:"); scanf("%d",&number); if(number%2==0){ printf("The number is even. "); } else{ printf("The number is odd. "); } return 0; }
#include<stdio.h> int main(void) { int count,i,n; double grade,total; printf("Enter n:"); scanf("%d",&n); total=0; count=0; for(i=1;i<=n;i++){ printf("Enter grade #%d:",i); scanf("%if",&grade); total=total+grade; if(grade<60){ count++; } } printf("Grade average=%.2f ",total/n); printf("Number of failures=%d ",count); return 0; }
-
#include<stdio.h> int main(void) { double x,y; printf("Enter x:"); scanf("%if",&x); if(x<0){ y=0; } else if(x<=15){ y=4*x/3; } else{ y=2.5*x-10.5; } printf("f(%.2f)=%.2f ",x,y); return 0; }
#include<stdio.h> int main(void) { double value1,value2; char op; printf("Type in an expression:"); scanf("%if%c%if",&value1,&op,&value2); if(op=='+') printf("=%.2f ",value1+value2); else if(op=='-') printf("=%.2f ",value1-value2); else if(op=='*') printf("=%.2f ",value1*value2); else if(op'/') printf("=%.2f ",value1/value2); else printf("Unknown operator "); return 0; }
经过这几天的学习和打代码,我对C语言有了更深层的认识,也对着门课程和语言有了兴趣和好奇。
一开始打得很慢,因为我以前对键盘不怎么熟悉,而且刚开始错误很多,虽然我很仔细的在打,还是会有错,但经过同学的帮助,我学会了怎样找错,以及怎样改正它们。
就这样,看着我打出来的代码,我有一种莫名的喜悦,呵呵。
问题:1.For语句和which语句的区别是什么;
2.空格会影响结果吗;
3.return 0是什么意思;