Click here to Skip to main content
15,891,529 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionC(17) Complete Tutorial References Pin
chipp_zanuff23-Feb-21 6:35
chipp_zanuff23-Feb-21 6:35 
AnswerRe: C(17) Complete Tutorial References Pin
CPallini23-Feb-21 20:27
mveCPallini23-Feb-21 20:27 
GeneralRe: C(17) Complete Tutorial References Pin
chipp_zanuff25-Feb-21 6:45
chipp_zanuff25-Feb-21 6:45 
GeneralRe: C(17) Complete Tutorial References Pin
CPallini25-Feb-21 20:07
mveCPallini25-Feb-21 20:07 
GeneralRe: C(17) Complete Tutorial References Pin
chipp_zanuff26-Feb-21 5:59
chipp_zanuff26-Feb-21 5:59 
AnswerRe: C(17) Complete Tutorial References Pin
Richard MacCutchan23-Feb-21 21:58
mveRichard MacCutchan23-Feb-21 21:58 
GeneralRe: C(17) Complete Tutorial References Pin
chipp_zanuff25-Feb-21 6:43
chipp_zanuff25-Feb-21 6:43 
GeneralRe: C(17) Complete Tutorial References Pin
Victor Nijegorodov25-Feb-21 7:47
Victor Nijegorodov25-Feb-21 7:47 
GeneralRe: C(17) Complete Tutorial References Pin
Richard MacCutchan25-Feb-21 23:12
mveRichard MacCutchan25-Feb-21 23:12 
GeneralRe: C(17) Complete Tutorial References Pin
chipp_zanuff26-Feb-21 6:36
chipp_zanuff26-Feb-21 6:36 
GeneralRe: C(17) Complete Tutorial References Pin
Richard MacCutchan26-Feb-21 6:43
mveRichard MacCutchan26-Feb-21 6:43 
AnswerRe: C(17) Complete Tutorial References Pin
Aghast (nj)9-Mar-21 19:27
Aghast (nj)9-Mar-21 19:27 
GeneralRe: C(17) Complete Tutorial References Pin
Nelek9-Mar-21 19:29
protectorNelek9-Mar-21 19:29 
GeneralRe: C(17) Complete Tutorial References Pin
chipp_zanuff13-Mar-21 0:54
chipp_zanuff13-Mar-21 0:54 
QuestionGetComputerObjectNameW Win API is failing Pin
rajneshmalik18-Feb-21 18:42
rajneshmalik18-Feb-21 18:42 
AnswerRe: GetComputerObjectNameW Win API is failing Pin
Victor Nijegorodov18-Feb-21 20:46
Victor Nijegorodov18-Feb-21 20:46 
GeneralRe: GetComputerObjectNameW Win API is failing Pin
rajneshmalik18-Feb-21 21:47
rajneshmalik18-Feb-21 21:47 
GeneralRe: GetComputerObjectNameW Win API is failing Pin
Victor Nijegorodov18-Feb-21 22:45
Victor Nijegorodov18-Feb-21 22:45 
GeneralRe: GetComputerObjectNameW Win API is failing Pin
rajneshmalik19-Feb-21 1:01
rajneshmalik19-Feb-21 1:01 
GeneralRe: GetComputerObjectNameW Win API is failing Pin
Victor Nijegorodov19-Feb-21 3:33
Victor Nijegorodov19-Feb-21 3:33 
GeneralRe: GetComputerObjectNameW Win API is failing Pin
rajneshmalik25-Mar-21 23:27
rajneshmalik25-Mar-21 23:27 
AnswerRe: GetComputerObjectNameW Win API is failing Pin
Randor 18-Feb-21 22:43
professional Randor 18-Feb-21 22:43 
QuestionUnexpected output in array Pin
Member 1507028617-Feb-21 18:43
Member 1507028617-Feb-21 18:43 
AnswerRe: Unexpected output in array Pin
CPallini17-Feb-21 20:22
mveCPallini17-Feb-21 20:22 
You are putting holes in your arrays of even and odd elements. In order to avoid that, you need to maintain two separate variables to keep track of how many even and odd items have been added so far. Try
C
#include <stdio.h>

#define SIZE 20
int main()
{
  int items, odd_items, even_items;
  int array[SIZE], odd[SIZE], even[SIZE];
  printf("enter how many array elements\n");

  scanf("%d",&items);


  odd_items = even_items = 0;

  for (int n=0; n<items; ++n)
  {
    printf("enter item %d:\n", n);
    scanf("%d", &array[n]);

    if ( (array[n] % 2) == 0)
    {
      even[even_items] = array[n];
      ++even_items;
    }
    else
    {
      odd[odd_items] = array[n];
      ++odd_items;
    }
  }

  printf("array items\n");
  for (int n=0; n<items; ++n)
    printf("%d ", array[n]);
  printf("\n");

  printf("even array items\n");
  for (int n=0; n<even_items; ++n)
    printf("%d ", even[n]);
  printf("\n");

  printf("odd array items\n");
  for (int n=0; n<odd_items; ++n)
    printf("%d ", odd[n]);
  printf("\n");

  return 0;
}

"In testa che avete, Signor di Ceprano?"
-- Rigoletto

GeneralRe: Unexpected output in array Pin
Greg Utas18-Feb-21 0:02
professionalGreg Utas18-Feb-21 0:02 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.