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

[Test] Kiểm tra 60 phút - Lập trình C

Bài 1:

- Nhập vào mảng gồm N số nguyên

Yêu cầu:

- Tính tổng các số chia hết cho 5

- Tìm các số chính phương (a luỹ thừa 2).

- Sắp xếp mảng sao cho các phần tử chẵn ở đầu mảng, các phần tử lẻ ở cuối mảng

Bài 2:

Tạo struct sinhvien gồm các thuộc tính sau char name[50], rollno[20], int age.

Khai báo 1 mảng gồm N sinh viên => N nhập từ bàn phím

Hiển thị thông tin sinh viên có tuổi là số chính phương

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

5

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

vuong huu phu [T2008A]
vuong huu phu

2020-09-30 10:05:24


bai 1


#include <stdio.h>
#include <stdlib.h>
#include <math.h>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
//bai 1
int main(int argc, char *argv[]) {
int n,t,i;
printf("\n nhap so n: ");
	scanf("%d",&n);	
int a[n];
for(i=0;i<n;i++){
	printf("\n nhap so nguyen %d ",i+1);
	scanf("%d",&a[i]);
}
t=0;
for(i=0;i<=n;i++){
	if(a[i]%5==0){
	t=t+a[i];	
	}
}
printf("\n tong cua cac so chia het cho 5: %d ",t);
printf("\n so chinh phuong la: ");
for(i=0;i<=n;i++){
	if(sqrt(a[i])*sqrt(a[i])==a[i]){
		printf ("%d ",a[i]);
	}
}
printf("\n sap xep : ");
for(i=0;i<n;i++){
	if(a[i]%2==0){
		printf("%d ",a[i]);}}
for(i=0;i<n;i++){
	if(a[i]%2!=0){
		printf("%d ",a[i]);}}
	return 0;
}



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

2020-09-30 10:00:52



#include <stdio.h>
#include <stdlib.h>
typedef struct studentST {
		char name[50], rollno[20];
		int age;
	} student;
/* run this program using the console pauser or add your own getch, system("pause") or input loop */

int main(int argc, char *argv[]) {
	int i, j, n;
	printf("\nNhap so luong sinh vien: n =  ");
	scanf("%d", &n);
	student studentList[n];
	for(i=0;i<n;i++) {
		printf("\nNhap thong tin sinh vien thu %d", i+1);
		printf("\n1. Ten sinh vien: ");
		fflush(stdin); fflush(stdout);
		gets(studentList[i].name);
		printf("\n2. Ma SV: ");
		fflush(stdin); fflush(stdout);
		gets(studentList[i].rollno);
		printf("\n3. Tuoi: ");
		scanf("%d", &studentList[i].age);
	}
	
	for(i=0;i<n;i++) {
		printf("\nThong tin sinh vien thu %d", i+1);
		printf("\n%10s, %10s, %10d", 
			studentList[i].name, studentList[i].rollno, studentList[i].age);
	}
	printf("\n Thong tin sinh vien co so tuoi la so chinh phuong: ");
	for(i=0;i<n;i++) {
		for(j=1;j<1000;j++) {
			if(studentList[i].age == j*j) {
				printf("\n%10s, %10s, %10d", 
					studentList[i].name, studentList[i].rollno, studentList[i].age);
			}
		}
		
	}
	
	return 0;
}



An Văn Minh [T2008A]
An Văn Minh

2020-09-30 10:00:19



//Bai 1:
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
int SoChiPhuong(int a)
{
   for (int i=1; i<a; i++)
       if (i*i == a)
           return 1;
   return 0;
}
int main(){
	int N,i;
	int s=0;
	printf("\nNhap N: ");
	scanf("%d", &N);
	int t[N];
	for(i=0;i<N;i++){
		printf("\nt[%d]=", i+1);
		scanf("%d", &t[i]);
	}
	for(i=0;i<3;i++){
		if(t[i]%5==0){
			s=s+t[i];
		}
	}
	printf("\nTong cac so chia het cho 5=%d", s);
	printf("\n");
	printf("\nCac so chinh phuong la:");
	for(i=0;i<N;i++){
		if(sqrt(t[i])*sqrt(t[i])==t[i]){
			printf(" %d",t[i]);
		}
	}
		for(int i=0;i<N;i++)
		for(int j=i;j<N;j++){
			if(t[j]%2==0){
				int m = t[i];
				t[i]=t[j];
				t[j]=m;
			}
		}
		printf("\nMang sau khi sap xep la:");
		for(int i=0;i<N;i++)
		printf("%d ", t[i]);
	return 0;
}



An Văn Minh [T2008A]
An Văn Minh

2020-09-30 10:00:18



