C++

Найти номера всех элементов с максимальным значением

Решение 1
#include <iostream>
using std::cout;
using std::cin;
int main(){
    float **a;
    int n,m,i,j;
    cout<<"n: ";cin>>n;
    cout<<"m: ";cin>>m;
    cout<<"A:"<<std::endl;
    a=new float* [n];
    for(i=0;i<n;i++){
        a[i]=new float [m];
        for(j=0;j<m;j++)
            cin>>a[i][j];
    }
    for(i=0;i<n;i++){
        for(j=0;j<m;j++)
            cout<<a[i][j];
        cout<<std::endl;
    }
    cout<<"nepBbIE oTpuu,aTeJIbHbIe CTPOK:"<<std::endl;
    for(i=0;i<n;i++){
        for(j=0;j<m;j++)
            if(a[i][j]<0){
                cout<<a[i][j]<<std::endl;
                break;
            }
            if(j==m) cout << "Bce noJLo}|{uTeJIbHb|"<<std::endl;
    }
    cout<<"nepBbIE oTpuu,aTeJIbHbIe CTOJI6u,oB:"<<std::endl;
    for(i=0;i<n;i++){
        for(j=0;j<m;j++)
            if(a[j][i]<0){
                cout<<a[j][i]<<std::endl;
                break;
            }
        if(j==m) cout << "Bce noJLo}|{uTeJIbHb|"<<std::endl;
    }
    system("pause");
    return 0;
}

Решение 2
#include <stdio.h>
 
int main(int argc, char * argv [])
{
    const short N = 10;
    int mas[N] = {58, 7, 476, 47, 7, 4, 954, 89, 4, 477};
 
    int max = mas[0], maxElem = 1;
 
    for(int i = 1; i < N; i++)
    {
        if(mas[i] > max)
        {
            max = mas[i];
            maxElem = i + 1;
        }
    }
 
    printf("Maximal element for array: %d\n", maxElem);
 
    return 0;
}
Теги:
массив
Добавлено: 23 Сентября 2013 12:28:06 Добавил: Андрей Ковальчук Нравится 0
Добавить
Комментарии:
Нету комментариев для вывода...