• Ziyaretçi Sayısı:588319
  • www.oguzata.com
  • 18.191.171.235
 !

BF4

Oğuz Ata - BF3 Profili


Facebook

Oguz Ata

Kartınızı Oluşturun



by: Oðuz Ata - 21 Haziran 2015 Pazar 23:01:38

Use a single-subscripted(1-dimantional) array to solve the following problem.

Read in 20 numbers, each of which is between 10 and 100, inclusive. As each number is read, print

it only if it’s not a duplicate of a number already read. Provide for the “worst case” in which all 20

numbers are different. Use the smallest possible array to solve this problem.

 

4. Soru



#include < stdio.h >
#define MAX 20
int main()
{
	int a[MAX] = { 0 }; /* array for user input */
	int i; /* loop counter */
	int j; /* loop counter */
	int k = 0; /* number of values currently entered */
	int duplicate; /* flag for duplicate values */
	int value; /* current value */

	printf("Enter 20 integers between 10 and 100:\n");

	/* get 20 integers from user */
	for (i = 0; i <= MAX - 1; i++) {
		duplicate = 0;
		printf("%d.number=", i + 1);
		scanf("%d", &value);

		/*if value is not between 10 to 100 ignore it!!! */
		if (value<10 || value>100) continue;

		/* test if integer is a duplicate */
		for (j = 0; j < k; j++) {

			/* if duplicate, raise flag and break loop */
			if (value == a[j]) {
				duplicate = 1;
				break;
			} /* end if */

		} /* end for */

		/* if number is not a duplicate, enter it in array */
		if (!duplicate) {
			a[k++] = value;
		} /* end if */

	} /* end for */

	printf("\nThe nonduplicate values are:\n");

	/* display array of nonduplicates */
	for (i = 0; a[i] != 0; i++) {
		printf("%d ", a[i]);
	} /* end for */

	printf("\n");

	return 0; /* indicate successful termination */

} /* end main */



viewed 6521 times -


1 2
Sınav Soruları

Sınav Soruları için tıklatın
(
Son Güncelleme:15.02.2017)




 
 
Oğuz Ata, 2012