Write a program that reads the dimension N of an integer array T (maximum dimension: 50 components), fills the array with values entered on the keyboard and displays the array.

Then replace all 1 and 100 values by 0 and display the array.


Difficulty level
This exercise is mostly suitable for students
#include<stdio.h>
#include<math.h>
#include<conio.h>
#define SIZE 50
void main()
{
	int N; // nb of elements
	int T[SIZE]; // array of maximum size 50
	int i;
	do {
		printf("Enter N: ");
		scanf("%d", &N);
	} while (N<0 || N>SIZE);

	for (i = 0; i < N; i++)
	{
		printf("Enter T[%d]: ", i);
		scanf("%d", &T[i]);
	}

	printf("\n\nPrinting the elements\n");
	for (i = 0; i < N; i++)
	{
		printf("T[%d]=%d\n", i, T[i]);
	}

	// replacing 1 and 100 by 0
	for (i = 0; i < N; i++)
	{
		if(T[i]==1 || T[i]==100)
			T[i]=0;
	}
	
	printf("\n\nPrinting the elements\n");
	for (i = 0; i < N; i++)
	{
		printf("T[%d]=%d\n", i, T[i]);
	}
 
	getch();
}

Back to the list of exercises
Looking for a more challenging exercise, try this one !!
Number of occurrence of a string into another one