int main(){

	/*
	 * TEST 1
	 * Mid-Pt is missing
	 */
	{
		int myInts[] = {2,4,8,10,12,14};
		std::vector<int>arr1(myInts, myInts + sizeof(myInts) / sizeof(int) );
		printArray2(arr1,arr1.size());
		std::cout<<"Missing Elements in AP is: "<<findMissingElementAPExt(arr1,0,arr1.size())<<std::endl;
	}
	/*
	 * TEST 2
	 * Missing element is on left
	 */
	{
		int myInts[] = {2,6,8,10,12,14};
		std::vector<int>arr1(myInts, myInts + sizeof(myInts) / sizeof(int) );
		printArray2(arr1,arr1.size());
		std::cout<<"Missing Elements in AP is: "<<findMissingElementAPExt(arr1,0,arr1.size())<<std::endl;
	}
	/*
	 * TEST 3
	 * Missing element is on right
	 */
	{
		int myInts[] = {1,6,11,16,21,31};
		std::vector<int>arr1(myInts, myInts + sizeof(myInts) / sizeof(int) );
		printArray2(arr1,arr1.size());
		std::cout<<"Missing Elements in AP is: "<<findMissingElementAPExt(arr1,0,arr1.size())<<std::endl;
	}
	/*
	 * TEST 4
	 * Missing element is on right
	 */
	{
		int myInts[] = {1,6,16};
		std::vector<int>arr1(myInts, myInts + sizeof(myInts) / sizeof(int) );
		printArray2(arr1,arr1.size());
		std::cout<<"Missing Elements in AP is: "<<findMissingElementAPExt(arr1,0,arr1.size())<<std::endl;
	}
	/*
	 * TEST 5
	 * Everything is good
	 */
	{
		int myInts[] = {1,6,11};
		std::vector<int>arr1(myInts, myInts + sizeof(myInts) / sizeof(int) );
		printArray2(arr1,arr1.size());
		std::cout<<"Missing Elements in AP is: "<<findMissingElementAPExt(arr1,0,arr1.size())<<std::endl;
	}
	return 0;
}
Exemple #2
0
int main()
{
	/* variable declarations */
	int amount, twenties, tens, fives, ones;
	int numbers [MAX], first, second;
	int *ptr;

	srand(time(NULL));

	/* prompt the user to enter a dollar amount as an integer and then read it in*/
	printf("Enter a dollaar amount (an integer): ");
	scanf("%d", &amount);

	/* invoke the function 'payAmount' to calculate the number of bills to return to the user
	pass 'amount' via pass-by-value, and all other variable via pass-by-reference (address)*/
	payAmount(amount, &twenties, &tens, &fives, &ones);

	/* print out the amount of bills */
	printf("\nYour equivalent amount of bills for %d dollars is:\n", amount);
	printf("$20 bills: %d\n", twenties);
	printf("$10 bills: %d\n", tens);
	printf("$5 bills: %d\n", fives);
	printf("$1 bills: %d\n", ones);

	/* just for fun assign the pointer 'ptr' to point to the variable
	'tens' print out its value. Then print out the address to which 'ptr'
	is pointint to and compare it to the address of 'tens'. */
	ptr = &tens;
	printf("Using a pointer, there are %d ten dollar bills\n", *ptr);
	printf("Printing the pointer's address to where it is pointing to %d and where 'tens' is located %d\n", ptr, &tens);

	/* invoke the function 'populateArray' and fill the array with random numbers */
	populateArray(numbers, MAX);

	/* invoke the 'printArray1' function to print out the array eleents in a normal fashion */
	printArray1(numbers, MAX);

	/* invoke the 'printArray2' function to print out the array eleents in a different fashion via pointers */
	printArray2(numbers, MAX);

	/* Randomly select two numbers that will represnet two subscripts for the array 'numbers' */
	first = rand() % MAX;
	second = rand() % MAX;

	/* invoke the funciton 'updateTwoElements' to modify the elements at position
	'first' and 'second' of array 'numbers' */
	updateTwoElements(numbers, first, second);

	/* print out the two elements of the array 'numbers' that were modified */
	printf("\nBack in function main\n");
	printf("Element %d is now %d\n", first, numbers[first]);
	printf("Element %d is now %d\n", second, numbers[second]);

	printf("\n\nThis program was written by Harry Staley");
	printf("\nEnd of program.\n");

    return 0; /* end program normally */
}/* end function Main*/
int main(void)
{
	int a[3][4] = {{1, 3, 5, 7}, {2, 4, 6, 8}, {11, 13, 15, 17}};

	printArray(a[0], 3, 4);
	printArray2(a, 3);

	return 0;

}
Exemple #4
0
int main(int argc, char **argv){
	int array[ARRAY_SIZE];

	int value = 1;
	int i = 0;
	int count = 0;

	printf("<SELECTION SORT>\n\n");
	do{
		printf("Insira um numero (0 para terminar):");
		scanf("%d",&value);
		
		if(value != 0){
				array[count] = value;
				++count;
				printArray2(array, count);
		}
		
	}while(value); //sai caso o valor seja 0
	selectionSort(array,count);	
	printArray2(array, count);

	return 0;
}