lundi 29 mars 2021

C program that prints out the non repeated number in an array using break statement

so I was searching about a program that prints out the non repeated numbers in an array, the program is completely fine but I can't understand what exactly happens in the break statement part so can someone please explains what happens because I can't get it, here is the code down below.

#include<stdio.h>
int main(void){

int n;
printf("enter a value for n: ");
scanf("%d",&n);
int T[n];
int j;  
printf("fill in the array: \n");
for(int i=0 ; i<n ; i++)
{
    printf("enter value %d: ",i+1);
    scanf("%d",&T[i]);
}   
for(int i=0 ; i<n ; i++)
{
    printf("%d ",T[i]);
}


//---------------------------------------------------------------------//

        
printf("the non repeated elements are: \n");
for(int i=0 ; i<n ; i++)
{
    for( j=0 ; j<n ; j++)
    {
        if(T[i]==T[j] && i!=j)
        {
            break;
        }
            
            
    }
    if(j==n)
    {       
    printf("%d ",T[i]);         
    }
}   
return 0;
}

Aucun commentaire:

Enregistrer un commentaire