Технический форум

Технический форум (http://www.tehnari.ru/)
-   C/C++/С# (http://www.tehnari.ru/f42/)
-   -   Сделайте программу (http://www.tehnari.ru/f42/t59024/)

павля 27.10.2011 17:57

Сделайте программу
 
:tehnari_ru_837: на практике вот задали такое...лёгкое относительно...а я не в состоянии осилить :tehnari_ru_121:

условие:
дано челое число N и набор из N целых чисел. Найти номера первого максимального и последнего минимального элемента из данного набора и вывести их в указанном порядке.

shrek=) 29.10.2011 15:21

Если я правильно понял задание: Найти максимальный минимальный элемент, то вот:
Код:

#include <iostream>
#include <stdlib.h>
#include <time.h>
using namespace std;
int main ()
{
    //srand (unsigned) time(NULL);
    srand(time(NULL));
    int a[1000], N, min=1000, max=-1000;
    cout<<"Enter N<1001    "; cin>>N;
    for (int i=0; i<=N; i++)
    {
        a[i]=rand()/100-100;
        if (a[i]<min) min=a[i];
        if (a[i]>max) max=a[i];
        cout<<a[i]<<"  ";
    }
    cout<<endl;
    cout<<"maximal \t"<<max<<endl;;
    cout<<"minimal \t"<<min<<endl;;
system ("pause");
}


shrek=) 29.10.2011 15:37

Первый код находит просто max и min, а вот это еще и их номера, что и требовалось:
Код:

#include <iostream>
#include <stdlib.h>
#include <time.h>
using namespace std;
int main ()
{
    //srand (unsigned) time(NULL);
    srand(time(NULL));
    int a[1000], N, min=1000, max=-1000, imin=0, imax=0;
    cout<<"Enter N<1001    "; cin>>N;
    for (int i=0; i<=N; i++)
    {
        a[i]=rand()/100-100;
        if (a[i]<min) {min=a[i]; imin=i;}
        if (a[i]>max) {max=a[i]; imax=i;}
        cout<<a[i]<<"  ";
    }
    cout<<endl;
    cout<<"Number maximal \t"<<imax<<"\t"<<max<<endl;;
    cout<<"Number minimal \t"<<imin<<"\t"<<min<<endl;;
system ("pause");
}



Часовой пояс GMT +4, время: 21:40.

Powered by vBulletin® Version 4.5.3
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.