1.輸出hello world
#include <stdio.h>
int main() {
printf("hello,world");
}
2.求兩個整數(shù)之和
#include <stdio.h>
int main() {
int a,b,sum;
a=10;
b=5;
sum=a+b;
printf("a+b=%d",sum);
}
3.編寫一個C程序,運行時輸出以下圖形:
*****
?*****
? *****
? ? *****
4.編寫一個程序,輸入a,b,c三個值,輸出其中最大者
自己的版本:
#include <stdio.h>
int main(){
int a,b,c,max;
printf("please input a,b,c:\n");
scanf("%d %d %d",&a,&b,&c);
if(a>b){
????if(a>c){
????max=a;
????}else{
????max=c;
????}
}else{
????if(b>c){
????max=b;
????}else{
????max=c;
????}
}
printf("the max number is %d",max);
}
習題答案版本:
#include <stdio.h>
int main(){
int a,b,c,max;
printf("please input a,b,c:\n");
scanf("%d %d %d",&a,&b,&c);
max=a;
if(max<b)
????max=b;
if(max<c)
????max=c;
printf("the max number is %d",max);
}