29.12.2008, 11:22. Просмотров 2333. Ответов 14
Огрррромная просьба!!!Все есть и условие и программа,но!!!!
Условие:Дана Двумерная матрица m*n и одномерный массив,посчитать сумму каждого столбца матрицы,номер которого не является элементом одномерного массива.Счет столбцов в моей проге идет с нулегого.
Загвоз вот в чем:
Код
#include <stdio.h>
#include <conio.h>
#include <math.h>
#include <stdlib.h>
#include<string.h>
#include <fstream.h>
const int N=499;
int m,i;
const unsigned n=9;
int kol,b,a,c,d;
void output(char *t, int tmass)
{
printf(t, tmass);
}
void InpFile(char *NameF, int *x)
{
m=0;
ifstream finput;
finput.open(NameF);
finput>>x[m];
while (!finput.eof())
{
m++;
finput>>x[m];
if(m>N){ printf("nelzia schitat ");
break;}
}
finput.close();
}
void printMass(int co1, int co2, int **tmass)
{
for( int i = 0; i < co1; i++ )
{
for( int j = 0; j < co2; j++ )
{
output(" %d\t", tmass[i][j]);
}
output("\n", 0);
}
}
int** getMassFromFile( char *fname, int &count1, int &count2 )
{
FILE *file = fopen( fname, "r" );
if( file == NULL ) return NULL;
char str[512], *pstr;
count1 = 0; count2 = 0;
int **mass;
memset( str, 0, 512 );
while( ( fgets( str, 511, file) ) && (count1<500) )
{
count2 = 0;
pstr = strtok( str, " " );
do
{
count2++;
pstr = strtok( NULL, " " );
}
while( pstr );
count1++;
memset( str, 0, 512 );
}
mass = new int*[count1];
for( int a = 0; a < count1; a++ )
{ mass[a] = new int [count2]; }
fseek( file, 0, SEEK_SET );
count1 = 0;
while( fgets( str, 511, file) )
{
count2 = 0;
pstr = strtok( str, " " );
do
{
mass[count1][count2] = atoi(pstr);
count2++;
pstr = strtok( NULL, " " );
}
while( pstr );
count1++;
memset( str, 0, 512 );
}
printMass(count1, count2, mass);
fclose( file );
return mass;
}
int main (void)
{
int **array;
int i,j;
printf("Load source file data: \n ");
array=getMassFromFile( "input.txt", i, j );
FILE *ofile = fopen ("mask.txt", "r");
int maskArray[N];
InpFile("mask.txt", maskArray);
int n,m,sum=0;
for(n=0;n<co1;n++)
{
printf("%d ",maskArray[n]);
}
n=0;
for(n=0;n<co1;n++)
{
if(maskArray[n]==array[0][n])
{
for (m=0; m<co2;m++)
sum+=array[m][n];
printf("Summa %d \n",sum);
}
}
FILE *wfile = fopen ("arrayOuput.txt", "w");
fprintf(wfile, "%d\n", sum );
fclose(wfile);
return 1;
}
это текст,все пашет,ток создать три текстовых файла.А я хочу вот что.У меня ограничение при проверке 5 и в двумерном и в одномерном(строки 114,121 и 126) я хочу чтобы если в массиве больше 5,тож считал,или хотяб предупереждал о том,что массив больше...воооть,помогиииите плиз!!!
или перепишите ее...
0
|