By GokiSoft.com| 20:08 22/09/2023|
Lập Trình C

Bài tập ôn luyện Function - Lập trình C

Bài 1:

Viết hàm đặt tên là showInfor() => Hiển thị thông tin cá nhân của bạn gồm tên, tuổi, địa chỉ, email, sđt

Trong hàm main thực hiện gọi hàm showInfor()

Bài 2:

Viết hàm đặt tên là showMessage có 1 tham số truyền vào int msg => Hiển thị dòng Hello msg

Trong hàm main lân lượt gọi 3 lần hàm showMesage với các giá trị khác nhau

Bài 3:

Viết hàm tính giaithua => tham số truyền vào n => trả về kết quả tính giai thừa N

Viết hàm tính tổng => tham số truyền vào m => trả về kết quả tính tổng của 1->m

trong hàm main thực hiện tính giai thừa của 5 và tổng 1-10

so sánh 2 kết quả trên.

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

5

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

Nguyễn Tiến Đạt [T2008A]
Nguyễn Tiến Đạt

2020-09-18 08:33:51

Bai tap 1


#include<stdio.h>
void showlnfor(){
	printf("1.Ten: Nguyen Tien Dat\n2.Tuoi: 18\n3.Dia chi: Ha Noi\n4.Email: dattocngan@gmail.com\n5.So dien thoai: 0967962184");
}
int main(){
	showlnfor();
}



Đặng Trần Nhật Minh [T2008A]
Đặng Trần Nhật Minh

2020-09-18 08:27:38



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

int giaithua(int n) {
	
	int res = 1;
	
	for (int i = 1; i <= n; i++) res *= i;
	
	return res;
	
}

int tong(int m) {
	
	int sum = 0;
	
	for (int i = 1; i <= m; i++) sum += i;
	
	return sum;
	
}

int main() {

	int n, m;
	
	printf("Nhap n, m: "); scanf("%d%d", &n, &m);
	
	if (giaithua(n) > tong(m)) printf("giaithua n > tong m");
	else if(giaithua(n) < tong(m)) printf("Giaithua n < tong m");
	else printf("Giaithua n = tong n");
	
	return 0;

}



Nguyễn Hữu Hiếu [T2008A]
Nguyễn Hữu Hiếu

2020-09-18 08:22:13



//Bai 1902.2

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

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

void showMessage(int n) {

		printf("\nHello Message");
		
}
int main(int argc, char *argv[]) {
	showMessage(0);
	showMessage(2);
	showMessage(100);
	return 0;
}



Đặng Trần Nhật Minh [T2008A]
Đặng Trần Nhật Minh

2020-09-18 08:20:20


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

int showMessage(int msg) {
	
	printf("Hello %d", msg);
	
	return 0;
	
}

int main() {
	
	int a = 3;

	while (a--) {
		
		int n; 
		printf("\nNhap n: "); scanf("%d", &n);
		
		showMessage(n);
		
	}
	
	return 0;

}



Nguyễn Hữu Hiếu [T2008A]
Nguyễn Hữu Hiếu

2020-09-18 08:17:19



//Bai 1902.1

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

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

void showInfor() {
	printf("\nFullname: Nguyen Huu Hieu");
	printf("\nAge: Ha Noi");
	printf("\nAddress: Ha Noi");
	printf("\nEmail: nhh@gmail.com");
	printf("\nPhone: 5555588888");
}
int main(int argc, char *argv[]) {
	showInfor();	
	return 0;
}



Đặng Trần Nhật Minh [T2008A]
Đặng Trần Nhật Minh

2020-09-18 08:13:58

BAI 1


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

void ShowInfor() {
	
	printf("\nTen: Nhat Minh\nTuoi: 17\nDia chi: Ha Noi\nEmail: nm@gmail.com\nSDT: 0988766554");
	
}

int main() {

	ShowInfor();

}