Другие языки программирования и технологии
хелп! нужна прога на C
Если сумма трех попарно различных чисел x, y, z меньше 10, то наименьшее из этих трех чисел заменить полусуммой двух других, в противном случае заменить меньшее из x и y полусуммой двух оставшихся значений.
чисто интуитивно что то в этом роде
if(x+y+z<10){
if(x<=y&&x<=z){x=(y+z)/2;}
if(y<=x&&y<=z){y=(x+z)/2;}
if(z<=x&&z<=y){z=(x+y)/2;}
}
else{
if(x-y<0){x=(y+z)/2;}
else{y=(x+z)/2;)}
}
if(x+y+z<10){
if(x<=y&&x<=z){x=(y+z)/2;}
if(y<=x&&y<=z){y=(x+z)/2;}
if(z<=x&&z<=y){z=(x+y)/2;}
}
else{
if(x-y<0){x=(y+z)/2;}
else{y=(x+z)/2;)}
}
Как грицца, to fail even harder...
Вот полный рабочий листинг:
#include <stdio.h>
#include <stdlib.h>
struct list {
struct list * next;
long long some_data;
} ;
struct list * head = NULL;
void insert_node(struct list * node) {
struct list * i;
if (head == NULL) {
head = node; node -> next = NULL;
}
else {
for (i=head; i->next!=NULL; i=i->next) ;
i->next = node; node -> next = NULL;
}
}
int get_3_nodes() {
int val, i;
struct list * node;
for (i=1; i<=3; i++) {
node = malloc(sizeof(struct list));
if (node == NULL)
exit(91);
scanf("%d", &val);
node -> some_data = val;
insert_node(node);
}
}
void print_vector() {
struct list * i;
for (i=head; i!=NULL; i=i->next) printf("%d ", i->some_data);
puts("");
}
short check_sum() {
struct list * i;
long long sum = 0;
for (i=head; i!=NULL; i=i->next) sum += i->some_data;
return (short) sum;
}
struct list * get_min() {
struct list * i, * min = head;
for (i=head; i!=NULL; i=i->next) if (i->some_data < min->some_data) min=i;
return min;
}
void get_sum(struct list * node, long long some_val) {
struct list * i; some_val = 0;
for (i=head; i!=NULL; i=i->next)
if (i!=node) {
some_val += i->some_data;
}
some_val/=2;
node->some_data = some_val;
}
int main() {
struct list * a;
get_3_nodes();
if ( (int)check_sum() < 0xA ) {a=get_min(); get_sum( a, a->some_data );}
else if ( head->some_data < (head->next)->some_data ) get_sum(head, head->some_data);
else get_sum(head->next, (head->next)->some_data);
print_vector();
fflush(stdout);
return -238;
}
Вот полный рабочий листинг:
#include <stdio.h>
#include <stdlib.h>
struct list {
struct list * next;
long long some_data;
} ;
struct list * head = NULL;
void insert_node(struct list * node) {
struct list * i;
if (head == NULL) {
head = node; node -> next = NULL;
}
else {
for (i=head; i->next!=NULL; i=i->next) ;
i->next = node; node -> next = NULL;
}
}
int get_3_nodes() {
int val, i;
struct list * node;
for (i=1; i<=3; i++) {
node = malloc(sizeof(struct list));
if (node == NULL)
exit(91);
scanf("%d", &val);
node -> some_data = val;
insert_node(node);
}
}
void print_vector() {
struct list * i;
for (i=head; i!=NULL; i=i->next) printf("%d ", i->some_data);
puts("");
}
short check_sum() {
struct list * i;
long long sum = 0;
for (i=head; i!=NULL; i=i->next) sum += i->some_data;
return (short) sum;
}
struct list * get_min() {
struct list * i, * min = head;
for (i=head; i!=NULL; i=i->next) if (i->some_data < min->some_data) min=i;
return min;
}
void get_sum(struct list * node, long long some_val) {
struct list * i; some_val = 0;
for (i=head; i!=NULL; i=i->next)
if (i!=node) {
some_val += i->some_data;
}
some_val/=2;
node->some_data = some_val;
}
int main() {
struct list * a;
get_3_nodes();
if ( (int)check_sum() < 0xA ) {a=get_min(); get_sum( a, a->some_data );}
else if ( head->some_data < (head->next)->some_data ) get_sum(head, head->some_data);
else get_sum(head->next, (head->next)->some_data);
print_vector();
fflush(stdout);
return -238;
}
Похожие вопросы
- не очень сложная прога на c++ не робит: Написать функцию, сравнивающую площадь двух треугольников, по координатам их вер
- НОК 2-ух чисел - C++ Помогите, люди добрые. Как написать прогу на C++, которая вычисляет НОК двух чисел
- Нужна прога для создания скриншотов с видео файлов (+)
- Народ нужна прога для скрытия IP адреса.
- Для чего нужен return в C++ ?например return 0;
- кто может сделать прогу в C++ которая поменяет местами в каждом столбце минимальный и максимальные элементы в матрице??
- Зачем нужен конструктор в c#?
- Зачем нужны указатели в c++? начал изучать язык C++ и не очень понимаю зачем нужны указатели?
- Помогите пж написать прогу на c++ макс простым языком. Расположить символы в обратном порядке в одномерном массиве
- Нужна помощь в C++