Toggle navigation
Home
Latest pastes
FAQ
Random
BitBin is shutting down!
Register
Login
Pointer
SUBMITTED BY:
Guest
DATE:
Dec. 14, 2013, 5:57 p.m.
FORMAT:
C++
SIZE:
1.7 kB
Raw
Download
Tweet
HITS:
7596
Go to comments
Report
#include
<iostream>
using
namespace
std
;
int
main
()
{
int
*
p
=
new
int
[
10000
];
int
*
q
;
q
=
p
;
int
n
;
//INPUT USER
int
ctr
;
ctr
=
0
;
//penghitung jumlah data
do
{
cout
<<
"
\n
Menu:
\n
1. Tambah
\n
2. Lihat
\n
3. Ambil
\n
4. Keluar
\n
"
;
cout
<<
"Pilihan Anda: "
;
cin
>>
n
;
if
(
n
==
1
)
//TAMBAH
{
if
(
p
!=
NULL
)
{
cout
<<
"Masukkan bilangan yang mau ditambah: "
;
if
(
ctr
==
0
)
{
cin
>>
p
[
ctr
];
cout
<<
p
[
ctr
]
<<
" berhasil ditambah
\n
"
;
}
else
{
int
tmp
=
p
[
ctr
-
ctr
];
cin
>>
p
[
ctr
-
ctr
];
p
[
ctr
]
=
tmp
;
cout
<<
p
[
ctr
-
ctr
]
<<
" berhasil ditambah
\n
"
;
}
ctr
++
;
}
}
else
if
(
n
==
2
)
cout
<<
"Bilangan paling depan adalah: "
<<
p
[
0
]
<<
"
\n
"
;
//LIHAT
else
if
(
n
==
3
)
//AMBIL
{
if
(
p
!=
NULL
)
{
for
(
int
i
=
0
;
i
<
ctr
;
i
++
)
{
//SWAP
int
t
=
p
[
i
];
p
[
i
]
=
p
[
i
+
1
];
p
[
i
+
1
]
=
t
;
//
}
ctr
-=
1
;
}
}
}
while
(
n
!=
4
);
//delete memory
delete
[]
p
;
p
=
NULL
;
q
=
NULL
;
return
0
;
}
Please enable JavaScript to view the
comments powered by Disqus.
comments powered by
Disqus