[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
Tags:
Phản hồi từ học viên
5
(Dựa trên đánh giá ngày hôm nay)
Hồ Chí Đại
2020-10-22 09:23:29
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;
}
Nguyen ky anh
2020-10-20 14:16:28
#main.1.c
#include <stdio.h>
#include <stdlib.h>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
//bai1
int sochinhphuong(int n){
printf("\nNhap n = ");
scanf("%d", &n);
int j = 0;
while(j*j <= n){
if(j*j == n){
printf("%d la so chinh phuong!\n", n);
return 0;
}
++j;
}
printf("%d khong phai so chinh phuong!\n", n);
}
int main(int argc, char *argv[]) {
int N,i;
printf("\nNhap mang N= ");
scanf("%d",&N);
int b=0;
int a[N];
for(i=0;i<a;i++){
printf("\na[%d]",i+1);
scanf("%d",&a[i]);
}
for(i=0;i<a;i++){
printf("\nNhap a[%d]= ", i,a[i]);
}
for(i=0;i<3;i++){
if(a[i]%5==0){
b=b+a[i];
}
}
printf("\nTong cac so chia het cho 5=%d", b);
}
#main.3.c
#include <stdio.h>
#include <stdlib.h>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
//bai2
#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 2
int i;
typedef struct Sinhvien_ST{
char name[50], rollno[30];
int age;
}Sinhvien;
void showMenu(Sinhvien *p,int n){
for(i=0;i<n;i++){
printf("\nNhap sinh vien thu %d", i+1);
printf("\nNhap ten");
fflush(stdin);fflush(stdout);
gets(p[i].name);
printf("\nNhap ma sv");
fflush(stdin);fflush(stdout);
gets(p[i].rollno);
printf("\nNhap tuoi");
fflush(stdin);fflush(stdout);
scanf("%d",p[i].age);
}
}
void input (Sinhvien *p,int n) {
for(i=0;i<n;i++)
if(sqrt(p[i].age)*sqrt(p[i].age) == p[i].age){
printf("\nTen %s",p[i].name);
printf("\nMa %s", p[i].rollno);
printf("\nTuoi %s",p[i].age);
}
}
int main(int argc, char *argv[]) {
int n;
Sinhvien danhsachsinhvien[n];
printf("\nNhap so sin vien: ");
scanf("%d",&n);
showMenu(danhsachsinhvien,n);
input(danhsachsinhvien,n);
return 0;
}
Nguyen ky anh
2020-10-20 14:16:26
#main.1.c
#include <stdio.h>
#include <stdlib.h>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
//bai1
int sochinhphuong(int n){
printf("\nNhap n = ");
scanf("%d", &n);
int j = 0;
while(j*j <= n){
if(j*j == n){
printf("%d la so chinh phuong!\n", n);
return 0;
}
++j;
}
printf("%d khong phai so chinh phuong!\n", n);
}
int main(int argc, char *argv[]) {
int N,i;
printf("\nNhap mang N= ");
scanf("%d",&N);
int b=0;
int a[N];
for(i=0;i<a;i++){
printf("\na[%d]",i+1);
scanf("%d",&a[i]);
}
for(i=0;i<a;i++){
printf("\nNhap a[%d]= ", i,a[i]);
}
for(i=0;i<3;i++){
if(a[i]%5==0){
b=b+a[i];
}
}
printf("\nTong cac so chia het cho 5=%d", b);
}
#main.3.c
#include <stdio.h>
#include <stdlib.h>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
//bai2
#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 2
int i;
typedef struct Sinhvien_ST{
char name[50], rollno[30];
int age;
}Sinhvien;
void showMenu(Sinhvien *p,int n){
for(i=0;i<n;i++){
printf("\nNhap sinh vien thu %d", i+1);
printf("\nNhap ten");
fflush(stdin);fflush(stdout);
gets(p[i].name);
printf("\nNhap ma sv");
fflush(stdin);fflush(stdout);
gets(p[i].rollno);
printf("\nNhap tuoi");
fflush(stdin);fflush(stdout);
scanf("%d",p[i].age);
}
}
void input (Sinhvien *p,int n) {
for(i=0;i<n;i++)
if(sqrt(p[i].age)*sqrt(p[i].age) == p[i].age){
printf("\nTen %s",p[i].name);
printf("\nMa %s", p[i].rollno);
printf("\nTuoi %s",p[i].age);
}
}
int main(int argc, char *argv[]) {
int n;
Sinhvien danhsachsinhvien[n];
printf("\nNhap so sin vien: ");
scanf("%d",&n);
showMenu(danhsachsinhvien,n);
input(danhsachsinhvien,n);
return 0;
}
Tung Nguyen
2020-10-20 14:16:05
#main.1.c
#include <stdio.h>
#include <stdlib.h>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
//bai1
int sochinhphuong(int n){
printf("\nNhap n = ");
scanf("%d", &n);
int j = 0;
while(j*j <= n){
if(j*j == n){
printf("%d la so chinh phuong!\n", n);
return 0;
}
++j;
}
printf("%d khong phai so chinh phuong!\n", n);
}
int main(int argc, char *argv[]) {
int N,i;
printf("\nNhap mang N= ");
scanf("%d",&N);
int b=0;
int a[N];
for(i=0;i<a;i++){
printf("\na[%d]",i+1);
scanf("%d",&a[i]);
}
for(i=0;i<a;i++){
printf("\nNhap a[%d]= ", i,a[i]);
}
for(i=0;i<3;i++){
if(a[i]%5==0){
b=b+a[i];
}
}
printf("\nTong cac so chia het cho 5=%d", b);
}
#main.3.c
#include <stdio.h>
#include <stdlib.h>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
//bai2
#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 2
int i;
typedef struct Sinhvien_ST{
char name[50], rollno[30];
int age;
}Sinhvien;
void showMenu(Sinhvien *p,int n){
for(i=0;i<n;i++){
printf("\nNhap sinh vien thu %d", i+1);
printf("\nNhap ten");
fflush(stdin);fflush(stdout);
gets(p[i].name);
printf("\nNhap ma sv");
fflush(stdin);fflush(stdout);
gets(p[i].rollno);
printf("\nNhap tuoi");
fflush(stdin);fflush(stdout);
scanf("%d",p[i].age);
}
}
void input (Sinhvien *p,int n) {
for(i=0;i<n;i++)
if(sqrt(p[i].age)*sqrt(p[i].age) == p[i].age){
printf("\nTen %s",p[i].name);
printf("\nMa %s", p[i].rollno);
printf("\nTuoi %s",p[i].age);
}
}
int main(int argc, char *argv[]) {
int n;
Sinhvien danhsachsinhvien[n];
printf("\nNhap so sin vien: ");
scanf("%d",&n);
showMenu(danhsachsinhvien,n);
input(danhsachsinhvien,n);
return 0;
}
To Khuong Loc
2020-10-20 14:13:15
#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 *t, n, i, sum = 0;
t = (int *)calloc(n, sizeof(int));
printf("nhap tong so phan tu cua mang: \n");
scanf("%d", &n);
printf("Nhap cac phan tu cho mang: \n");
for(i = 0; i < n; i++) {
scanf("%d", t + i);
if(t[i] % 5 == 0) {
sum += t[i];
}
}
printf("\ntong so phan tu trong mang chia het cho 5 la: %d\n", sum);
printf("so chinh phuong trong mang la:");
for(i = 0; i < n; i++){
if(sqrt(t[i])*sqrt(t[i]) == t[i]){
printf("\n%d ", t[i]);
}
}
int j;
for(i = 0; i < n; i++)
for(j = i;j < n; j++){
if(t[j]%2 == 0){
int val = t[i];
t[i] = t[j];
t[j] = val;
}
}
printf("\nSap xep cac phan tu trong mang theo thu tu chan--le la :");
for(i = 0; i < n; i++)
printf("%d ", t[i]);
return 0;
}
========== bt1
#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 *t, n, i, sum = 0;
t = (int *)calloc(n, sizeof(int));
printf("nhap tong so phan tu cua mang: \n");
scanf("%d", &n);
printf("Nhap cac phan tu cho mang: \n");
for(i = 0; i < n; i++) {
scanf("%d", t + i);
if(t[i] % 5 == 0) {
sum += t[i];
}
}
printf("\ntong so phan tu trong mang chia het cho 5 la: %d\n", sum);
printf("so chinh phuong trong mang la:");
for(i = 0; i < n; i++){
if(sqrt(t[i])*sqrt(t[i]) == t[i]){
printf("\n%d ", t[i]);
}
}
int j;
for(i = 0; i < n; i++)
for(j = i;j < n; j++){
if(t[j]%2 == 0){
int val = t[i];
t[i] = t[j];
t[j] = val;
}
}
printf("\nSap xep cac phan tu trong mang theo thu tu chan--le la :");
for(i = 0; i < n; i++)
printf("%d ", t[i]);
return 0;
}
=============== bt2
#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 */
typedef struct Student_ST {
char name[50];
char rollno[20];
int age;
} Student;
int main(int argc, char *argv[]) {
int i, n;
printf("nhap tong so sinh vien trong mang: \n");
scanf("%d", &n);
Student studentList[n];
for(i = 0; i < n; i++) {
printf("\nNhap ten: ");
fflush(stdin);fflush(stdout);
gets(studentList[i].name);
printf("\nNhap rollno: ");
fflush(stdin);fflush(stdout);
gets(studentList[i].rollno);
printf("\nNhap age: ");
scanf("%d", &studentList[i].age);
}
printf("sinh vien co tuoi la so chinh phuong la:");
for(i = 0; i < n; i++){
if(sqrt(studentList[i].age) * sqrt(studentList[i].age) == studentList[i].age){
printf("%s ", studentList[i].name);
}
}
return 0;
}
ĐINH VĂN MẠNH
2020-10-20 14:07:28
void swap(int &a, int &b) {
int temp = a;
a = b;
b = temp;
}
int main() {
printf("\nNhap n: ");
int n; scanf("%d", &n);
int a[n], sum = 0;
printf("\nNhap mang: ");
for (int i = 0; i < n; i++) {
printf("\nNhap a[%d]: ", i);
scanf("%d", &a[i]);
if (a[i] % 5 == 0) sum += a[i];
}
printf("\nTong cac so chia het cho 5 la: %d", sum);
printf("\nCac so chinh phuong la: ");
for (int i = 0; i < n; i++) {
int test = sqrt(a[i]);
if (test * test == a[i])
printf("\n%d", a[i]);
}
for(int i = 0; i < n - 1; i++)
for (int j = i; j < n; j++)
if (a[j] % 2 == 0) {swap(a[i], a[j]); break;}
printf("\nSau sap xep: ");
for (int i = 0; i < n; i++)
printf("%d ", a[i]);
}
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
void swap(int &a, int &b) {
int temp = a;
a = b;
b = temp;
}
int main() {
printf("\nNhap n: ");
int n; scanf("%d", &n);
int a[n], sum = 0;
printf("\nNhap mang: ");
for (int i = 0; i < n; i++) {
printf("\nNhap a[%d]: ", i);
scanf("%d", &a[i]);
if (a[i] % 5 == 0) sum += a[i];
}
printf("\nTong cac so chia het cho 5 la: %d", sum);
printf("\nCac so chinh phuong la: ");
for (int i = 0; i < n; i++) {
int test = sqrt(a[i]);
if (test * test == a[i])
printf("\n%d", a[i]);
}
for(int i = 0; i < n - 1; i++)
for (int j = i; j < n; j++)
if (a[j] % 2 == 0) {swap(a[i], a[j]); break;}
printf("\nSau sap xep: ");
for (int i = 0; i < n; i++)
printf("%d ", a[i]);
}
Trinh Quoc Dai
2020-10-20 14:06:03
#123.c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct Student_ST {
char name[50];
char rollno[20];
int age;
} Student;
int main(int argc, char *argv[]) {
Student studentList[5];
int i;
for(i=0;i<5;i++) {
printf("\nNhap thong tin sinh vien thu %d", i + 1);
printf("\nNhap ten: ");
fflush(stdin);fflush(stdout);
gets(studentList[i].name);
printf("\nNhap tuoi: ");
fflush(stdin);fflush(stdout);
scanf("%d", &studentList[i].age);
}
//Hien thi thong tin sinh vien
for(i=0;i<5;i++) {
if(sqrt(studentList[i].age)*sqrt(studentList[i].age)==studentList[i].age){
printf("\nTen: %s, tuoi: %d", studentList[i].name, studentList[i].age);
}
return 0;
}
#test.c
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
//BAI 1:
int main(int argc, char *argv[]) {
int N;
printf("\nNhap so N= ");
scanf("%d", &N);
int k[N], i;
for(i = 0;i < N;i++){
printf("\nNhap k[%d]=", i);
scanf("%d", &k[i]);
}
int sum = 0;
for(i = 0;i < N;i++){
if(k[i]%5==0){
sum+=k[i];
}
}printf("\nTong=%d",sum);
for(i = 0;i < N;i++){
if(sqrt(k[i])*sqrt(k[i]) == k[i]){
printf("\n%d", k[i]);
}
}
int p, n;
for(i = 0;i < N;i++){
for(p = i +1;p < N;p++){
if(k[p]%2==0){
n = k[i];
k[i] = k[p];
k[p] = n;
}
}
}printf("\nMang sau khi sap xep: ");
for(i = 0;i < N;i++){
printf("%d", k[i]);
}
return 0;
}
ĐINH VĂN MẠNH
2020-10-20 14:05:28
#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;
}
ĐINH VĂN MẠNH
2020-10-20 14:04:02
C2002L
#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, 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<n;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 chi phuong la: ");
for(i=0;i<n;i++){
if(sqrt(t[i])*sqrt(t[i])==t[i]){
printf("\n%d",t[i]);
}
}
int j;
for(i=0;i<n-1;i++){
for(j=i+1;j<n;j++){
if(t[j] % 2 ==0 ){
int temp = t[i];
t[i] = t[j];
t[j] = temp;
}
}
}
printf("\nDay so sau sap xep, cac so chan len dau, so le ve cuoi nhu sau: ");
for(i=0;i<n;i++){
printf("\n%d", t[i]);
}
return 0;
}
Hoa Hoang
2020-10-20 14:03:05
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;
int s=0;
printf("Nhap N:");
scanf("%d", &N);
int arr[N];
for(i=0; i<N; i++){
printf("\n arr[%d]", i+1);
scanf("%d", &arr[i]);
}
for(i=0; i<N; i++){
if(arr[i]%5 == 0){
s=s+arr[i];
}
}
printf("\nTong cac so chia het cho 5=%d", s);
printf("\n");
printf("\nCac so chinh phuong :");
for(i=0; i<N; i++){
if(sqrt(arr[i])*sqrt(arr[i])== arr[i]){
printf("%d", arr[i]);
}
}
int j;
for(i=0; i<N; i++){
for(j=i; j<N; j++){
if(arr[j]%2 ==0){
int m = arr[i];
arr[i] = arr[j];
arr[j] = m;
}
}
}
printf("\nMang sau khi sap xep la:");
for(i=0; i<N; i++){
printf("%d", arr[i]);
}
return 0;
}
Bai 2
#include <stdio.h>
#include <stdlib.h>
#incluce <math.h>
typedef struct SinhVien{
char name[50];
char rollno[20];
int age;
}SinhVien;
int main(int argc, char *argv[]) {
int n;
printf("\nNhap so luong sinh vien: ");
scanf("%d", &n);
SinhVien SinhVienlist[n];
int choose, i;
do{
printf("\n1.Khai bao mang gom n sinh vien");
printf("\n2.Hien thi hien thi thong tin sinh vien co tuoi la so chinh phuong");
printf("\n3.Thoat");
printf("\nchon: ");
scanf("%d", %choose);
switch(choose){
case 1:
for(i=0; i<n; i++){
printf("\nSinh vien thu %d", i+1);
fflush(stdin),fflush(stdout);
printf("\nNhap ten: ");
fflush(stdin),fflush(stdout);
gets(SinhVienlist[i].name);
printf("\nNhap ma sinh vien: ");
fflush(stdin),fflush(stdout);
gets(SinhVienlist[i].rollno);
printf("|nNhap tuoi: ");
fflush(stdin),fflush(stdout);
scanf("%d", SinhVienlist[i].age);
}
break;
case 2:
int count=0;
for(i=0; i<n; i++){
if(sqrt(SinhVienList[i].age)*sqrt(SinhVienList[i].age)==SinhVienList[i].age){
count++;
}
if(count!=0){
for(i=0; i<n; i++){
if(sqrt(SinhVienList[i].age)*sqrt(SinhVienList[i].age)==SinhVienList[i].age){
printf("\nDanh sach sinh vien co tuoi là so chinh phuong la:\n");
}
}
}
}
break;
case 3:
printf("\nExit!");
break;
default;
printf("\nNhap sai!!");
break;
}
}while(choose != n);
return 0;
}