Solved programming problem

Replace Array Elements which is Divisible by 3 in C.

Source code

#include <stdio.h>

int main()

{

    int n,array[100],i;

    printf("Please Enter The Array Size: ");

    scanf("%d",&n);

    printf("Please Enter %d elements of The array: ",n);

    for(i=0; i<n; i++)

    {

        scanf("%d",&array[i]);

    }

    printf("
Your Array: 
");

    for(i=0; i<n; i++)

    {

        if(array[i]%3==0)

        {

           array[i]=-1;

           printf("%d ",array[i]);

        }

        else

        printf("%d ",array[i]);

    }

}

Output

Please Enter The Array Size: 5

Please Enter 5 elements of The array: 1 3 9 2 6

Your Array: -1 -1 -1 2 -1

Join the discussion

Add your comment