Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Bài TH C Hành 2

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 7

Báo cáo thực tập bài 2

Họ tên: Lê Hải Đăng

MSSV: 23134011

bài 1:

#include <stdio.h>

#include <stdlib.h>

int main()

int i, j;

int arr [3][3];

int c= 0, a, b= 0, x;

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

for( j= 0; j< 3; j++){

printf("nhap cot %d hang %d: ", j+ 1, i+ 1);scanf("%d", &arr[j][i]);

while(b!= 1){

printf("1. in mang\n2. tim kiem\n3. thoat\n");scanf("%d", &a);

if(a== 1){

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

for( j= 0; j< 3; j++){

printf("%d, ", arr[j][i]);

if(j== 2)printf("\n");

}
if(a== 2){

printf("nhap so can tim: ");scanf("%d", &x);

while(c!= 1){

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

for( j= 0; j< 3; j++){

if(arr[j][i]== x){

printf("cot %d, hang %d\n", j+ 1, i+ 1);

c=1;

if(c != 1){

printf("khong co nhap lai: ");scanf("%d", &x);

if(a== 3)break;

return 0;

bài 2:

#include <stdio.h>

int main(){

int M[10];
int i,c;

float a,d;

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

printf("nhap du lieu:");

scanf("%d", &M[i]);

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

printf("%d\t", M[i]);

d=d+M[i];

printf("\n");

for (i=9; i>=0; i--){

printf("%d\t",M[i]);

printf("\n");

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

if (M[i]>M[i+1]){

c=M[i+1];

M[i+1]=M[i];

M[i]=c;

a=d/10;

printf("max %d \n", M[9]);

printf("min %d \n", M[0]);

printf("%0.2f",a );
return 0;

bài 3:

#include <stdio.h>

#include <stdlib.h>

int main(){

int n;

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

float m[n];

float a[n];

int i;

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

m[i]=rand()% 150;

for (i=1; i<n-1; i++){

a[i]= (m[i-1] + m[i] + m[i+1])/3;

a[0]=(m[0] + m[1])/2;

a[n-1]=(m[n-2]+ m[n-1])/2;

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

printf("%f\t",a[i]);

return 0;

}
bai 4:

#include <stdio.h>

#include<stdlib.h>

struct pro{

int sp;

int soluong;

};

typedef struct pro pro;

int main()

int n;

int i;

int b= 0, a, c, d, e= 0;

printf("nhap so luong san pham: ");scanf("%d", &n);

pro* arr= (pro*)malloc(n*sizeof(pro));

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

printf("nhap ma sp: ");scanf("%d", &arr[i].sp);

printf("nhap so luong: ");scanf("%d", &arr[i].soluong);

while(b!= 1){

printf("1. nhap hang.\n2.xuat hang.\n3. in.\n4. thoat.\n");scanf("%d", &a);

if(a== 1){

printf("nhap ma sp: ");scanf("%d", &c);

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

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

if(c== arr[i].sp){

arr[i].soluong+=d;
e++;

if(e== 0){

n++;

arr= (pro*)realloc(arr, n);

arr[n- 1].sp= c;

arr[n- 1].soluong= d;

if(a== 2){

printf("nhap ma sp: ");scanf("%d", &c);

printf("nhap so luong xuat: ");scanf("%d", &d);

for(int i= 0; i< n; i++){

if((c== arr[i].sp) && (d<= arr[i].soluong)){

arr[i].soluong-=d;

if((c== arr[i].sp) && (d> arr[i].soluong)){

printf("khong du so luong\n");

if (a== 3){

printf("ma sp:\tso luong:\n");

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

printf("%d\t%d\n", arr[i].sp, arr[i].soluong);

}
if(a== 4){

break;

return 0;

You might also like