//Program begin
int main(void)
{
	//Set seed for rand()
	srand(time(NULL));
	//Local Variables
	int userSize; 
	int array[MAX][MAX];

	printf("\n"
			"Enter the size of the array: ");
	scanf("%d", &userSize);
	while(check_error(userSize) != 1)
	{
		printf("Invalid input enter the size of the array again: ");
		scanf("%d", &userSize);
	}
	
	initialize_2Darray(array, userSize);

	printf("\n"
			"Input Array\n");
	print_2Darray(array, userSize);

	printf("\n"
			"The smallest number in the array is %d\n\n", 
			smallest_number(array, userSize));

	return 0;
}
Exemplo n.º 2
0
Arquivo: lab6.c Projeto: sts44b/cs1050
int main()/*begin function main*/
{
   /*vaiables used in the main function*/
   int num;
   int large;
   int row;
   int col;
   int i;
   int x;
   int close;

   printf("\nEnter the size of the 2D  array: ");/*prompt user for the size of the array to be initialized*/
   scanf("%d", &num);

   while (check_error(num) == 0)/*check that a valid size was entered*/
   {
      printf("Invalid input enter the size of the array again: ");
      scanf("%d", &num);
   }

   srand(time(NULL));/*randomize the function reand()*/

   initialize_2Darray(num);/*initialize the 2D array*/

   print_2Darray(num);/*display the 2D array*/

   initialize_1Darray(num);/*initialize the 1D array*/

   print_1Darray(num);/*display the 1D array*/

   printf("\n\nEnter the row: ");/*prompt the user to enter a row number*/
   scanf("%d", &row);

   printf("Enter the col: ");/*prompt the user to enter a column number*/
   scanf("%d", &col);   

   large = search_max(row, col, num);/*find the largest number in the row and column entered by the user*/

   printf("\nThe largest number present in the row %d and col %d is %d\n", row, col, large);/*display the largest value found in the coulumn*/

   for (i = 0; i < num; i++)/*display the diagonal value and how many times it is present in that row and column*/
   {
      x = count_diagonal(i, num);   

      printf("\nDiagonal element %d is present %d more times in the row %d and col %d", array2D[i][i], x, i, i);
   }
  
   close = closest_row(num);/*assign the number of the closest row to the variable closest*/
   
   printf("\n\nRow closest to the array is row %d\n\n", close);/*display the row of the 2D array cloasest to the 1D array*/
}
Exemplo n.º 3
0
int main(void)
{
	//variable declaration//
	int size,student,row,col;
	float scores[COL_SIZE][COL_SIZE];
	srand(time(NULL));
	//size of array input//
	printf("Enter the size of the array:");
	scanf("%d",&size);
	//error checking//
	while(check_error(size)==0)
	{
		printf("Invalid input enter the size of the array again:");
		scanf("%d",&size);
	}
	//print array//
	printf("\nScores:\n");
	initialize_2Darray(scores,size);
	print_2Darray(scores,size);
	printf("\n");
	//average score// 
	average_scores(scores,size);
	//student number input//
	printf("Enter student number (1-%d):",size);
	scanf("%d",&student);
	//Overal grade for specific student// 
	printf("\nOverall grade for %dth student is %c",student,compute_grade(scores,size,student));
	//input row//
	printf("\nEnter the row (1-%d):",size);
        scanf("%d",&row);
	//input column//
	printf("Enter the col (1-%d):",size);
        scanf("%d",&col);
	//the largest number present in specific row and column//
	printf("The largest number present in row %d or col %d is %.2f\n",row,col,search_max(scores,row,col,size));
	printf("Bonus part");
	printf("\nArray before sorting\n");
	print_2Darray(scores,size);	

}	
Exemplo n.º 4
0
//Program Begin
int main(void)
{
	//Seed Random Generator
	srand(time(NULL));

	//Local Variables
	int mainSize, mainOption;
	int userRow, userColumn;
	int countMatchResult;
	int main2Darray[MAX][MAX];
	int main1Darray[MAX];

	//Receive and check user-selected size
	printf("\nEnter the size: ");
	scanf("%d", &mainSize);
	while(check_size(mainSize) == 0)
	{
		printf("Invalid input enter the size of the array again: ");
		scanf("%d", &mainSize);
	}

	do //Perform functions until user selects 6 (exit)
	{
		//Display menu, take and check user option
		display_menu();
		scanf("%d", &mainOption);
		while(check_option(mainOption) == 0)
		{
			printf("Invalid input: Enter the operation you want to perform: ");
			scanf("%d", &mainOption);
		}

		//Perform function based on user choice
		switch(mainOption)
		{
			case 1:
				// Perform Search Min Function
				initialize_2Darray(main2Darray, mainSize);

				//Display Arrays
				printf("\nSearch Min Operation\n\n");
				printf("2D array\n");
				print_2Darray(main2Darray, mainSize);

				//Get user row and column choice
				printf("\nEnter the row: ");
				scanf("%d", &userRow);
				printf("Enter the col: ");
				scanf("%d", &userColumn);

				//Perform function and display result
				printf( "\n\nThe smallest number present in the "
						"row %d and col %d is ", userRow, userColumn);
				printf("%d", search_min(main2Darray, userRow, userColumn, mainSize));

				break;

			case 2:
				// Perform Count Matches Function
				initialize_2Darray(main2Darray, mainSize);
				initialize_1Darray(main1Darray, mainSize);

				//Display initialized arrays
				printf("\nCount Match Operation\n\n");
				printf("2D array\n");
				print_2Darray(main2Darray, mainSize);
				printf("\n1D array\n");
				print_1Darray(main1Darray, mainSize);

				//Get user row choice
				printf("\n\nEnter the row: ");
				scanf("%d", &userRow);

				//Perform function and display result
				countMatchResult = count_match(main2Darray, main1Darray, mainSize, userRow);
				if(countMatchResult == 0)
					printf("\nThere are no numbers from 1D array present in the 2D array");
				else
				{
					printf( "\nThere are %d numbers from the 1D array present in the 2D array",
							countMatchResult);
				}

				break;

			case 3:
				// Perform Closest Row Function
				initialize_2Darray(main2Darray, mainSize);
				initialize_1Darray(main1Darray, mainSize);

				//Display initialized arrays
				printf("\nClosest Row Operation\n\n");
				printf("2D array\n");
				print_2Darray(main2Darray, mainSize);
				printf("\n1D array\n");
				print_1Darray(main1Darray, mainSize);

				//Perform function and display result
				printf( "\n\nRow closest to the 1D array is row %d",
						closest_row(main2Darray, main1Darray, mainSize));
				break;

			case 4:
				// Perform Sort 1D Array Function
				initialize_1Darray(main1Darray, mainSize);

				//Display initialized array
				printf("\nSort 1D Array Operation\n\n");
				printf("1D Array before sorting\n");
				print_1Darray(main1Darray, mainSize);

				//Display sorted array
				printf("\n1D Array after sorting\n");
				sort_1Darray(main1Darray, mainSize);
				print_1Darray(main1Darray, mainSize);

				break;

			case 5:
				// Perform Sort 2D Array Function
				initialize_2Darray(main2Darray, mainSize);

				//Display initialized array
				printf("\nSort 2D Array Operation\n\n");
				printf("2D Array before sorting\n");
				print_2Darray(main2Darray, mainSize);

				//Display sorted array
				printf("\n2D Array after sorting\n");
				sort_2Darray(main2Darray, mainSize);
				print_2Darray(main2Darray, mainSize);

				break;

			case 6:
				// Exit Program

				break;

			default:
				// Invalid input - Error
				printf( "\n"
						"*********************************\n\n"
						" Error: Invalid Switch Condition \n\n"
						"*********************************\n");
		}

	} while(mainOption != 6);

	return 0;
}