Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <conio.h>
- #include <stdio.h>
- int a[50][50], m, n, i, j;
- void input_matrix(){
- printf("Nhap vao so hang:");
- scanf("%d", &m);
- printf("Nhap vao so cot:");
- scanf("%d", &n);
- for (i=0;i<m;i++){
- for (j=0;j<n;j++){
- nhaplai:
- printf("Nhap gia tri cho a[%d][%d]=", i+1, j+1);
- scanf("%d", &a[i][j]);
- if (a[i][j]<0||a[i][j]>100){
- printf("Xin hay nhap gia tri lon hon 0 va nho hon 100\n");
- goto nhaplai;
- }
- }
- }
- }
- void max_element(){
- int max=a[0][0], l, k;
- for (i=0;i<m;i++){
- for (j=0;j<n;j++){
- if (a[i][j]>max){
- max=a[i][j];
- l=i+1;
- k=j+1;
- }
- }
- }
- printf("Phan tu lon nhat trong ma tran la a[%d][%d]=%d", l, k, max);
- }
- int check_prime(int b){
- int dem=0;
- for (i=1;i<=b;i++){
- if (b%i==0)
- dem++;
- }
- if (dem==2)
- return 1;
- return 0;
- }
- void prime_matrix(){
- printf("\nCac so la nguyen to trong ma tran la:");
- for (i=0;i<m;i++){
- printf("\n%d", m);
- for (j=0;j<n;j++){
- if (check_prime(a[i][j]))
- printf("%d\t", a[i][j]);
- else
- printf("%d\t", 0);
- }
- }
- }
- int main(){
- input_matrix();
- max_element();
- prime_matrix();
- getch();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement