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

📄 promediodelarreglo.cpp

📁 Topics Practices: Programming and Numerical Methods Practice 1: Introduction to C Practice 2
💻 CPP
字号:
// Escriba una funcion que calcule el promedio de un arreglo
// Usar la funcion para poner un cero en el lugar que el numero sea menor al promedio
#include<stdio.h>
#include<conio.h>

float promedio(float a[], int n)  // Hago la funcion.. 
{
      int i;
      float suma=0;
      for(i=0; i<n; ++i)
      suma+=a[i];
      return suma/n; // Retorno
}

main()
{
      int n,i;
     float p;
     
     printf("Ingrese el tama駉 del arreglo \n");
     scanf("%d" ,&n);
     
     float a[n];
       printf("Ingrese los elementos del arreglo\n ");
     for (i=0; i<n; ++i)//Para que recorra todos los elementos del arreglo..
     scanf("%f", &a[i]);
     p=promedio(a, n);
     printf("Promedio=%f \n", p);
     for (i=0; i<n; ++i)
       if(a[i]<p)
       a[i]=0;
     for (i=0; i<n; ++i)
     printf ("%.2f", a[i]);
     printf("\n");
printf("Precione cualquier tecla para terminar\n");
getch();
}               
     
     
     
     
     
           

⌨️ 快捷键说明

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