namespace std; int main() int num[ ] = { , , , , }; int t= ; cout<<num[ ] <<endl; // S1 cout<<num[ + ] <<endl; // S2 cout<<num[t=t+ ]; // S3 output: // Accessing array elements Chapter Page - - In the above program, statement S1 displays the value of the 3rd element (subscript index ). S2 will display the value of the 5th element (ie. Subscript value is + = ). In the same way statement S3 will display the value of the 4th element.
#include <iostream> using namespace std; int main() int num[ ], even= , odd= ; for (int i= ; i< ; i++) cout<< "\n Enter Number " << i+ <<"= "; cin>>num[i]; if (num[i] % == ) ++even; else ++odd; cout << "\n There are "<< even <<" Even Numbers"; cout << "\n There are "<< odd <<" Odd Numbers"; C++ program to inputs values and count the number of odd and even numbers Output : Enter Number = Enter Number = Enter Number = Enter Number = Enter Number = Enter Number = Enter Number = Enter Number = Enter Number = Enter Number = There are Even Numbers There are Odd Numbers ( HOTS : Rewrite the above program using the conditional operator instead of if) Searching in a one dimensional array: Searching is a process of finding a particular value present in a given set of numbers. The linear search or sequential search compares each element of the list with the value that has to be searched until all the elements in the array have been traversed and compared. Chapter Page - - #include <iostream> using namespace std; int main() int num[ ], val, id=- ; for (int i= ; i< ; i++) cout<< "\n Enter value " << i+ <<"= "; cin>>num[i]; cout<< "\n Enter a value to be searched: "; cin>>val; for (int i= ; i<size; i++) if (arr[i] == value) { id= i; break; if(id==- ) cout<< "\n Given value is not found in the array.."; else cout<< "\n The value