[Daozy極限編程]C入門編程100題(初階33題)

第1關 輸出 “Hello, World!”

在線課件:https://shimo.im/docs/HRrYh8RVy3gHTGTQ

#include <stdio.h>

int main(int argc, char *argv[]) {

	printf("Hello World!!\n");
	
	return 0;
}

任何問題可以加扣羣 :876662784
掃描觀看視頻課程:
在這裏插入圖片描述

第2關 輸出整數

#include <stdio.h>

int main(int argc, char *argv[]) {
	int a = 0;
	int b = 0;

	printf("Please input a int: ");
	scanf("%d", &a);
	printf("Please input a int: ");
	scanf("%d", &b);

	printf("a = %d, b = %d\n", a, b);

	return 0;
}

第3關 輸出單個字符

#include <stdio.h>

int main() {
	char x = '\0'; 
	// char c = 0; 
	
	x = 'B';

	printf("x = %c\n", x);

	return 0;
}

第4關 輸出浮點數

#include <stdio.h>

int main() {
	float x = 0.0;

	x = 1.2222;
	printf("x = %f\n", x);

	return 0;
}

第5關 輸出雙精度數

#include <stdio.h>

int main() {
	double x = 0.0;

	x = 23.444;
	printf("x = %lf\n", x);

	return 0;
}

第6關 兩個數字相加

#include <stdio.h>

int main() {
	int a = 0;
	int b = 0;

	printf("Please input two int: ");
	scanf("%d%d", &a, &b);

	printf("a + b = %d\n", a + b);

	return 0;
}

第7關 兩個浮點數相乘

#include <stdio.h>

int main() {
	float a = 0.0;
	float b = 0.0;
	float product = 0.0;
	
	double c = 0.0;
	double d = 0.0;
	double product2 = 0.0;
	
	scanf("%f%f", &a, &b);
	scanf("%lf%lf", &c, &d);

	product = a * b;
	product2 = c * d;

	printf("product = %f\n", product);
	printf("product2 = %lf\n", product2);

	return 0;
}

第8關 字符轉 ASCII 碼

#include <stdio.h>

int main() {
	char c = '\0';

	printf("Please input a char: ");
	scanf("%c", &c);

	printf("%c -> ASCII: %d\n", c, c);

	return 0;
}

第9關 兩數相除

#include <stdio.h>

int main() {
	int a = 0;
	int b = 0;

	printf("Please input 被除數: ");
	scanf("%d", &a);
	printf("Please input 除數: ");
	scanf("%d", &b);

	printf("c = %d\n", a / b);
	printf("r = %d\n", a % b);

	return 0;
}

第10關 數值比較

#include <stdio.h>

int main() {
	int a = 0;
	int b = 0;

	printf("Please input a and b: ");
	scanf("%d%d", &a, &b);

	if (a > b) {
		printf("a > b\n");
	} else { 
		printf("a <= b\n");
	}

	return 0;
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章