olyska20 Posted October 18, 2008 Report Share Posted October 18, 2008 суть задания надо создать массив целых чисел используя три прототипа первывй для заполнения массива случ числами второй для вывода его и третий считает сумму вот. программа вышла такая но компилятор очень ругается на одну ошибку он не распознает а как ему указать что а равносильно array вот программа #include "stdafx.h" #include <stdlib.h> #include <time.h> #include <stdio.h> #include <string.h> #include <iomanip.h> const int count = 5; int total; void fill (int *array,const int count){ for (int i = 0; i < count; i++) array = rand()%100; } void print (int *array,const int count){ for (int i = 0; i < count; i++) cout << array << ""; cout << endl; } void sum (int *array, const int count){ for (int i = 0; i < count; i++) total = 0; total += array; cout << total << endl; } int main(int argc, char* argv[]) { fill(a, count); return 0; } Link to comment Share on other sites More sharing options...
Тролль Posted October 18, 2008 Report Share Posted October 18, 2008 olyska20: а как ему указать что а равносильно array Объявить, что a - массив. Например, int a[count]; Вся программа будет выглядеть так: #include <iostream>#include <time.h> using namespace std;void fill (int *array,const int count){srand(time(NULL)); for (int i = 0; i < count; i++)array[i] = rand()%100;}void print (int *array,const int count){for (int i = 0; i < count; i++) cout << array[i] << " ";cout << endl;}void sum (int *array, const int count){int total = 0;for (int i = 0; i < count; i++) total += array[i];cout << total << endl;}int main(int argc, char* argv[]){const int count = 5;int a[count];fill(a, count); print(a,count);sum(a,count);getchar();return 0;} Link to comment Share on other sites More sharing options...
olyska20 Posted October 19, 2008 Author Report Share Posted October 19, 2008 пасибкиии :) Link to comment Share on other sites More sharing options...
olyska20 Posted October 19, 2008 Author Report Share Posted October 19, 2008 вот надо было написать прогу с массивом двумерным дальш графически его разбить на миноры причём размерр массива 4на 4 вот я написала всё ок работает #include "stdafx.h" #include <stdlib.h> #include <stdio.h> #include <time.h> #include <iostream.h> int main(int argc, char* argv[]) { int N = 4; int** a; a = new int*[N]; for (int i = 0; i < N; i++) a = new int[N]; srand((unsigned)time(NULL)); for ( i = 0; i < N; i++) { for (int j = 0; j < N; j++) a[j] = rand()%100; } for ( i = 0; i < N; i++){ for (int j = 0; j < N; j++) printf("%5d", a[j]); printf("\n"); } cout << endl; cout << endl; cout << "\t | \t " << endl; for ( i = 0; i < N - 3; i++){ for (int j = 0; j < N; j++) printf("%5d", a[0][j]); printf("\n"); cout << "\t | \t " << endl; } for ( i = 1; i < N - 2; i++){ for (int j = 0; j < N; j++) printf("%5d", a[1][j]); printf("\n"); cout << "\t | \t " << endl; } cout << "-----------------------" << endl; for ( i = 2; i < N - 1; i++){ for (int j = 0; j < N; j++) printf("%5d", a[2][j]); printf("\n"); cout << "\t | \t " << endl; } for ( i = 3; i < N ; i++){ for (int j = 0; j < N; j++) printf("%5d", a[3][j]); printf("\n"); cout << "\t | \t " << endl; } cout << endl; cout << endl; for ( i = 0; i < N; i++) { for (int j = 0; j < N; j++) printf("%5d", a[j]); printf("\n"); } return 0; } ВОТ А ТЕРЬ ПРОБЛЕМА НАД ЭТИ МИНОРЫ(Т.У ДЕЛИМ МАССИВ НА 4 РАВНЫХ КУСКА, И ПЕРЕМЕЩАЕМ ЛЕВЫЙ ВЕРХНИЙ КУСОК ВМЕСТО ПРАВОГО ВЕРХНЕГО КУСКА, ПРАВЫЙ ВЕРХН КУСОК ПЕРЕМЕЩАЕМ ВМЕСТО НИЖНЕГО ПРАВОГО КУСКА, НИЖНИЙ ПРАВЫЙ ПЕРЕМЕЩАЕМ ВМЕСТО НИЖНЕГО ЛЕВОГО КУСКА, И ЛЕВЫЙ НИЖНИЙ ИДЁТ НА МЕСТО ЛЕВОГО ВЕРХНЕГ. ЗНАЧИТ В КАЖДОМ КУСКЕ ПО 4 ЭЛЕМЕНТА МАССИВА ) ПРОКРУТИТЬ ПО ЧАСОВОЙ СТРЕЛКЕ Т.Е НАПРИМЕР ИСХОДНЫЙ МАССИВ НАДО ОЧЕНЬ СРОЧНО ОТВЕТТТТТТТТТТТТТТТ ДО ЗАВТРАШНЕГО ДНЯ ДО 5 ВЕЧЕРААААААА ПАСИБООООООООООООООО Link to comment Share on other sites More sharing options...
Тролль Posted October 19, 2008 Report Share Posted October 19, 2008 "И летят кошмарики на воздушном шарике..." :) #include <iostream>#include <time.h> using namespace std;const int n = 4;int a[n][n];void print(){for(int i=0;i<n;i++){for(int j=0;j<n;j++){cout.width(j%2?4:7);cout<<a[i][j];}if(i%2)cout<<endl<<endl;cout<<endl;}cout<<endl<<endl;}void change(int ia,int ja,int ib,int jb){for(int i=0;i<n/2;i++)for(int j=0;j<n/2;j++){int k=a[i+ia][j+ja];a[i+ia][j+ja]=a[i+ib][j+jb];a[i+ib][j+jb]=k;}}int main(){srand(time(NULL)); for(int i=0;i<n;i++)for(int j=0;j<n;j++)a[i][j]=rand()%100;print(); change(0,0,0,2); change(2,0,2,2); change(0,0,2,2); print(); getchar(); return 0;} Link to comment Share on other sites More sharing options...
olyska20 Posted October 20, 2008 Author Report Share Posted October 20, 2008 пасибо тебе огромное Link to comment Share on other sites More sharing options...
olyska20 Posted October 21, 2008 Author Report Share Posted October 21, 2008 ПОМОГИТЕ ПЛИЗ ДАЛИ ЗАДАЧУ COPLFNM ДВЕ СТРУКТУРЫ КОТОРЫЕ СОДЕРЖАТ ПО ОДНОМУ МАССИВУ ТИПА ИНТЭДЖЕР И НАДО ПРОИЗВЕСТИ ПОЧЛЕННОЕ СЛОЖЕНИЕ И ВЫЧИТАНИЕ ЭЛЕМЕНТОВ МАССИВА И ВЫВЕСТИ НА ЭКРАН РЕЗУЛЬТАТ ИСПОЛЬЗУЯ ПЕРЕГРУЗКУ+ И _ ПОДСКАЖИТЕ ПЛИЗ ЗАРАНЕЕ ОГРОМНОЕ СПАСИБО ! Предупреждение:У вас проблемы с Caps Lock? Не надо кричать. Q-Q Link to comment Share on other sites More sharing options...
olyska20 Posted October 21, 2008 Author Report Share Posted October 21, 2008 и ещё одна в olyjq структуре два массива над перегрузить операцию + и - и произвести почленное сложение и вычитание элементов массивов и вывести результат пусть будет 5 элементов м массиве два массива типа инт пасибо я написалано не могу почленно сложить ((( Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now