0 Members and 1 Guest are viewing this topic.
I recommend storing in decimal because he's going to have to output the values in human-readable format. I assume he won't want to make a routine to extract decimal digits from a large binary number.
int arraysize;char *array;char *output;int j = 0;For(i,i<arraysize,i++) {stream = *array[i];if stream>0x0A {*array[j] = 0x31;j = j+1;stream = stream % 10;}*array[j] = stream + 0x30;j = j+1;}
Quote from: calc84maniac on June 17, 2011, 12:43:52 amI recommend storing in decimal because he's going to have to output the values in human-readable format. I assume he won't want to make a routine to extract decimal digits from a large binary number.It's not terribly difficult to convert to decimal, but yeah.Example psuedo-code for Hex array->Dec:Code: [Select]int arraysize;char *array;char *output;int j = 0;For(i,i<arraysize,i++) {stream = *array[i];if stream>0x0A {*array[j] = 0x31;j = j+1;stream = stream % 10;}*array[j] = stream + 0x30;j = j+1;}
#include <stdio.h>int main();double factorial(int n);int main() { int n; scanf("%d",&n); int i; for (i=0;i<n;i++) { int x; scanf("%d",&x); printf("%f\n",factorial(x)); } return 0;}double factorial(int n){ if (n==0) { return 1; } double sum = 1; int i; for (i=n;i>0;i--) { sum = sum*i; } return sum;}
Well, you're not declaring x to be anything but null, so..
#include <stdio.h>int main();double factorial(double n);int main() { int n; scanf("%d",&n); int i; for (i=0;i<n;i++) { double x; scanf("%lf",&x); printf("%lf\n",factorial(x)); } return 0;}double factorial(double n){ if (n==0) { return 1; } double sum = 1; int i; for (i=n;i>0;i--) { sum = sum*i; } return sum;}
He means you are not initializing X with a value, you are just going int X or double X, which creates the variable, but it holds no value.
double x;scanf("%lf",&x);
#include <stdio.h>int main();double factorial(double n);int main() { int n; scanf("%d",&n); int i; for (i=0;i<n;i++) { double x; scanf("%lf",&x); printf("%lf\n",factorial(x)); } return 0;}double factorial(double n){ if ((n == 1) || (n == 0)) { return(1); } else { return(n * factorial(n - 1)); }}