⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 practica6_3_otra forma.cpp

📁 Topics Practices: Programming and Numerical Methods Practice 1: Introduction to C Practice 2
💻 CPP
字号:
/*PRACTICA 6 EJERCICIO 3
Escribir un programa que le pida al usuario un conjunto de n鷐eros y que 
encuentre la moda de los n鷐eros introducidos (la moda de una muestra es el valor 
que m醩 se repite en la muestra).*/


#include<conio.h>
#include<stdio.h>
void swap(int b[],int i ,int j)
{int aux;
   aux=b[i];
   b[i]=b[j];
   b[j]=aux;
}
void ordenar(int b[], int n)
{
     int pos,i,k;
     for(i=0 ; i<n; ++i)
     { 
             pos=i;  
       for(k=i+1 ; k<n ; ++k)
       {
          if(b[pos]>b[k])
            pos=k;
       }
       swap(b,i,pos);
     }
} 
main()
{ int i,j,n,cont,max,moda;
    printf("Ingrese la cantidad de numeros que contiene el arreglo");
  scanf("%d",&n);
  int b[n],a[n];
  printf("Ingresa %d numeros",n);
  for(i=0; i<n;++i)
 {
      scanf("%d",&b[i]); //hasta aca tenemos el arreglo..
 }
  ordenar(b,n);
  printf("Los elementos del arreglo ordenados son:\n");
  for(i=0; i<n; ++i)
  {
   printf("%d ,",b[i]);
  }
  for(i=0; i<n ; ++i)
  { cont= 1;
   for(j=i+1 ; j<n && b[i]==b[j] ;++j)
   { 
    cont=cont+1;  
   }
   a[i] = cont;
  }
  max=a[0];
  moda=b[0];
  for(i=0 ; i<n ; ++i)
  {
    if(max < a[i])
    {
      max=a[i];
      moda=b[i];
    } 
  }            
  if(max > 1)
     printf("La moda del arreglo es: %d \n",moda);
  else
     printf("Son todos numeros distintos");
printf("PRESIONE CUALQUIER TECLA PARA TERMINAR!!!!!!!");
getch();
} 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -