Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <math.h>
- using namespace std;
- #include "Rus.h"
- int zap_mas (int *mas, int n, int max, int min);
- void vivod_mas (int *mas, int n);
- int sum(int n, int M, int *mas);
- int zap_mas (int *mas, int n, int max, int min)
- {
- int i;
- for (i=0;i<n;i++)
- {
- mas[i]=rand()%(max-min+1)+min;
- }
- return mas[i];
- }
- void vivod_mas (int *mas, int n)
- {
- int i;
- for (i=0; i<n; i++)
- cout<<mas[i]<<"\t";
- cout<<endl;
- }
- int sum(int n, int M, int *mas)
- {
- int x,c1,c2,c3,c,i;
- for (i=0; i<n; i++)
- {
- x=abs(mas[i]);
- c1=x/100;
- c2=x/10;
- c2=c2%10;
- c3=x%10;
- c=c1+c2+c3;
- if (c==M)
- return 1;
- }
- return -1;
- }
- void main ()
- {
- int *mas, n, M,i;
- srand(NULL);
- cout<<Rus("Введите размерность массива и число М \n");
- cin>>n>>M;
- mas= new int [n];
- zap_mas ( mas, n, 1000, -1000);
- vivod_mas ( mas, n);
- i=sum ( n, M, mas);
- cout<<Rus("Индекс элемента =")<<i;
- delete[] mas;
- mas=0;
- }
Add Comment
Please, Sign In to add comment