The question: Modify the first Loop so that the values in the array data are initialized to multiples of 2 as
follows: 2,4,6,....,20.

here is the original codes that has been set in the question paper:
#include <stdio.h>
#define numitems 10
int main(int argc, char* argv[])
{
int data[numitems];
int i;
int *ptr;
for(ptr = data; ptr < &data[numitems]; ptr++)
*ptr = 0;
for (i=0;i<numitems;i++)
printf("data[%d]=%d\n", i, data[i]);
return 0;
}
HERE ARE MY MODIFICATION BUT STILL NOTHING IS BEING DISPLAYED:
    #include <stdio.h>
#define numitems 10
int main(int argc, char* argv[])
{
int data[numitems];
int i;
int *ptr;
for(ptr = data; ptr < &data[numitems]; (ptr=ptr+2)){
*ptr = 2;
}
for (i=0;i<numitems;i++)
{
printf("data[%d]=%d\n", i, data[i]);
}
return 0;
}
2teez commented: You mean you are in an exam? -1

Recommended Answers

All 3 Replies

Hi,

here is the original codes that has been set in the question paper

Is it permitted in your school to share and ask for help on a question paper, that is not an assignment?

Member Avatar for humorousone

^^ good point.
If it is, we can only give advice on how to solve this problem, not a direct solution or examples.

When you begin computer programming ... don't leave your 'normal thinking skills' ... behind.

How is the series 2,4,6,8, ...
related to        1,2,3,4, ..

.

Answer: ?

How could you design a program for this?

Or ... if you start with 2
What can you keep adding to the previous value(s) ...
So that you get ... 4,
                    6,
                    8,
                    ... etc

Can you code this in C?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.