#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")
... 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);
}
...
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;
}
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
find even number in array
int array[10] = {...}; for (int i = 0; i < 10; ++i) { if (i % 2 == 0) array[i] += 5; else array[i] -= 10; }
Divide the array in half and get the median of each half
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}
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.
find even number in array
int array[10] = {...}; for (int i = 0; i < 10; ++i) { if (i % 2 == 0) array[i] += 5; else array[i] -= 10; }
for(int i = 1; i < 100; i+=2) { System.out.println(i); }
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.
Divide the array in half and get the median of each half
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}
void f (int* a, int len) { if (!a) return;for (int i=0; i<len; ++i) { if (a[i]%2) { printf ("%d is odd\n", a[i]); } else { printf ("%d is even\n", a[i]); } }
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.
NO. Not even close. Nothing will interchange.
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.
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.
'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.