| Task: | Kolikot |
| Sender: | Aapeli |
| Submission time: | 2018-10-12 18:37:25 +0300 |
| Language: | C++ |
| Status: | COMPILE ERROR |
Compiler report
input/code.cpp: In function 'int main()':
input/code.cpp:15:21: error: invalid conversion from 'void*' to 'int*' [-fpermissive]
int* list=malloc(sizeof(int));
~~~~~~^~~~~~~~~~~~~
input/code.cpp:21:21: error: invalid conversion from 'void*' to 'int*' [-fpermissive]
list=realloc(list, sizeof(int)*pile);
~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
input/code.cpp:14:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%i",&number);
~~~~~^~~~~~~~~~~~~~Code
//
// main.c
// datatahti
//
// Created by aapo haavisto on 10/11/18.
// Copyright © 2018 Aapo Haavisto. All rights reserved.
//
#include <stdio.h>
#include <stdlib.h>
int main(void) {
int number;
scanf("%i",&number);
int* list=malloc(sizeof(int));
int again=1;
int pile=0;
int maara=0;
while (again) {
pile++;
list=realloc(list, sizeof(int)*pile);
if (number>=pile) {
number-=pile;
list[pile-1]=pile;
maara++;
}
else{
list[pile-2]+=number;
again=0;
}
}
printf("%i\n", maara);
for (int i=0; i<maara; i++) {
printf("%i ",list[i]);
}
free(list);
}
