By GokiSoft.com|
20:05 18/09/2023|
Lập Trình C
Fibonacci - Lập trình C
Cho chuỗi Fibonacci như sau
F(0) = 1;
F(1) = 1;
F(n) = F(n-1) + F(n-2);
Nhập vào số Fibonaci max từ bàn phím
Yêu cầu : In ra chuỗi fibonaci với số lớn nhất là max
Ví dụ :
max = 100; được nhập từ bàn phím
Chuỗi fibonaci sẽ như sau
1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89
Tags:
Phản hồi từ học viên
5
(Dựa trên đánh giá ngày hôm nay)
![TRẦN VĂN ĐIỆP [community,C1812L,C2002L,T2008A]](https://www.gravatar.com/avatar/fc6ba9324e017d540af3613b3a77dd21.jpg?s=80&d=mm&r=g)
TRẦN VĂN ĐIỆP
2020-12-16 02:31:57
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int main(int argc, char *argv[]) {
int max;
printf("\nNhap max = ");
scanf("%d", &max);
int f0 = 1, f1 = 1, fn;
printf("\n1, 1");
while(1) {
fn = f0 + f1;
if(fn > max) {
break;
}
printf(", %d", fn);
f0 = f1;
f1 = fn;
}
return 0;
}
![Nguyễn Anh Vũ [T2008A]](https://www.gravatar.com/avatar/8863d24ed74b396082becbc4db8331fd.jpg?s=80&d=mm&r=g)
Nguyễn Anh Vũ
2020-09-22 18:00:05
#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[]) {
//bat dau code;
int FMax, x=0,y=1,F;
printf("\nNhap max :");
scanf("%d",&FMax);
while(1){
F=x+y;
if(F>FMax) {
break;
}else{
printf("\n%d",F);
x=y;
y=F;
}
}
//ket thuc code;
return 0;
}
![An Văn Minh [T2008A]](https://www.gravatar.com/avatar/e0f14efe4b11f7d9d5901e8802319c92.jpg?s=80&d=mm&r=g)
An Văn Minh
2020-09-17 13:16:08
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[])
{
int f0, f1, fn, max;
printf("\nNhap so Fibonacci max = "); scanf("%d", &max);
f0=1;
f1=1;
printf("1");
while(fn<=max){
f0=f1;
f1=fn;
printf(", %d",fn);
fn=f1+f0;
}
return 0;
}
![Trần Thị Khánh Huyền [T2008A]](https://www.gravatar.com/avatar/554e115833778e4294a01aebe228f3d6.jpg?s=80&d=mm&r=g)
Trần Thị Khánh Huyền
2020-09-17 12:30:09
#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[]) {
int f0, f1, fn, max;
printf("Nhap so Fibonacci max = "); scanf("%d", &max);
f0=1;
f1=1;
printf("1");
while(fn<=max){
f0=f1;
f1=fn;
printf(", %d",fn);
fn=f1+f0;
}
return 0;
}
![Trần Văn Lâm [T2008A]](https://www.gravatar.com/avatar/cfc15c8cb7781ad669b013e01f9f1a6b.jpg?s=80&d=mm&r=g)
Trần Văn Lâm
2020-09-17 02:43:12
#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[]) {
int f0, f1, fn, max;
f0 = 1;
f1 = 1;
printf("\nNhap max: ");
scanf("%d", &max);
printf("\n%d, %d", f0, f1);
while(1) {
fn = f0 + f1;
if(fn > max) {
break;
}
printf(", %d", fn);
f0 = f1;
f1 = fn;
}
return 0;
}
![hainguyen [T2008A]](https://www.gravatar.com/avatar/32855ce6db55d60134d830aee06b41e5.jpg?s=80&d=mm&r=g)
hainguyen
2020-09-16 07:08:30
#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[]) {
int f0, f1, fn, max;
f0 = 1;
f1 = 1;
printf("\nNhap max: ");
scanf("%d", &max);
printf("\n%d, %d", f0, f1);
while(1){
fn = f1 + f0;
if(fn > max)
break;
}
printf(", %d", fn);
f0 = f1;
f1 = fn;
return 0;
}
![TRẦN VĂN ĐIỆP [Teacher]](https://www.gravatar.com/avatar/ae8d66100c882095c429167b0fc6737f.jpg?s=80&d=mm&r=g)
TRẦN VĂN ĐIỆP
2020-09-16 06:59:30
Cấu trúc dữ liệu và giải thuật
- Giải thuật sắp xếp
- Tìm kiếm
- Vun đống
- Cây nhị phân tìm kiếm
- Bài toán tham lam
- Giải thuật dijkstra
- Giải thuật tìm kiếm đường đi
![TRẦN VĂN ĐIỆP [Teacher]](https://www.gravatar.com/avatar/ae8d66100c882095c429167b0fc6737f.jpg?s=80&d=mm&r=g)
TRẦN VĂN ĐIỆP
2020-09-16 06:56:15
#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[]) {
int f0, f1, fn, max;
//khoi tao du lieu
f0 = 1;
f1 = 1;
printf("\nNhap max: ");
scanf("%d", &max);
printf("\n%d, %d", f0, f1);
// while(1) {
// fn = f0 + f1;
// if(fn > max) {
// break;
// }
// printf(", %d", fn);
// f0 = f1;
// f1 = fn;
// }
fn = f0 + f1;
while(fn <= max) {
printf(", %d", fn);
f0 = f1;
f1 = fn;
fn = f0 + f1;
}
return 0;
}
![TRẦN VĂN ĐIỆP [Teacher]](https://www.gravatar.com/avatar/ae8d66100c882095c429167b0fc6737f.jpg?s=80&d=mm&r=g)
TRẦN VĂN ĐIỆP
2020-09-16 06:52:43
- Bài toán Fibonaci
- Tìm số Fibonaci ở vị trí n (n nhập từ bàn phím)
- Tính tổng các số Fibonaci chia hết cho 2 trong dãy Fibonaci có số max là n (n -> nhập từ bàn phím)
![TRẦN VĂN ĐIỆP [Teacher]](https://www.gravatar.com/avatar/ae8d66100c882095c429167b0fc6737f.jpg?s=80&d=mm&r=g)
TRẦN VĂN ĐIỆP
2020-09-16 06:48:37
#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[]) {
int f0, f1, fn, max;
//khoi tao du lieu
f0 = 1;
f1 = 1;
printf("\nNhap max: ");
scanf("%d", &max);
printf("\n%d, %d", f0, f1);
while(1) {
fn = f0 + f1;
if(fn > max) {
break;
}
printf(", %d", fn);
f0 = f1;
f1 = fn;
}
return 0;
}