C programming :array

how can i find negative even number using an array

i've tried one but couldnt get the output.. can anyone correct my mistake:

main();
{

int a[100], n, i;
printf("Enter the number of elements
");
scanf("%d", &n);
for(i=a; i<n; i++);

{
scanf("%d", &a[i]);
}

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

{
if(a[i]%2==0)

{
printf("The even number %d
", a[i]);
}

}

}

Comments

  • [color=Blue]Few problems (see RED):

    1. Why do you put a ';' after EVERY statement?
    Some statements, like FOR() and IF() and WHILE() - loop statements - they do not need that in 99.999999% of the time.

    2. In the FOR() loop you have 'i=a;'. This will not even compile. [b]i[/b] begins with value of zero.

    3. main() returns [b]int[/b] by C/C++ standards.
    [/color]
    : [code]
    : [color=Red]int[/color] main() [color=Green]// removed ';'[/color]
    : {
    : int a[100], n, i;
    : printf ("Enter the number of elements
    ");
    : scanf ("%d", &n);
    :
    : for (i=[color=Red]0[/color]; i<n; i++) [color=Green]// removed ';'[/color]
    : {
    : scanf ("%d", &a[i]);
    : }
    :
    : for(i=0; i<n; i++) [color=Green]// removed ';'[/color]
    : {
    : if(a[i]%2==0)
    : {
    : printf("The even number %d
    ", a[i]);
    : }
    : }
    : [color=Red]return 0;[/color]
    : }
    [/code]
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

In this Discussion