Esempio n. 1
0
int main(void) {
    char str[MAXLINE], *token;

    /* read input lines */
    while (fgets(str, MAXLINE, stdin) != NULL) {

        int *arr = NULL, len, pos = 0;
        bool start = true;

        /* tokenize input line and parse each token */
        for (token = strtok(str, DELIMITERS);
             token != NULL;
             token = strtok(NULL, DELIMITERS))
        {
            /* first token is the array length */
            if (start) {
                len = atoi(token);
                start = false;

                /* allocate mem for arr */
                arr = (int *)malloc(len * sizeof(int));
                if (arr == NULL) { printf("malloc failure!"); exit(-1); }
            }
            /* remaining elements are arr members */
            else { arr[pos++] = atoi(token); }
        }

        // printArr(arr, len);
        productArray(arr, len);
        printf("\n");

        /* cleanup */
        if (arr) { free(arr); arr = NULL; }
    }
}
int main(){
  int arr[] = {10, 3, 5, 6, 2};
  int n = sizeof(arr)/sizeof(arr[0]);
  printf("The product array is: \n");
  productArray(arr, n);
  getchar();
}
Esempio n. 3
0
int main()
{
  int arr[] = {56,90,89,76};
  int num = sizeof(arr)/sizeof(arr[0]);
  printf("The product array is: \n");
  productArray(arr, num);
  getchar();
}
Esempio n. 4
0
int main()
{
	int *op;
	int j,i;
	for(i=0;i<10;i++)
	{
		op=productArray(testDB[i].input,testDB[i].length);
		if(isCheck(op,i))
			printf("valid\n");
		else
			printf("Invalid\n");
		free(op);
	}
	return 0;
}