//Bai 1:
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
int SoChiPhuong(int a)
{
   for (int i=1; i<a; i++)
       if (i*i == a)
           return 1;
   return 0;
}
int main(){
	int N,i;
	int s=0;
	printf("\nNhap N: ");
	scanf("%d", &N);
	int t[N];
	for(i=0;i<N;i++){
		printf("\nt[%d]=", i+1);
		scanf("%d", &t[i]);
	}
	for(i=0;i<3;i++){
		if(t[i]%5==0){
			s=s+t[i];
		}
	}
	printf("\nTong cac so chia het cho 5=%d", s);
	printf("\n");
	printf("\nCac so chinh phuong la:");
	for(i=0;i<N;i++){
		if(sqrt(t[i])*sqrt(t[i])==t[i]){
			printf(" %d",t[i]);
		}
	}
		for(int i=0;i<N;i++)
		for(int j=i;j<N;j++){
			if(t[j]%2==0){
				int m = t[i];
				t[i]=t[j];
				t[j]=m;
			}
		}
		printf("\nMang sau khi sap xep la:");
		for(int i=0;i<N;i++)
		printf("%d ", t[i]);
	return 0;
}



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

2020-09-30 09:41:32



#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 N;
	printf("\nNhap N: ");
	scanf("%d", &N);
	int i, j, mang[N], count5 = 0, temp;
	for(i=0;i<N;i++) {
		printf("\nNhap so nguyen thu %d: ", i+1);
		scanf("%d", &mang[i]);
		if (mang[i] % 5 == 0) {
			count5 = count5 + mang[i];
		}
	}
	printf("\n1. Tong cac so chia het cho 5: %d", count5);
	printf("\n2. Cac so chinh phuong trong mang la: ");
	for(i=0;i<N;i++) {
		for(j=1;j<100000;j++) {
			if(mang[i] == j*j) {
				printf("%d, ", mang[i]);
				
			}
	
		}
	}
	
	printf("\nMang sap xep chan, le: ");
	for(i=0;i<N-1;i++) {
		for(j=i+1;j<N;j++) {
			if (mang[j] % 2 == 0) {
				temp = mang[i];
				mang[i] = mang[j];
				mang[j] = temp;
				}
		}
			
	}
	for(i=0;i<N;i++) {
		printf("%d, ", mang[i]);
		
	}
	
	
	return 0;
}



hainguyen [T2008A]
hainguyen

2020-09-30 09:38:21



#include <stdio.h>
#include <stdlib.h>
#include <math.h>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
// Bai 1.
int main(int argc, char *argv[]) {
	int N;
	printf("\nNhap N: ");
	scanf("%d", &N);
	
	int t[N], i;
	for(i=0;i<N;i++){
			printf("\nNhap t[%d]: ", i);
	        scanf("%d", &t[i]);
	}
		int s = 0;
	for(i=0;i<N;i++){
	
		if(t[i] % 5 == 0){
			s = s + t[i];
				printf("\nTong cac so chia het cho 5 la : %d ", s);
		}
	
	}
	
	for(i=0;i<N;i++){
			int sqr = sqrt(t[i]);
	if(sqr*sqr==t[i]){
		printf("\n%d ", t[i]);
	}
	}
	printf("\nSap xep mang: ");
	for(i=0;i<N;i++){
		if(t[i]%2 == 0){
			printf("\n%d", t[i]);
		}
		else if(t[i]%2 != 0){
			printf("\n%d", t[i]);
		}
	}

	return 0;
}



Triệu Văn Lăng [T2008A]
Triệu Văn Lăng

2020-09-30 09:32:14

bai 1


#include <stdio.h>
#include <stdlib.h>
#include <math.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 n, i, *p;
	printf("\nnhap n ");
	scanf("%d", &n);
	int A[n];
	for(i=0;i<n;i++) {
		printf("\nNhap so thu A[%d] ",i+1);
		scanf("%d", &A[i]);
	}
    int tong=0;
	for(i=0;i<n;i++) {
		if(A[i] % 5 ==0) {
			tong+=A[i];
			printf("\nTong cac so chia het cho 5 la %d", tong);
		}
			
		}
		
	for(i=0;i<n;i++) {
		int sqr=sqrt(A[i]);
		if(sqr*sqr==A[i]) {
			printf("\nCac so chinh phuong la %d",A[i]);
		}
		
	} 
	printf("\nMang sau khi sap xep ");
	for(i=0;i<n;i++) {
		if(A[i]%2==0) {
			printf("%d",A[i]);
		}
	}
	for(i=0;i<n;i++) {
		if(A[i]%2!=0) {
			printf("%d",A[i]);
		}
	}
		
	
		
	
	
	
	return 0;
}



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

