-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathChapter1DSA.cpp
More file actions
75 lines (62 loc) · 1.16 KB
/
Chapter1DSA.cpp
File metadata and controls
75 lines (62 loc) · 1.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <array>
using namespace std;
//Question 4.1
void sumArray(int intArray[], int arraySize){
int *p = intArray;
int sum = 0;
for(int i=0; i < arraySize; i++){
sum += *p;
p++;
}
cout << sum;
delete p;
}
void removeOdds(int intArray[], int arraySize){
int *p = intArray;
for(int i=0; i < arraySize; i++){
if(*p %2 !=0){
*p = 0;
//*(p+1) = 0;
}
cout << *p << endl;
p++;
}
}
int main(){
/* //QUESTION 1
int i, *p, *q;
p = &i; //A
i = *&*p; //D
p = &*&i; //G
q = *&p; //J
q = &*p; //K
*/
/* // QUESTIOn 2
char *s2 = "hello";
char *s1;
cout << strlen(s2);
s1 = new char[strlen(s2)];
strcpy(s1, s2);
*/
/* //QUESTION 3
int intArray[] = {1, 2, 3}, *p = intArray;
cout << p << endl;
*p++;
(*p)++;
cout << intArray[0] << endl;
cout << intArray[1] << endl;
cout << intArray[2] << endl;
cout << p;
*/
/* QUESTION 4-1
int SIZE = 9;
int intArray[SIZE] = {1, 2,3,4,5,6,7,8,9};
sumArray(intArray, SIZE);
*/
int SIZE = 9;
int intArray[SIZE] = {1, 2,3,4,5,6,7,8,9};
// removeOdds(intArray, SIZE);
}