[ create a new paste ] login | about

Link: http://codepad.org/0uzN9rZZ    [ raw code | output | fork ]

C, pasted on Aug 3:
#include<stdio.h>
#include<stdbool.h>
#define MAX_DONG 100
#define MAX_COT 100

void Nhap_Mang_2_Chieu(int arr[][MAX_COT],int dong,int cot) {
	for(int i = 0; i < dong; i++) {
		for(int j = 0; j < cot; j++) {
			printf("\nHay nhap gia tri cho arr[%d][%d]: ",i,j);
			scanf("%d",&arr[i][j]);
		}
	}
}

void Xuat_Mang_2_Chieu(int arr[][MAX_COT],int dong,int cot) {
	for(int i = 0; i < dong; i++) {
		for(int j = 0; j < cot; j++) {
			printf("\t%d",arr[i][j]);
		}
		printf("\n");
	}
}

bool So_Nguyen_To(int n) {
	if(n == 2) {
		return true;
	} else if(n < 2) {
		return false;
	} else if(n > 2) {
		for(int i = 2; i < n; i++) {
			if(n % i == 0) {
				return false;
			}
		}
	}
	return true;
}

int Tinh_Tong(int arr[][MAX_COT],int dong,int cot) {
	int Sum = 0;
	for(int i = 0; i < dong; i++) {
		for(int j = 0; j < cot; j++) {
			if(So_Nguyen_To(arr[i][j] == true)) {
				Sum += arr[i][j];
			}
		}
	}
	printf("\nTong cac phan tu la so nguyen to trong ma tran la:%d",Sum);
}

int main() {
	int arr[MAX_DONG][MAX_COT];
	int dong;
	int cot;
	do {
		printf("\nHay nhap so dong: ");
		scanf("%d",&dong);
		printf("\nHay nhap so cot: ");
		scanf("%d",&cot);
		if(dong < 1 || dong > MAX_DONG || cot < 1 || cot > MAX_COT) {
			printf("\nGia tri ban vua nhap khong hop le,hay nhap lai: ");
		}
	} while(dong < 1 || dong > MAX_DONG || cot < 1 || cot > MAX_COT);
	printf("\n\tNHAP GIA TRI CUA MANG 2 CHIEU:\n");
	Nhap_Mang_2_Chieu(arr,dong,cot);
	printf("\n\tXUAT GIA TRI CUA MANG 2 CHIEU:\n ");
	Xuat_Mang_2_Chieu(arr,dong,cot);
    Tinh_Tong(arr,dong,cot);
}


Output:
1
2
3
4
5
6
7
8
9
10
11
In function 'Nhap_Mang_2_Chieu':
Line 7: error: 'for' loop initial declaration used outside C99 mode
Line 8: error: 'for' loop initial declaration used outside C99 mode
In function 'Xuat_Mang_2_Chieu':
Line 16: error: 'for' loop initial declaration used outside C99 mode
Line 17: error: 'for' loop initial declaration used outside C99 mode
In function 'So_Nguyen_To':
Line 30: error: 'for' loop initial declaration used outside C99 mode
In function 'Tinh_Tong':
Line 41: error: 'for' loop initial declaration used outside C99 mode
Line 42: error: 'for' loop initial declaration used outside C99 mode


Create a new paste based on this one


Comments: