473,325 Members | 2,608 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,325 software developers and data experts.

C programming Language : 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:

Expand|Select|Wrap|Line Numbers
  1. main();
  2. {
  3.  
  4.     int a[100], n, i;
  5.     printf("Enter the number of elements\n");
  6.     scanf("%d", &n);
  7.     for(i=a; i<n; i++);
  8.  
  9.     {
  10.         scanf("%d", &a[i]);
  11.     }
  12.  
  13.     for(i=0; i<n; i++);
  14.  
  15.     {
  16.         if(a[i]%2==0)
  17.  
  18.         {
  19.             printf("The even number %d \n", a[i]);
  20.         }
  21.  
  22.     }
  23.  
  24. }
May 7 '10 #1
5 1374
Dheeraj Joshi
1,123 Expert 1GB
Expand|Select|Wrap|Line Numbers
  1. for(i=a; i<n; i++);
  2.  
Is not this should be
Expand|Select|Wrap|Line Numbers
  1. for(i=0; i<n; i++);
  2.  
Regards
Dheeraj Joshi
May 7 '10 #2
i'v correct the mistake but still wont work.
May 7 '10 #3
Karlen
5
@ashiela
instead of "if(a[i]%2==0)", try "if((a[i]%2==0) && (a[i]<0))".
May 7 '10 #4
i have changed the lineno 7 and 13. it will work.. check

main();
{

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

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

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

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

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

}

}
May 7 '10 #5
Joseph Martell
198 Expert 128KB
As your code is posted you have a ';' immediately after main. If your compiler compiles this (mine wouldn't) then you have an empty body on your main function and an un-named function body defined by your curly braces.
May 7 '10 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

18
by: Roman Suzi | last post by:
;-) Just type into google "best programming language" and press (I am lucky) Sincerely yours, Roman Suzi -- rnd@onego.ru =\= My AI powered by GNU/Linux RedHat 7.3
3
by: Matt | last post by:
I always heard dialet of programming language. Or implementation of a programming language. What does it really mean? C++ is standardized already, does it mean it doesn't have any dialets? But I...
2
by: Matt | last post by:
I always heard dialet of programming language. For example, Objective-C is a dialet of C programming language. What does it really mean? C is already standardize, why there are dialets? Or when...
134
by: evolnet.regular | last post by:
I've been utilising C for lots of small and a few medium-sized personal projects over the course of the past decade, and I've realised lately just how little progress it's made since then. I've...
2
by: Juuso Hukkanen | last post by:
Language is quite good, if you don't learn the language syntax in 30 minutes complain and flame. t3d(TM) in a nutshell: -Languages main documentation is two pages (presented on the last two...
25
by: Dave | last post by:
I want to spend two minutes on my soapbox. I love C#. I am so productive in it it's ridiculous. But it's so easy to write code that uses poor design principles. Example: just making...
7
by: Robert Seacord | last post by:
The CERT/CC has just deployed a new web site dedicated to developing secure coding standards for the C programming language, C++, and eventually other programming language. We have already...
14
by: deko | last post by:
For building Windows desktop apps, the clear favorite is C#. But my clients can't afford to buy Microsoft products. So I need to develop software for Linux users and web applications. In the...
17
by: CoreyWhite | last post by:
I bought this book years ago, when I was just learning C++. Since then I've gone through every math course offered at my college, taken courses on coding C & thinking in terms how how to make the...
43
by: Adem24 | last post by:
The World Joint Programming Language Standardization Committe (WJPLSC) hereby proclaims to the people of the world that a new programming language is needed for the benefit of the whole mankind in...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.