2020-09-30 09:23:24


Bai tap 2
#include<stdio.h>
#include<math.h>

typedef struct SinhVien{
	char name[50], rollno[20]; 
	int age;
}SV;

void nhapdulieu(SV *p,int n){
	int i;
	printf("\nNhap thong tin sinh vien:\n");
	for(i=0;i<n;i++){
		printf("\nSinh vien thu %d:",i+1);
		fflush(stdin);
		printf("\nHo va ten: ");
		gets(p[i].name);
		fflush(stdin);
		printf("\nMa sinh vien: ");
		gets(p[i].rollno);
		fflush(stdin);
		printf("\nTuoi: ");
		scanf("%d",&p[i].age);
		fflush(stdin);
	}
}

void hienthi(SV *p,int n){
	int i;
	int count=0;
	for(i=0;i<n;i++){
		if(sqrt(p[i].age)*sqrt(p[i].age)==p[i].age){
			count++;
		}
	}
	if(count !=0){
		printf("\nDanh sach sinh vien co tuoi la so chinh phuong:\n");
	}
	if(count !=0){
		for(i=0;i<n;i++){
		    if(sqrt(p[i].age)*sqrt(p[i].age)==p[i].age){
			    printf("\nHo va ten: %s",p[i].name);
			    printf("\nMa sinh vien: %s",p[i].rollno);
			    printf("\nTuoi: %d",p[i].age);
			    printf("\n");
		    }
	    }
	}
	if(count==0){
		printf("\nKhong co sinh vien nao co tuoi la so chinh phuong");
	}
}

int main(){
	int n;
	printf("\nNhap so sinh vien: ");
	scanf("%d",&n);
	SV studentList[n];
	nhapdulieu(studentList,n);
	hienthi(studentList,n);
}



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

2020-09-30 09:17:14


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

typedef struct student_st {
	
	char name[50], rollno[20];
	int age;
	
} SV;

bool checkSquare(int a) {
	
	int test = sqrt(a);
		
	if (test * test == a) return true;
	else return false;
	
}

int main() {

	int n; printf("\nNhap n: "); scanf("%d", &n);
	
	SV a[n];
	
	for (int i = 0; i < n; i++) {
		
		printf("\nEnter data of student No.%d:", i + 1);
					
		printf("\nFull Name: ");
		fflush(stdin); fflush(stdout);
		gets(a[i].name);
					
		printf("\nRoll No: ");
		fflush(stdin); fflush(stdout);
		gets(a[i].rollno);
					
		printf("\nAge: ");
		fflush(stdin); fflush(stdout);
		scanf("%d", &a[i].age);
								
	}
	
	printf("\n|No.|Name                          |Roll Number    |Age  |"); //|3|30|15|5|
	
	int stt = 0;
	for (int i = 0; i < n; i++)
		if (checkSquare(a[i].age))
			printf("\n|00%d|%-30s|%-15s|%-5d|", ++stt, a[i].name, a[i].rollno, a[i].age);
			
	return 0;

}



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

2020-09-30 09:07:44


Bai 1
#include<stdio.h>
#include<math.h>

int tong(int *p,int n){
	int tong=0;
	int i;
	for(i=0;i<n;i++){
		if(p[i] % 5 ==0){
			tong=tong+p[i];
		}
	}
	return tong;
}

void sochinhphuong(int *p,int n){
	int i;
	printf("\nCac so chinh phuong la:");
	for(i=0;i<n;i++){
		if(sqrt(p[i]) * sqrt(p[i]) == p[i]){
			printf(" %d",p[i]);
		}
	}
}

void sapxep(int *p,int n){
	int i,j;
	printf("\nDay so duoc sap xep theo yeu cau la:");
	for(i=0;i<n-1;i++){
		for(j=i+1;j<n;j++){
			if(p[j]<p[i]){
				int temp=p[i];
				p[i]=p[j];
				p[j]=temp;
			}
		}
	}
	for(i=0;i<n;i++){
		if(p[i] % 2 ==0){
			printf(" %d",p[i]);
		}
	}
	for(i=0;i<n;i++){
		if(p[i] % 2 !=0){
			printf(" %d",p[i]);
		}
	}
}

int main(){
	int n;
	printf("\nNhap so phan tu trong mang: ");
	scanf("%d",&n);
	int a[n];
	int i;
	printf("\nNhap vao mang gom %d so nguyen:",n);
	for(i=0;i<n;i++){
		printf("\na[%d]= ",i);
		scanf("%d",a+i);
	}
	printf("\nTong cac so chia het cho 5 la %d",tong(a,n));
	sochinhphuong(a,n);
	sapxep(a,n);
	return 0;
}