0
My code for extra-terrestrial is not working
#include <stdio.h> #include <string.h> #include <stdlib.h> int main() { char arr[10]; char *ptr; ptr = (char*) malloc(10* sizeof(char)); for(int i=0; i<10; i++) { scanf("%c", &arr[i]); } for(int j =10-1; j>=0; j--) { printf ("%c", arr[j]); } return 0; }
5 Answers
+ 1
In case of a string of length less than the length 10, the program will display a lot of useless characters (NULL to be precise) before the actual string leading to wrong answer.
Simple fix is to start iterating from the length of the string instead of traversing entire array backwards.
Also your program will fail on any input larger than the length 10
+ 4
FYI, 35 is the minimum size of array you'll need in order to pass this code coach. Anything less will result in an error for at least 1 or more of the tests.
+ 1
Arsenic what thread I didn't get it
0
Arsenic: Could you please take a look at this code of mine also not running for Halloween-candy
#include <stdio.h>
int main() {
int houses;
scanf("%d", &houses);
//your code goes here
int p = 100/houses;
int z = 100%houses;
int c = p*2;
if(houses > 3 && z == 0) {
printf ("%d",c);
}
else {
printf ("%d",c+1);
}
return 0;
}
0
Vishal it is preferred to keep one thread for one question only.
Either DM me the query or better create another question thread regarding the same.
edit:
by thread, I mean a new question thread or question post (whatever you like to call it )