Форум С++

 

Ответить на сообщение

Вернуться к теме

Вы отвечаете на сообщение:

Автор: StarWorm   (17.11.2008 в 23:53)
Честно... Я не смотрел твое решение, а сам написал новое! Оно точно работает, но не знаю, лучше оно или хуже!
Будет время - может посмотрю...
#include "stdafx.h"
#include <iostream>
#include <conio.h>
#include <time.h>

using namespace std;

int numCol(int** arr,int str,int col)
{
for(int j=0;j<col;j++)
for(int i=0;i<str;i++)
if(arr[i][j]==0)
return j+1;
return 0;
}

int main()
{
srand( (unsigned)time( NULL ) );
int min_range=-2,max_range=2;
int n=0,m=0,colZero=0;
cout<<"Enter dimensinsions of array: ";
cin>>n>>m;
int** arr=new int*[n];
for(int i=0;i<n;i++)
arr[i]=new int[m];
for(int i=0;i<n;i++)
for(int j=0;j<m;j++)
{
cout<<"\nEnter element arr("<<i+1<<","<<j+1<<"): ";
//cin>>arr[i][j];
arr[i][j]=(rand()%(max_range-min_range+1))+min_range; //Это для отладки... массив случайных чисел от min_range до max_range
}
cout<<"\n\nYour array is: \n";
for(int i=0;i<n;i++)
{
for(int j=0;j<m;j++)
{
cout<<"\t"<<arr[i][j];
}
cout<<"\n";
}
colZero=numCol(arr,n,m);
if(colZero)
cout<<"\nAnswer: column #"<<colZero<<" have element \'0\' first";
else
cout<<"\nAnswer: no columns with element \'0\'";
getch();
return 0;
delete [] arr;
}


Ваше имя:

Пароль:

Цитировать

Используйте тэги для выделения текста:
Код: [code][/code]
Жирный: [b][/b]
Наклонный: [i][/i]
URL: [url][/url]

Сообщение:

Прикрепить: