#include<iostream>
#include<vector>
int main()
{
std::vector<int> Array;
Array.push_back (42); // insert
Array.pop_back(); // delete
}
#include
#include
void print_array(std::vector
{
std::cout<<"Array elements:\n"< for( size_t index=0; index std::cout<<"Element "< std::cout< } void print_duplicates(std::vector { // 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 // 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 . . .
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 );
}
What is the number of an array<question mark>
Using sorted(array,reverse=True)
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.
To write a C++ program to display the student details using class and array of object.
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.
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.
Using sorted(array,reverse=True)
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.
sorry
To write a C++ program to display the student details using class and array of object.
one is the only number in reverse alphabetical order, while 40 is the only in alphabetical 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); } } }
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.
#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 < size) fscanf(stdin, "%f", array + (i++)); } void spill(float* array, int size, char* delimiter) { int i = 0; while (i < 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 < size; i++) for (j = i; j < size; j++) if (array[i] > array[j]) swap(array + i, array + j); } void reverse(float* array, int size) { int i; for (i = size / 2; i >= 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.
The number is 21978. 21978 when multiplied by 4 which gives the result 87912 which is in reverse order.
plz as soon as possible give me the program for shorting an array in asscending order without using any sort function in c++
main() { int no,reverse=0,digit; scanf("%d",no); for( ;no>0; ) { digit=no%10; reverse=reverse*10 + digit; no=no/10; } printf("%d",reverse); }
The order of prime factors is not relevant in factorisation.