- Data types, variables and constants
- Ввод с клавиатуры и вывод данных на экран
- Арифметические операции и комбинированные операторы
- Операторы выбора if и else в С
- The switch statement in C ++
- The for loop in C++
- Циклы while, do while, nested loops
- Two-dimensional arrays C ++
- Arrays in C++
- Functions in C++
- Pointers C ++
- A pointer to a pointer to C ++
- Classes in C ++
Additional collection of problems with solutions
This page contains all of the tasks on the topics lessons, posted on our website. К каждой задаче прилагается наш вариант решения. Постарайтесь всё же решать их самостоятельно и только потом сравнивать наш исходный код со своим. “Хочешь научиться программировать – программируй”!
Больше практических заданий с решениями найдёте here.
Рекомендуем посетить Сайт для юных программистов – где вы найдете уроки по различным языкам программирования (в том числе для детей), 3D-моделированию, Linux и др.
Hello,I need help writing code in C for the C8051F38 microcontroller with LCD screen ,you need to connect a 7-segment display to the microcontroller(common anode) via button,when turned on, the display and screen should display 0, when you press the button, it should count forward to 9 with a delay of 500ms,when the button is released, the display saves the last number shown ,with the next clamping, the countdown continues from the place where it stopped and so on in a circle,the countdown should be displayed in parallel on the LCD screen with the inscription Status:running in green when the countdown is in progress,and State :stop red when it stops,I tried,but it doesn't work
#include
#include
#include
#define BUTTON_PIN PB0
#define SEGMENT_A_PIN PD0
#define SEGMENT_B_PIN PD1
#define SEGMENT_C_PIN PD2
#define SEGMENT_D_PIN PD3
#define SEGMENT_E_PIN PD4
#define SEGMENT_F_PIN PD5
#define SEGMENT_G_PIN PD6
#define SEGMENT_PORT PORTD
#define SEGMENT_DDR DDRD
#define BUTTON_PORT PORTB
#define BUTTON_DDR DDRB
// Symbol table for 7-segment indicator (common anode)
const unsigned char SEGMENT_DIGITS[] = {
0b00001000, // 0
0b00111110, // 1
0b00100100, // 2
0b00011100, // 3
0b01001110, // 4
0b01100100, // 5
0b01111000, // 6
0b00000110, // 7
0b01111110, // 8
0b01101100, // 9
};
// Variables
volatile uint8_t current_digit = 0;
volatile uint8_t button_state_prev = 1; // Initialization how “released” to avoid false clicks
void display_digit(uint8_t digit) {
SEGMENT_PORT = ~SEGMENT_DIGITS[digit]; // Invert values for common anode
}
void update_display() {
display_digit(status == 0 ? 0 : current_digit);
}
void handle_button_press() {
if (status == 0) {
status = 1;
current_digit = 0;
} else {
current_digit = (current_digit + 1) % 16;
}
update_display();
}
void handle_button_release() {
if (status == 1) {
status = 0;
}
}
void setup() {
// Configuring a button as a pull-up resistor input
BUTTON_DDR &= ~(1 << BUTTON_PIN);
BUTTON_PORT |= (1 << BUTTON_PIN);
// Configuring Segment Pins as Outputs
SEGMENT_DDR |= (1 << SEGMENT_A_PIN) |
(1 << SEGMENT_B_PIN) |
(1 << SEGMENT_C_PIN) |
(1 << SEGMENT_D_PIN) |
(1 << SEGMENT_E_PIN) |
(1 << SEGMENT_F_PIN) |
(1 << SEGMENT_G_PIN);
}
void loop() {
// Reading button state with edge detection (volatile to update the flag)
volatile uint8_t button_state = PINB & (1 << BUTTON_PIN);
// Processing a Button Press with Edge Detection
if (!button_state && button_state_prev) {
handle_button_press();
}
// Button release processing with edge detection
if (button_state && !button_state_prev) {
handle_button_release();
}
// Update display
update_display();
// Delay 500 ms (replace with the appropriate delay function)
_delay_ms(500);
// Updating a button's previous state
button_state_prev = button_state;
}
int main() {
setup();
loop();
return 0;
}
help me please, in a week I have an exam in C++, I also broke my finger, what should I do? 1 star quickly help me bitch creatures
How was your exam?
A natural number n is given (n <=100), integer k (k =+-1) and a sequence of integers a1, a2, …, an. Carry out a cyclic shift of the elements of the sequence on 1 position to the right (with k =1) or to the left (at
k = −1)
cpp
#include
class Matrix
{
public:
void setData()
{
if (arrBase != nullptr)
{
clearMatrix();
}
std::cin >> rows >> cols;
arrBase = new int* [rows];
for (int i = 0; i < rows; i++)
{
arrBase[i] = new int[cols];
}
int data;
for (int i = 0; i < rows; i++)
{
for (int j = 0; j > data;
arrBase[i][j] = data;
}
}
arrInverted = new int* [cols];
for (int i = 0; i < cols; i++)
{
arrInverted[i] = new int[rows];
}
for (int i = 0; i < cols; i++)
{
for (int j = 0; j < rows; j++)
{
arrInverted[i][j] = arrBase[j][i];
}
}
}
void getData()
{
std::cout << " ~ ~ ~ arrBase ~ ~ ~ " << std::endl;
for (int i = 0; i < rows; i++)
{
for (int j = 0; j < cols; j++)
{
std::cout << arrBase[i][j] << "\t";
}
std::cout << std::endl;
}
std::cout << std::endl;
std::cout << " ~ ~ ~ arrInverted ~ ~ ~ " << std::endl;
for (int i = 0; i < cols; i++)
{
for (int j = 0; j < rows; j++)
{
std::cout << arrInverted[i][j] << "\t";
}
std::cout << std::endl;
}
std::cout << std::endl;
}
private:
void clearMatrix()
{
for (int i = 0; i < rows; i++)
{
delete[] arrBase[i];
}
delete[] arrBase;
arrBase = nullptr;
for (int i = 0; i < cols; i++)
{
delete[] arrInverted[i];
}
delete arrInverted;
arrInverted = nullptr;
}
int** arrBase = nullptr;
int** arrInverted = nullptr;
size_t rows;
size_t cols;
};
int main()
{
Matrix m;
m.setData();
m.setData();
m.setData();
m.getData();
return 0;
}