// PascalABC.NET
begin
// 1
var s11 := SeqRandom(100, 10, 99).Sum;
var s12 := ArrRandom(100, 10, 99).Sum;
case Sign(s11 - s12) of
-1: Println('Сумма второго массива больше');
0: Println('Суммы равны');
else
Println('Сумма первого массива больше')
end;
// 2
var s21 := SeqRandom(1000, -9, 9).Sum;
var s22 := ArrRandom(1000, -9, 9).Sum;
var s23 := ArrRandom(1000, -9, 9).Sum;
if s21 > s22 then
Swap(s21, s22);
if s22 > s23 then
begin
Swap(s22, s23);
if s21 > s22 then
Swap(s21, s22)
end;
Println(s21, s22, s23);
// 3
var a := ArrRandom(50, -99, 99);
a.Println;
var s31 := a.Where(p -> p > 30);
Print('Количество', s31.Count, ' сумма', s31.Sum)
end.
#include <iostream>
using namespace std;
int main()
{
int *arr;
int size;
cout << "size = ";
cin >> size;
if (size <= 0) {
cerr << "Invalid size" << endl;
return 1;
}
arr = new int[size];
for (int i = 0; i < size; i++) {
cout << "arr[" << i << "] = ";
cin >> arr[i];
}
int temp;
for (int i = 0; i < size - 1; i++) {
for (int j = 0; j < size - i - 1; j++) {
if (arr[j] > arr[j + 1]) {
temp = arr[j];
arr[j] = arr[j + 1];
arr[j + 1] = temp;
}
}
}
for (int i = 0; i < size; i++) {
cout << arr[i] << " ";
}
cout << endl;
delete [] arr;
return 0;
}
Поделитесь своими знаниями, ответьте на вопрос:
#include <iostream>
#include <cstdlib>
#include <cstring>
using namespace std;
string dig(int n)
{
string st="";
if (n>9) { st=st+char(n%10+48); st=char(n/10+48)+st; }
else st=st+'0'+char(n+48);
return(st);
}
int main(int argc, char** argv) {
int n,k,m,sc;
string s="";
cout<<"n = "; cin>>n; cout<<endl;
k=n/3600;
m=(n-k*3600)/60;
sc=n-k*3600-m*60;
if (k>24) k=k%24;
if (k<10) s=s+char(k+48)+':';
else s=s+dig(k)+':';
s=s+dig(m)+':';
s=s+dig(sc);
cout<<"time: "<<s<<endl;
system("pause");
return(0);
}