0% found this document useful (0 votes)
5 views9 pages

NTP 46B 4

Uploaded by

Loan Kim
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views9 pages

NTP 46B 4

Uploaded by

Loan Kim
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 9

Bài 1

#include <stdio.h>

#include <math.h>

#include <conio.h>

int ptb2 ( int a, int b, int c) {

printf("suy ra ");

int delta, x1, x2;

delta = b *b - 4*a*c;

if (delta < 0)

printf("Phuong trinh vo nghiem.");

else if (delta = 0){

x1 = -b/(2*a);

printf("\nket qua nghiem x1 = ");

else {

x1 = (-b-sqrt(delta))/(2*a);

x2 = (-b+sqrt(delta))/(2*a);

printf("\n ngiem x1 = ", x1);

printf("\n nghiem x2 = ", x2);

}
main() {

int a, b, c;

printf("\n nhap a: "); scanf("%d", &a);

printf("\n nhap b: " ); scanf("%d", &b);

printf("\n nhap c: "); scanf("%d", &c);

ptb2 (a, b, c);

getch();

Bài 2

#include <math.h>

#include <stdio.h>

#include <conio.h>

int he_2(int n){

int s, i, tam;

s = 0;

i = 1;

while ( n > 0){

tam = n % 2;

n = n / 2;

s= s + tam * i;

i = i * 10;

int he_10(int m) {
int s, i, tam;

s = 0;

i = 0;

while ( m > 0){

tam = n % 10;

s= s + tam * pow(2, i);

m = m / 10;

i = i + 1;

main() {

int n, m;

printf("\nnhap n: "); scanf("%d", &n);

printf("\nnhap m: "); scanf("%d", m);

he_2(n);

he_10(m);

printf("\nket qua la: ")

getch() ;

Bài 3

#include <stdio.h>
#include <conio.h>

int so_chinh_phuong(int n){

printf (" Vay ");

int i = 0;

while (i*i<=n){

if (i*i == n)

printf("n khong phai la so chinh phuong");

i = i + 1;

printf("n khong phai la so chinh phuong.");

main() {

int n;

so_chinh_phuong(n);

printf("\nnhap n: "); scanf("%d", &n);

getch() ;

Bài 4

#include <stdio.h>

#include <conio.h>

int kiemtra_doixung(int n){


printf("Vay ");

int i, sum, tam;

sum = 0;

tam = n;

while (n != 0){

i = n % 10;

sum = sum * 10 + i;

n = n / 10;

if ( sum == tam) printf("n la doi xung.");

else printf("n la khong doi xung.");

main(){

int n;

printf("nhap n: "); scanf("%d", &n);

kiemtra_doixung(n);

getch();

#include <stdio.h>

#include <conio.h>

int UCLN(int a, int b) {

while (a != b){

if (a > b) {
a = a - b;

else {

b = b - a;

return (a);

main() {

int a, b, x;

printf("nhap he so a: "); scanf("%d", &a);

printf("nhap he so b: "); scanf("%d", &b);

printf("Boi so chung nho nhat la: %d", x);

x = a * b / UCLN(a,b);

getch();

#include <stdio.h>

#include <conio.h>

#include <iostream>

using namespace std;

int fibo(int n){

int f0 = 0;

int f1 = 1;
int fn = 1;

int i;

if (n < 0) {

return -1;

} else if (n == 0 || n == 1) {

return n;

} else {

for (i = 2; i < n; i++) {

f0 = f1;

f1 = fn;

fn = f0 + f1;

return fn;

main(){

int n;

cout << "10 so dau tien cua day so Fibonacci: \n";

for (n = 0; n < 10; n++) {

cout << fibo(n) << " ";

}
}

#include <conio.h>

#include <stdio.h>

#include <iostream>

using namespace std;

int fibo_dequy(int n) {

if (n < 0) {

return -1;

} else if (n == 0 || n == 1) {

return n;

} else {

return fibo_dequy(n - 1) + fibo_dequy(n - 2);

main() {

int i, n;

printf("10 so dau tien cua day so Fibonacci: \n") ;

for (i = 0; i < 10; i++) {

cout << fibo_dequy(i) << " ";

#include <conio.h>

#include <stdio.h>
#include <iostream>

using namespace std;

int fibo_dequy(int n) {

if (n < 0) {

return -1;

} else if (n == 0 || n == 1) {

return n;

} else {

return fibo_dequy(n - 1) + fibo_dequy(n - 2);

main() {

int i, n;

printf("10 so dau tien cua day so Fibonacci: \n") ;

for (i = 0; i < 10; i++) {

cout << fibo_dequy(i) << " ";

You might also like