Написать программу в Paskal. Догонит ли второй автомобиль первый за Н часов, если они выехали из одной и той же точки, но второй через n часов после выезда первого?
Возможный вариант в C++ #include <iostream> int main() { using namespace std; int N; cout << "Enter N: "; cin >> N; int num; int max = 1; int i; for (i = 0; i < N; ++i) { cout << "Enter #" << i + 1 << " number: "; cin >> num; if ((num - 9) % 10 != 0 && num % 3 == 0) { max = num; break; } } for (int j = i + 1; j < N; ++j) { cout << "Enter #" << j + 1 << " number: "; cin >> num; if ((num - 9) % 10 != 0 && num % 3 == 0) if (num > max) max = num; } if (max != 1) cout << "Max number div by 3 and don't end 9: " << max << endl; else cout << "No numbers div by 3 and don't end 9" << endl; return 0; }
#include <iostream>
int main()
{
using namespace std;
int N;
cout << "Enter N: ";
cin >> N;
int num;
int max = 1;
int i;
for (i = 0; i < N; ++i)
{
cout << "Enter #" << i + 1 << " number: ";
cin >> num;
if ((num - 9) % 10 != 0 && num % 3 == 0)
{
max = num;
break;
}
}
for (int j = i + 1; j < N; ++j)
{
cout << "Enter #" << j + 1 << " number: ";
cin >> num;
if ((num - 9) % 10 != 0 && num % 3 == 0)
if (num > max)
max = num;
}
if (max != 1)
cout << "Max number div by 3 and don't end 9: " << max << endl;
else
cout << "No numbers div by 3 and don't end 9" << endl;
return 0;
}
Відповідь:
#include <iostream>
using namespace std;
int main(){
setlocale(LC_ALL , "Rus");
int a,b,x,y;
cout << "Введите первое число: ";
cin >> a;
cout << "Введите второе число: ";
cin >> b;
if(a % b == 0){
cout << "Делится" << endl;
x = a / b;
cout << "Частное: " << x << endl;
}
else if(a % b != 0){
cout << "Не делится" << endl;
x = a / b;
y = a % b;
cout << "Частное: " << x << " Остаток: " << y << endl;
}
return 0;
}