This web page requires JavaScript to be enabled.

JavaScript is an object-oriented computer programming language commonly used to create interactive effects within web browsers.

How to enable JavaScript?

Tổng dòng/cột max, dòng có nhiều số nguyên tố trong mảng 2 chiều

10cth1-2 July 30, 2011 Nam Le 0

Thao tác trên mảng 2 chiều:

[codes=c]#include “stdio.h”
#include “conio.h”
#include “math.h”
#define row 100
#define col 100

void nhapmang(int a[][col],int dong, int cot)
{
  for(int i=0; i    for(int j=0; j      {
        printf(“NHap phan tu cua mang: a[%d][%d]”,i, j);
        scanf(“%d”,&a[i][j]);
      }
}

void xuatmang(int a[][col],int dong, int cot)
{
  for(int i=0; i     {
      for(int j=0; j        printf(“%4d”, a[i][j]);
        printf(“\n”);
     }

}

long tongdong(int a[][col],int cot,int i)
{
  long s=0;
  for(int j=0; j  {
    s+=a[i][j];
  }
  return s;
}

int timdongmax(int a[][col], int dong, int cot)
{
  int vt=0;
  for( int i=0;i    for( int j=0; j       {
        if(tongdong(a,cot,i)>tongdong(a,cot,vt))
          vt=i;
       }
  return vt;
}

long cotmax(int a[][col], int dong,int j)
{
  long scot=0;
  for(int i=0; i    scot+=a[i][j];
  return scot;
}

int timcotmax(int a[][col],int dong, int cot)
{
  int vtcot=0;
  for(int i=0; i    for(int j=0; j      {
        if(cotmax(a, dong, j)>cotmax(a, dong, vtcot))
          vtcot=j;
      }
  return vtcot;
}

int ktnt(int p)
{
  if(p<2) return 0;
  for(int u=2; u<=sqrt(p); u++)
    if(p%u==0)
      return 0;
  return 1;
}

int demdongngto(int a[][col], int cot, int i)
{
  int demdong=0;
  for(int j=0; j    {
      if(ktnt(a[i][j]))
        demdong++;
    }
  return demdong;
}

int tim_dong_nh_nt(int a[][col], int dong, int cot)
{
  int vtdong=0;
  for(int i=0; i    for(int j=0;j      {
        if(demdongngto(a, cot, i)>demdongngto(a, cot, vtdong))
          vtdong=i;
      }
  return vtdong;
}

void main()
{
  clrscr();
  int a[row][col],dong,cot;
  printf(“Nhap vao so dong”); scanf(“%d”,&dong);
  printf(“Nhap vao so cot”); scanf(“%d”,&cot);
  nhapmang(a, dong, cot);
  printf(“Mang vua nhap la \n”);
  xuatmang(a, dong, cot);
  int kq1= timdongmax(a, dong, cot);
  printf(“Dong co tong lon nhat la %d \n”,kq1);
  int kq2= timcotmax(a, dong, cot);
  printf(“Cot co tong lon nhat la %d \n”,kq2);
  int kq3= tim_dong_nh_nt(a, dong,cot);
  printf(“Dong co nhieu co nguyen to la %d \n”, kq3);
  getch();
}
[/codes]


Last modified on December 9th, 2020 at 1:28 am

Nam Le
lequocnam



0 responds

Leave a Reply

Your email address will not be published. Required fields are marked *