Неправильно считает сумму после минимального элемента
#include <windows.h>
#include <iostream>
#include <math.h>
#include <ctime>
using namespace std;
template <class Type> void vvod(Type *a,int n);
template <class Type> void vivod(Type *a,int n);
template<class T> int kolich(T*a,int n);
template <class T> void preobr (T*a,int n);
template <class T> int min1(T*a,int n);
template <class T>int sum1(T*a,int n);
int main(){
SetConsoleOutputCP(1251);
int *b,m, min=0,sum;
srand(time(0));
cout<<"Введите размерность массива:"<<endl;
cin>>m;
b=new int[m];
cout<<"Целочисленный массив:\n";
vvod(b,m);
cout<<"Кол-во нулевых элементов="<<kolich(b,m)<<endl;
cout<<"преобразованный массив:\n";
preobr(b,m);
cout<<"Минимальный элемент:"<<endl;
min1(b,m);
vivod(b,m);
cout<<"Сумма после минимального:"<<endl;
sum1(b,m);
vivod(b,m);
system("pause");
return 0;
}
template <class Type> void vvod(Type *a,int n){
Type x=10,y=20;
for(int i=0;i<n;i++)
a= rand() % y - rand() % x;
vivod(a,n);
}
template <class Type> void vivod(Type *a,int n){
for(int i=0;i<n;i++)
cout<<a<<"\t";
cout<<endl<<endl;
}
template <class T> int kolich(T*a,int n)
{ int i,kolvo=0;
for(i=0;i<n;i++)
if (a==0) kolvo++;
return kolvo;
}
template <class T> void preobr (T*a,int n){
int tmp = a[0];
for ( int j = 0; j < n - 1; j ++ )
for ( int i = j; i < n; i ++ )
if ( fabs(a[j]) > fabs (a) )
{
tmp = a[j];
a[j] = a;
a = tmp;
}
vivod (a,n);
}
template <class T> int min1(T*a,int n){
int min=a[0];
for(int i=0;i<n;i++)
if(a<min)
min=a;
cout<<min<<endl;
return min;
}
template <class T>int sum1(T*a,int n){
int sum,min=a[0];
for(int i=0;i<n;i++)
if(a>min)
{
min=a;
i=n;
}
{
for(int i=n+1;i<n;++i)
sum+=a;
}
cout<<sum<<endl;
return sum;
sum1(a,n);
}
#include <windows.h>
#include <iostream>
#include <math.h>
#include <ctime>
using namespace std;
template <class Type> void vvod(Type *a,int n);
template <class Type> void vivod(Type *a,int n);
template<class T> int kolich(T*a,int n);
template <class T> void preobr (T*a,int n);
template <class T> int min1(T*a,int n);
template <class T>int sum1(T*a,int n);
int main(){
SetConsoleOutputCP(1251);
int *b,m, min=0,sum;
srand(time(0));
cout<<"Введите размерность массива:"<<endl;
cin>>m;
b=new int[m];
cout<<"Целочисленный массив:\n";
vvod(b,m);
cout<<"Кол-во нулевых элементов="<<kolich(b,m)<<endl;
cout<<"преобразованный массив:\n";
preobr(b,m);
cout<<"Минимальный элемент:"<<endl;
min1(b,m);
vivod(b,m);
cout<<"Сумма после минимального:"<<endl;
sum1(b,m);
vivod(b,m);
system("pause");
return 0;
}
template <class Type> void vvod(Type *a,int n){
Type x=10,y=20;
for(int i=0;i<n;i++)
a= rand() % y - rand() % x;
vivod(a,n);
}
template <class Type> void vivod(Type *a,int n){
for(int i=0;i<n;i++)
cout<<a<<"\t";
cout<<endl<<endl;
}
template <class T> int kolich(T*a,int n)
{ int i,kolvo=0;
for(i=0;i<n;i++)
if (a==0) kolvo++;
return kolvo;
}
template <class T> void preobr (T*a,int n){
int tmp = a[0];
for ( int j = 0; j < n - 1; j ++ )
for ( int i = j; i < n; i ++ )
if ( fabs(a[j]) > fabs (a) )
{
tmp = a[j];
a[j] = a;
a = tmp;
}
vivod (a,n);
}
template <class T> int min1(T*a,int n){
int min=a[0];
for(int i=0;i<n;i++)
if(a<min)
min=a;
cout<<min<<endl;
return min;
}
template <class T>int sum1(T*a,int n){
int sum,min=a[0];
for(int i=0;i<n;i++)
if(a>min)
{
min=a;
i=n;
}
{
for(int i=n+1;i<n;++i)
sum+=a;
}
cout<<sum<<endl;
return sum;
sum1(a,n);
}