【入門1】順序結構
Hello,World!
#include<stdio.h>
int main(){
printf("Hello,World!");
return 0;
}
輸出字元菱形
#include <stdio.h>
int main(){
printf(" * \n");
printf(" *** \n");
printf("***** \n");
printf(" *** \n");
printf(" * \n");
return 0;
}
超級瑪麗遊戲
#include<stdio.h>
int main() {
printf(
" ********\n"
" ************\n"
" ####....#.\n"
" #..###.....##....\n"
" ###.......###### ### ###\n"
" ........... #...# #...#\n"
" ##*####### #.#.# #.#.#\n"
" ####*******###### #.#.# #.#.#\n"
" ...#***.****.*###.... #...# #...#\n"
" ....**********##..... ### ###\n"
" ....**** *****....\n"
" #### ####\n"
" ###### ######\n"
"##############################################################\n"
"#...#......#.##...#......#.##...#......#.##------------------#\n"
"###########################################------------------#\n"
"#..#....#....##..#....#....##..#....#....#####################\n"
"########################################## #----------#\n"
"#.....#......##.....#......##.....#......# #----------#\n"
"########################################## #----------#\n"
"#.#..#....#..##.#..#....#..##.#..#....#..# #----------#\n"
"########################################## ############\n"
);
return 0;
}
A+B Problem
#include<stdio.h>
int main(){
int a,b;
scanf("%d%d",&a,&b);
printf("%d",(a+b));
return 0;
}
字元三角形
#include <stdio.h>
int main()
{
char c = getchar();
printf(" %c\n %c%c%c\n%c%c%c%c%c\n", c,c,c,c,c,c,c,c,c);
return 0;
}
【深基2.例5】蘋果採購
#include<stdio.h>
int main(){
int a,b;
scanf("%d%d",&a,&b);
printf("%d",a*b);
return 0;
}
【深基2.例6】字母轉換
#include<stdio.h>
int main(){
putchar(getchar()-32);
return 0;
}
【深基2.例7】數字反轉
#include <stdio.h>
#include <string.h>
int main() {
char s[20];
scanf("%s", s);
int len = strlen(s);
for (int i = len - 1; i >= 0; i--) {
printf("%c", s[i]);
}
printf("\n");
return 0;
}
【深基2.例8】再分肥宅水
#include<stdio.h>
int main(){
int a;
float t;
scanf("%f%d",&t,&a);
printf("%.3f\n",t/a);
printf("%d",a*2);
return 0;
}
【深基2.習2】三角形面積
#include<stdio.h>
#include<math.h>
int main(){
double a,b,c,p;
scanf("%d%d%d",&a,&b,&c);
p = (a+b+c)/2;
printf("%.1f",sqrt(p*(p-a)*(p-b)*(p-c)));
return 0;
}
大象喝水
#include<stdio.h>
int main(){
double h0,r0,sum;
scanf("%lf%lf",&h0,&r0);
double h=h0*0.1;
double r=r0*0.1;
double v=3.14*r*r*h;
int i = 1;
while (1){
sum=v*i;
if(20<=sum){
printf("%d",i);
break;
}
else{
i++;
}
}
return 0;
}
[NOIP2017 普及組] 成績
#include<stdio.h>
int main(){
double a,b,c;
scanf("%lf%lf%lf",&a,&b,&c);
printf("%.0lf",a*0.2+b*0.3+c*0.5);
return 0;
}
小玉買文具
#include<stdio.h>
int main(){
int a,b;
scanf("%d%d",&a,&b);
printf("%d",(a*10+b)/19);
return 0;
}
小魚的游泳時間
#include<stdio.h>
int main(){
int a,b,c,d;
scanf("%d%d%d%d",&a,&b,&c,&d);
int begin =a*60+b;
int end = c*60+d;
int time =end - begin;
printf("%d %d",time/60,time%60);
return 0;
}