C++ Program to print array in reverse order The array is one of the most asked topics in any coding exam. Hence one must know how to read and access array elements. The below is a basic program that explains how to read array elements and how to access and print them in reverse order. Code #include <iostream> using namespace std; int main() { int …
Read moreC++ program to search a given element in an array The below program simply takes all the inputs from the user and prints "PRESENT" if the element is found in the array and prints "ABSENT" if the element is not found in the array. This code is a simple execution of " The Linear Search Algorithm " in C++. Code #include…
Read moreC++ program to search and print index position of an element in array The below program is based on arrays. The user will provide array size and its elements along with the element whose index position the user wants to know. You need to search the element in the array if the element is found print " found at: index position ". If the e…
Read moreC++ program to print second largest element in array In this program, you need to print the second largest element of the given array. For that, first sort the array in descending order. When the array is sorted in descending order the second largest element will be at the 1st index position. Print the 1st index position element. Consider the example array…
Read moreC++ program to print second smallest element of the array In this program, you need to print the second smallest element of the given array. For that, first sort the array in ascending order. When the array is sorted in ascending order the second smallest element will be at the 1st index position. Print the 1st index position element. Consider this example…
Read moreC++ program to find and print the smallest element of the array The below program searches and prints the smallest element in the array. In this program, I have used a variable small and initialized it to the first element of the array. You can take any other variable but it should not be greater than the smallest element If you do not …
Read moreC++ program to count occurrences of an array element In this program, you will be counting how many times any particular element occurs in an array. Take all the inputs from the user, set the counter to zero. Traverse through the array and check the element matches with the given element or not. If the match is found increase the counter. Finally, print th…
Read moreC++ program to print multiplication of largest and smallest element of array Take inputs from the user. Sort the array in ascending order then the smallest element will be at index position 0 and the largest element will be at index position size-1 . Take a variable "mul" to store the multiplication of the largest and smallest element. Print the …
Read moreC++ program to check given year is leap year or not In a leap year, February has 29 days making it a total of 366 days in a year. Following conditions are tested to determine a year is a leap year or not. Divisible by 4 and 400 - Leap Year Divisible by 100 - Not a Leap Year for rest - Not a Leap Year To check the given year is a leap ye…
Read moreProgram to print all the odd numbers in an array Take the array and array elements from the user, Using a loop check each element is even or odd. If the element is odd print the element. If the number is completely divisible by 2 it is even otherwise it is odd. For this modulo operator is used. To understand about modulo operator read modulo operator in C+…
Read moreProgram to print all the even numbers in an array Take the array from the user, access each element using a loop . Check each element is even or not, dividing it by 2. If a number is completely divisible by 2 it is even else not. Code #include <bits/stdc++.h> using namespace std; int main() { int n; …
Read moreFind the sum of all elements of an array with and without using functions. How to pass array to a C++ function ? Passing array to a C++ function is same as you pass other variables or values. Just one modification is needed when you pass array to a function, you need to pass array name and size both while calling the function in the main function. In t…
Read moreProgram to print the total sum, individual sum of each row and column To perform any operation on a matrix(multidimensional array), nested loops are used. To know more about nested loops read The nested loops in C++. In this code, I have used for loops to perform all the operations on the matrix. First, read the size and matrix elements from the…
Read moreProgram to print sum of even numbers, sum of odd numbers, total sum of all elements in an array and mean of array Take the array size and its elements from the user. Using loop check each element is even or odd if the array element is even_add it to the even_sum and if it is odd add that element to the odd sum. To find the total sum add the even_sum and odd…
Read more
tcs
Copyright © 2021 Coding Demons All Rights Reseved
Social Plugin