Вопрос задан 16.06.2023 в 01:01. Предмет Информатика. Спрашивает Сараева Ольга.

Программа запрашивает натуральные числа и находит кратные 3, заканчивающихся на 1. Помогите

пожалуйста!!!
0 0
Перейти к ответам

Ответы на вопрос

Внимание! Ответы на вопросы дают живые люди. Они могут содержать ошибочную информацию, заблуждения, а также ответы могут быть сгенерированы нейросетями. Будьте внимательны. Если вы уверены, что ответ неверный, нажмите кнопку "Пожаловаться" под ответом.
Отвечает Искакова Маржан.

Відповідь:

#include <iostream>

using namespace std;

int main(){

setlocale(LC_ALL, "Rus");

int number,x;

cout << "Введите число: ";

cin >> number;

x = number % 10;

if(x == 1){

 if(number % 3 == 0){

  cout << "Кратное" << endl;

 }

 else{

  cout << "Не кратное" << endl;

 }

}

else{

 cout << "Не кончаеться на 1" << endl;

}

return 0;        

}

0 0
Отвечает нейросеть ChatGpt. Будьте внимательны, ответы нейросети могут содержать ошибочные или выдуманные данные.

Finding Multiples of 3 Ending in 1 in C++

To find natural numbers that are multiples of 3 and end with 1, you can use a simple C++ program with a while loop to iterate through the numbers and check for the given conditions.

Here's a basic outline of how you can achieve this:

1. Initialize Variables: Start by initializing variables for the loop and the number to be checked. 2. Use a While Loop: Create a while loop to iterate through the natural numbers and check for the conditions. 3. Check for Multiples of 3 Ending in 1: Within the loop, check if the current number is a multiple of 3 and ends with 1. If it meets both conditions, print the number.

Here's a sample C++ code that demonstrates this:

```cpp #include

int main() { int number = 1; // Start with the first natural number while (number < 100) { // Assuming we want to find such numbers below 100 if (number % 3 == 0 && number % 10 == 1) { // Check if the number is a multiple of 3 and ends with 1 std::cout << number << " "; // Print the number } number++; // Move to the next number } std::cout << "done!" << std::endl; // Indicate the end of the program return 0; } ```

This code initializes a variable `number` to 1 and then uses a while loop to iterate through the numbers from 1 to 100. Within the loop, it checks if the number is a multiple of 3 and ends with 1. If it meets both conditions, it prints the number.

Feel free to modify the range or conditions based on your specific requirements.

I hope this helps! If you have any further questions or need additional assistance, feel free to ask!

0 0

Похожие вопросы

Топ вопросов за вчера в категории Информатика

Последние заданные вопросы в категории Информатика

Задать вопрос