answersLogoWhite

0


Best Answer

#include<stdio.h>

#include<conio.h>

void main()

{

int a[10],i,evc=0,odc =0;// sum=0;

clrscr();

printf("enter 10 no.s in the array\n");

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

{

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

}

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

{

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

{

evc=evc+1;

}

else

{

odc=odc+1;

}

}

printf("Even nos %d\n",evc);

printf("odd nos %d\n",odc);

getch();

}

0"). This is a perfectly valid and correct approach, but in many implementations, a simple test for the least significant bit ("a[i] & 1") can be more efficient. This also allows to replace logic with arithmetic, which generally is more efficient (i.e. "odc += a[i] & 1")

User Avatar

Wiki User

11y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

14y ago

... int number_to_check = 0;

...

cin >> number_to_check;

if ((number_to_check % 2))

{

printf("The number %d is even\n", number_to_check);

}

else

{

printf("The number %d is odd\n", number_to_check);

}

...

This answer is:
User Avatar

User Avatar

Wiki User

11y ago

Write a c program that interchanges the odd and even elements of an array?

Answer:

#include

int main()
{
int num[]={1,2,3,4,5,6};
int i,temp;

for(i=0;i<=5;i=i+2)
{
temp=num[i];
num[i]=num[i+1];
num[i+1]=temp;
}
for(i=0;i<=5;i=i+2)
printf(''%d",num[i]);
return 0;
}

This answer is:
User Avatar

User Avatar

Wiki User

13y ago

Full source code for counting even and odd elements of an array is available at:

http://bitsbyta.blogspot.com/2011/02/counting-even-odd-elements-in-array.html

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: A c program to interchange odd and even components of an array?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

Program to print all the even numbers of an array in visual basic?

find even number in array


Can you help me with the C plus plus code of the program which has 10 index of array it adds 5 into every even elements of the array and then it subtracts 10 into the odd elements of the array?

int array[10] = {...}; for (int i = 0; i &lt; 10; ++i) { if (i % 2 == 0) array[i] += 5; else array[i] -= 10; }


How do you find the quartile in an even array of values?

Divide the array in half and get the median of each half


How do you calculate size of an unsized array?

In Java, all arrays have a finite size. Even if you did not initialize an array to a particular size (say the array was being passed into a method), some other part of the program did. Because of this, the length of an array can always be accessed via the .length parameter.Example:int[] arr = new int[5];System.out.print(arr.length); //5public void k(int[] arr){System.out.print(arr.length) //arr will always have a finite size}


Does mentioning the array name gives the base address in all the contexts?

Mentioning the array name in C or C++ gives the base address in all contexts except one. Syntactically, the compiler treats the array name as a pointer to the first element. You can reference elements using array syntax, a[n], or using pointer syntax, *(a+n), and you can even mix the usages within an expression. When you pass an array name as a function argument, you are passing the "value of the pointer", which means that you are implicitly passing the array by reference, even though all parameters in functions are "call by value". There is, however, one very important distinction. While an array name is referentially the same as a pointer, it is not a pointer in that it does not occupy program referential space in the process. This means that, while you can change the value of a pointer, and thus the address to which it points, you can not change the value of an array name. This distinction is what we call R-Value (array or pointer) as opposed to L-Value (pointer only), i.e. can the object appear on the left sign of an assignment operator.

Related questions

Program to print all the even numbers of an array in visual basic?

find even number in array


Can you help me with the C plus plus code of the program which has 10 index of array it adds 5 into every even elements of the array and then it subtracts 10 into the odd elements of the array?

int array[10] = {...}; for (int i = 0; i &lt; 10; ++i) { if (i % 2 == 0) array[i] += 5; else array[i] -= 10; }


Write a java program to find sum of even and odd numbers in given array?

for(int i = 1; i &lt; 100; i+=2) { System.out.println(i); }


Why is the electronic recycling program for electronics?

Recycling is done in order to retrieve the components which can be used for repairing, replacementand even for improvement.If u recycle an old device the electronic components which can have various applications.


How do you find the quartile in an even array of values?

Divide the array in half and get the median of each half


How do you calculate size of an unsized array?

In Java, all arrays have a finite size. Even if you did not initialize an array to a particular size (say the array was being passed into a method), some other part of the program did. Because of this, the length of an array can always be accessed via the .length parameter.Example:int[] arr = new int[5];System.out.print(arr.length); //5public void k(int[] arr){System.out.print(arr.length) //arr will always have a finite size}


How do you wwrite a Program that prints all odd and even numbers from an array?

void f (int* a, int len) { if (!a) return;for (int i=0; i&lt;len; ++i) { if (a[i]%2) { printf ("%d is odd\n", a[i]); } else { printf ("%d is even\n", a[i]); } }


What are the types of array?

There are several different types of arrays, which describe the characteristics of the array. Arrays may be static or dynamic. Static arrays have a predetermined size that will not change over the course of the program's life cycle, while dynamic arrays may be made larger or smaller as necessary while the program runs. Arrays may be one-dimensional or multi-dimensional. An array of just one dimension stores values in a straight line, while a multi-dimensional array represents data that might be rectangular, such as the dots in an image, or even 3 dimensional, such as a multi-layer image, an animation, etc.


Is a 700R4 transmission casing inter changeable with a 4L80E?

NO. Not even close. Nothing will interchange.


What components does a CNC lathe manufacture?

A cnc lathe can manufacture nearly anything cylindrical. Some even have attachments to do other types of work in the machine as well, for a virtually endless array of parts. Whatever you can imagine really, as long as it will fit in the machine.


Does mentioning the array name gives the base address in all the contexts?

Mentioning the array name in C or C++ gives the base address in all contexts except one. Syntactically, the compiler treats the array name as a pointer to the first element. You can reference elements using array syntax, a[n], or using pointer syntax, *(a+n), and you can even mix the usages within an expression. When you pass an array name as a function argument, you are passing the "value of the pointer", which means that you are implicitly passing the array by reference, even though all parameters in functions are "call by value". There is, however, one very important distinction. While an array name is referentially the same as a pointer, it is not a pointer in that it does not occupy program referential space in the process. This means that, while you can change the value of a pointer, and thus the address to which it points, you can not change the value of an array name. This distinction is what we call R-Value (array or pointer) as opposed to L-Value (pointer only), i.e. can the object appear on the left sign of an assignment operator.


What is the default value of the array elements in an integer array?

'0' Try this: public static void main(String[] args){ } The output would be 0 even though you did not initialize any value in the int array.