cho dãy số gồm n phần tử ( 0 { "@context": "https://schema.org", "@type": "QAPage", "mainEntity": { "@type": "Question", "name": " cho dãy số gồm n phần tử ( 0
0 bình luận về “cho dãy số gồm n phần tử ( 0<n<1000) viết chương trình tìm số nguyên xuất hiện nhiều nhất trong dãy số”
#include<bits/stdc++.h> using namespace std; #define cls system(“cls”) #include <stdio.h> #define MAX 100 void Input(int [MAX], int); void Count(int [MAX], int [MAX], int * ); void Print(int [MAX], int [MAX], int ); int main() { int n, a[MAX], b[MAX]; cout<<“Nhap n: “; cin>>n; Input(a, n); Count(a, b, &n); cout<<“\n”; Print(a, b, n); //samon247 return 0; } void Input(int a[MAX], int n) { int i;
#include<bits/stdc++.h>
using namespace std;
#define cls system(“cls”)
#include <stdio.h>
#define MAX 100
void Input(int [MAX], int);
void Count(int [MAX], int [MAX], int * );
void Print(int [MAX], int [MAX], int );
int main()
{
int n, a[MAX], b[MAX];
cout<<“Nhap n: “;
cin>>n;
Input(a, n);
Count(a, b, &n);
cout<<“\n”;
Print(a, b, n);
//samon247
return 0;
}
void Input(int a[MAX], int n)
{
int i;
for(i = 0;i < n; i++)
{
printf(“Nhap a[%d]: “, i);
scanf(“%d”, &a[i]);
}
}
void Count(int a[MAX], int b[MAX], int *n )
{
int i, j, t;
for(i = 0; i < *n; i++)
{
b[i] = 1;
}
for(i = 0; i < *n; i++)
{
for(j = i + 1; j < *n; j++)
{
if(a[i] == a[j])
{
b[i]++;
for(t = j; t < *n; t++)
{
a[t] = a[t + 1];
}
(*n)–;
j–;
}
}
}
}
void Print(int a[MAX], int b[MAX], int n)
{
int i, flag = 0, max;
max = b[0];
for(i = 1; i < n; i++)
{
if( b[i] > max)
{
max = b[i];
}
}
for( i = 0 ;i < n; i++ )
{
if((b[i] == max) && (flag == 0))
{
cout<<“Phan tu “<<a[i]<<“, “;
flag = 1;
i++;
}
if((b[i] == max) && (flag == 1))
{
cout<<a[i]<<“, “;
}
}
cout<<“la phan tu xuat hien nheu nhat trong mang”;
//samon247
return 0;
}