Difference of sum of even and odd coderinme

Difference of sum

Suppose that you have an array of size n, Find Difference of sum it means you need to find the odd numbers and add them, find even numbers and add them finally print the absolute value of subtraction between those two sums of odd and even values.
Like we Have an example :a size [5]= {2,3,4,13,8} EvenSum=4+2+8=14 OddSum=3+13=16 Difference=| 14-16 |=2

#include <iostream>
#include <cmath>
using namespace std;

int main() {
	int n,even=0,odd=0;
	//enter size of array
	int *a=new int[n];
	for(int i=0; i<n; i++){
	// enter all elemnt	
	// check even or odd and adding
	// your code goes here
	return 0;
Dynamic Array

In C++

Dynamic memory is allocated using operator new. new is followed by a data type specifier and, if a sequence of more than one element is required, the number of these within brackets [].

Its syntax is: 

pointer = new type
pointer = new type [number_of_elements]

It returns a pointer to the beginning of the new block of memory allocated.
in C
The C dynamic memory allocation functions are defined in stdlib.h header
malloc allocates the specified number of bytes
realloc increases or decreases the size of the specified block of memory. Reallocates it if needed
calloc allocates the specified number of bytes and initializes them to zero
free releases the specified block of memory back to the system
int array[10];
However, the size of the array is fixed at compile time. If one wishes to allocate a similar array dynamically, the following code can be used:

int * array = malloc(10 * sizeof(int));

In Java

down vote
Arrays in Java are of fixed size. What you’d need is an ArrayList, one of a number of extremely valuable Collections available in Java.

Instead of

Integer[] ints = new Integer[x]
you use

List<Integer> ints = new ArrayList<Integer>();
<strong>In Python</strong>
st = [] # Declares an empty list named lst
Or you can fill it with items:

lst = [1,2,3]
You can add items using "append":

In Shell script</strong>
#! /bin/bash
while read -r input ; do
echo Num items: ${#field[@]}
echo Data: ${field[@]}
It stops reading when no more input is available

Difference of sum

Array Problem

Array easy problem

array problem trick

All rights reserved. No part of this Post may be copied, distributed, or transmitted in any form or by any means, without the prior written permission of the website admin, except in the case of brief quotations embodied in critical reviews and certain other noncommercial uses permitted by copyright law. For permission requests, write to the owner, addressed “Attention: Permissions Coordinator,” to the admin@coderinme.com

A web developer(Front end and Back end), and DBA at csdamu.com. Currently working as Salesforce Developer @ Tech Matrix IT Consulting Private Limited. Check me @about.me/s.saifi

Leave a reply:

Your email address will not be published.