Beispiel #1
0
void arrayTests()
{
    int arr[16];
    int arr1[16];
    int res[16];
    time_t t;
    int size = sizeof(arr)/sizeof(arr[0]);
    srand((unsigned) time(&t));
    fillRand3(arr, size);
    srand((unsigned) time(&t) + 1);
    fillRand3(arr1, size);
    printf("Array 1 was filled %scorrecly :\n", checkRand3(arr, size) ? "" : "in");
    printArr(arr, size);
    printf("Array 2 was filled %scorrecly :\n", checkRand3(arr1, size) ? "" : "in");
    printArr(arr1, size);
    printf("Array 1:\n");
    printf("Max value is %i\nIts index is %i\n", max(arr, size), maxIndex(arr, size));
    printf("Mean value is %f\nThe closest number is at the index %i\n", meanValue(arr, size), meanIndex(arr, size));
    printf("Number %i was find maximum times in our array\n", maxOccurance(arr, size));
    printf("\nArray 2:\n");
    printf("Max value is %i\nIts index is %i\n", max(arr1, size), maxIndex(arr1, size));
    printf("Mean value is %f\nThe closest number is at the index %i\n", meanValue(arr1, size), meanIndex(arr1, size));
    printf("Number %i was find maximum times in our array\n", maxOccurance(arr1, size));
    printf("\nArrays 1 and 2 are %s equal\n", diff(arr, arr1, res, size) ? "" : "not");
    printf("The result if adding Array 1 and Array 2 is :\n");
    add(arr, arr1, res, size);
    printArr(res, size);
    printf("Corresponding elements of Array 1 and Array 2 are %s less or equal\n", lteq(arr, arr1, size) ? "" : "not");
    printf("The result of logical OR to corresponding elements of Array 1 and Array 2:\n");
    lor(arr, arr1, res,size);
    printArr(res, size);
}
Beispiel #2
0
int main(void) {
	srand(time(NULL));
	int arr[12];
	int arr2[12];
	int res[12];
	int size = 12;
	int i;
	int check;
	fillRand3(arr, 12);
	for (i = 0; i < 12; i++) {
		printf("%d ", arr[i]);
	}
	puts("- First randomly generated array\n");
	check = checkRand3(arr, size);
	printf("%d", check);
	puts(" - Is is really consist of only [0..1]\n");
	printf("%.10f", meanValue(arr, size));
	puts(" - Average value of the array\n");
	check = maxValue(arr, size);
	printf("%d", check);
	puts(" - Maximal element of the array\n");
	check = meanIndex(arr, size);
	printf("%d", check);
	puts(" - Index of the first element most close to the average value\n");
	check = maxIndex(arr, size);
	printf("%d", check);
	puts(" - Index of the first maximal number\n");
	check = maxOccurance(arr, size);
	printf("%d", check);
	puts(" - The most occurable element of the array\n");
	fillRand3(arr2, size);
	for (i = 0; i < 12; i++) {
		printf("%d ", arr2[i]);
	}
	puts("- Second randomly generated array\n");
	check = diff(arr, arr2, res, size);
	printf("%d", check);
	puts(" - Is it different from the first one or not\n");
	sub(arr, arr2, res, size);
	for (i = 0; i < 12; i++) {
		printf("%d ", res[i]);
	}
	puts("- Result array consisting of arr[i]-arr2[i]\n");
	check = eq(arr, arr2, size);
	printf("%d", check);
	puts(" - Whether arrays are equal or not\n");
	lor(arr, arr2, res, size);
	for (i = 0; i < 12; i++) {
		printf("%d ", res[i]);
	}
	puts("- Result array consisting of arr[i]||arr2[i]\n");
	return 0;
}
Beispiel #3
0
int main(){
    int size = 6;
    int arr[size];
    int arr1[6]={1,2,3,4,5,6};
    int arr2[6]={-11,-12,-13,-14,-15,-16};
    int res[6];
    int i;
    fillRand3(arr, size);

    for (i = 0; i < size; i++)
        printf("%d\t", arr[i]);
    printf("\nrez = %d\n",checkRand3(arr, size));
    printf("sred = %.3f\n",meanValue(arr, size));
    printf("min = %d\n", minValue(arr, size));
    printf("index= %i\n", meanIndex(arr, size));
    printf("index = %d\n", minIndex(arr, size));
    printf("elem = %d\n", maxOccurance(arr, size));
    printf("res = %d\n", diff(arr1, arr2, res, size));
    sub(arr1, arr2, res, size);
    for (i=0;i<size;i++)
        printf("%d\t", res[i]);
    printf("\neq= %d\n", eq(arr1, arr2, size));
    land(arr1, arr2, res, size);
    for (i=0;i<size;i++)
        printf("%d\t", res[i]);
    return 0;
}