answersLogoWhite

0


Best Answer

#include<iostream>

#include<vector>

int main()

{

std::vector<int> Array;

Array.push_back (42); // insert

Array.pop_back(); // delete

}

User Avatar

Wiki User

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

Wiki User

10y ago

#include

#include

void print_array(std::vector& arr)

{

std::cout<<"Array elements:\n"<

for( size_t index=0; index

std::cout<<"Element "<

std::cout<

}

void print_duplicates(std::vector& arr)

{

// Loop through all but the last element

for( size_t index=0; index

{

// Compare the indexed value with all remaining values

for( size_t compare=index+1; compare

{

if( arr[index]==arr[compare] )

{

std::cout<<"Element "<

// Duplicate found, no need to check remaining elements.

break;

}

}

}

}

int main()

{

std::vector arr;

// Push 10 values in range 0 to 8 (guarantees at least one duplicate value):

for(size_t index=0; index<10; ++index)

arr.push_back(rand()%9);

print_array(arr);

print_duplicates(arr);

}

Output

Array elements:

Element 0 has value 5

Element 1 has value 8

Element 2 has value 7

Element 3 has value 4

Element 4 has value 8

Element 5 has value 1

Element 6 has value 3

Element 7 has value 0

Element 8 has value 7

Element 1 contains a duplicate value 8

Element 2 contains a duplicate value 7

Press any key to continue . . .

This answer is:
User Avatar

User Avatar

Wiki User

10y ago

int count(const std::vector<int>& v, const int num)

{

int total = 0;

for( std::vector<int>::const_iterator i=v.begin(); i!=v.end(); ++i )

if( *i == num )

++total;

return( total );

}

This answer is:
User Avatar

User Avatar

Wiki User

11y ago

What is the number of an array<question mark>

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: What is a C program to print the number of an array in reverse order?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

Sort array in ascending descending order in python?

Using sorted(array,reverse=True)


How do you reverse the order of the elements in the array?

Start by pointing to each end of the array. Work your way towards the middle of the array, swapping elements as you go. When the pointers meet or pass each other, the array is completely reversed.


How do you write a program to read set of numbers using by an array and display the ascending order of the given input numbers?

To write a C++ program to display the student details using class and array of object.


How do you write a program which reads a list of ten numbers and print the list in reserve order in c program?

The simplest way is probably to read the numbers into an array and then prints each element of the array starting at the last one and moving backwards.


What are 3 different ways to implement an array of order 4x8?

An array of order 4x8 can either be implemented as a one-dimensional array of order 32 or as a one-dimensional array of order 4, where each element is a one-dimensional array of order 8. In either case, the 32 data elements are allocated contiguously and there is no difference in performance. A third way is to implement the one-dimensional array of order 4 as an array of pointers to separately allocated one-dimensional arrays of order 8. The order 4 array is contiguous as are the order 8 arrays, however they need not be contiguous with one another other. This is the least efficient implementation due to the additional level of indirection required to navigate the array.

Related questions

Sort array in ascending descending order in python?

Using sorted(array,reverse=True)


How do you reverse the order of the elements in the array?

Start by pointing to each end of the array. Work your way towards the middle of the array, swapping elements as you go. When the pointers meet or pass each other, the array is completely reversed.


What will be the program to arrange numbers stored in array in ascending order using pointers?

sorry


How do you write a program to read set of numbers using by an array and display the ascending order of the given input numbers?

To write a C++ program to display the student details using class and array of object.


What number is in reverse alphabetical order?

one is the only number in reverse alphabetical order, while 40 is the only in alphabetical order


Write a program to sort elements of an array in ascending order?

import java.util.Arrays; public class arraysort { public static void main(String[] a) { int array[] = { 2, 5, -2, 6, -3 }; Arrays.sort(array); for (int i : array) { System.out.println(i); } } }


How do you write a program which reads a list of ten numbers and print the list in reserve order in c program?

The simplest way is probably to read the numbers into an array and then prints each element of the array starting at the last one and moving backwards.


How do you create a program that will let the user to enter 10 numbers and arrange it in ascending and descending?

#include "stdio.h" #define ARRAY_SIZE 10 void fill(float* array, int size); void spill(float* array, int size, char* delimiter); void bubble_sort(float* array, int size); void reverse(float* array, int size); void swap(float* a, float* b); int main(int argc, char* argv[]) { float numbers[ARRAY_SIZE]; fill(numbers, ARRAY_SIZE); bubble_sort(numbers, ARRAY_SIZE); spill(numbers, ARRAY_SIZE, " "); reverse(numbers, ARRAY_SIZE); spill(numbers, ARRAY_SIZE, " "); return 0; } void fill(float* array, int size) { int i = 0; while (i &lt; size) fscanf(stdin, "%f", array + (i++)); } void spill(float* array, int size, char* delimiter) { int i = 0; while (i &lt; size) fprintf(stdout, "%f%s", array[i++], delimiter); fputc('\n', stdout); } void bubble_sort(float* array, int size) { int i, j; for (i = 0; i &lt; size; i++) for (j = i; j &lt; size; j++) if (array[i] &gt; array[j]) swap(array + i, array + j); } void reverse(float* array, int size) { int i; for (i = size / 2; i &gt;= 0; i--) swap(array + i, array + (size - (i + 1))); } void swap(float* a, float* b) { float c = *a; *a = *b; *b = c; } fill gets the numbers from input spill sends them to output bubble sort will sort the array in ascending order reverse will reverse the list so that it is in descending order swap is used to swap two floats You can change float to double or int depending on which datatype you want to use.


What 5 digit number when multiplied by 4 yields the number the same five digits in reverse order?

The number is 21978. 21978 when multiplied by 4 which gives the result 87912 which is in reverse order.


Sorting an array in PHP without using sort function?

plz as soon as possible give me the program for shorting an array in asscending order without using any sort function in c++


Reverse the order of separate numbers without using array or list exinput 5 7 9 1 output 1 9 7 5?

main() { int no,reverse=0,digit; scanf("%d",no); for( ;no&gt;0; ) { digit=no%10; reverse=reverse*10 + digit; no=no/10; } printf("%d",reverse); }


When does a prime number factor reverse order?

The order of prime factors is not relevant in factorisation.