By GokiSoft.com| 20:25 14/12/2021|
Lập Trình C

[Video] Fibonacci - Lập trình C - C2110L

Fibonacci - Lập trình C



#include <stdio.h>
#include <stdlib.h>

/* run this program using the console pauser or add your own getch, system("pause") or input loop */

int main(int argc, char *argv[]) {
	//B1. Nhap so max
	int max;
	printf("\nNhap max = ");
	scanf("%d", &max);
	
	//B2. Khai bao bien su dung trong fibonacci
	int f0 = 1, f1 = 1, fn;
	printf("\nDay Fibonacci");
	printf("\n%d, %d", f0, f1);
	
	for(;;) {
		fn = f0 + f1;
		if(fn > max) {
			break;
		}
		printf(", %d", fn);
		//next buoc tiep theo
		f0 = f1;
		f1 = fn;
	}
	
	return 0;
}




Tags:



Phản hồi từ học viên

5

(Dựa trên đánh giá ngày hôm nay)

Đăng nhập để làm bài kiểm tra

Chưa có kết quả nào trước đó