//Pascal
//Для натуральных чисел
var a, s, p:integer;
begin
write('Введите число = ');
readln(a);
s := 0;
p := 1;
while (a<>0) do
begin
p := p * (a mod 10);
s := s + (a mod 10);
a := a div 10;
end;
writeln( 'Сумма цифр числа = ', s);
writeln( 'Произведение цифр числа = ', p);
end.
//Если число отрицательное
var
s, p, a, b, c: integer;
f: boolean;
begin
write('Введите число = ');
readln(a);
if a < 0 then
f := true;
a := abs(a);
b := a mod 10;
a := a div 10;
c := a mod 10;
a := a div 10;
if f = true then
begin
p := (-a) * b * c;
s := -a + b + c;
end
else
begin
s := a + b + c;
p := a * b * c;
end;
writeln('Сумма цифр числа = ', s);
writeln('Произведение цифр числа = ', p);
end.
#include <iostream>
#include <cstdlib>
#include <ctime>
int main()
{
using namespace std;
cout << "Enter size of array: ";
int N;
cin >> N;
int * ARR = new int[N];
srand(time(0));
int i;
for (i = 0; i < N; ++i)
ARR[i] = rand() % 100 + 1;
cout << "Here is an original array:\n";
for (i = 0; i < N; ++i)
cout << ARR[i] << " ";
cout << endl;
int temp = ARR[N - 1];
for (i = N - 1; i > 0; --i)
ARR[i] = ARR[i - 1];
ARR[0] = temp;
cout << "\nHere is a new array:\n";
for (i = 0; i < N; ++i)
cout << ARR[i] << " ";
cout << endl;
return 0;
}