Deklarasi:
Balik,tempat,n: integer
Deklarasi:
temp = temp * 10 + n % 10;
if (temp == 0) cout << "0";
n = n/10;
outputnya: balik angka
#include <cstdlib>
#include <iostream>
using namespace std;
int balik(int n) {
int temp = 0;
while (n>0) {
temp = temp * 10 + n % 10;
if (temp == 0) cout << "0";
n = n/10;
}
cout << temp;
return temp;
}
int main(int argc, char *argv[])
{
int bil;
cout << "\t\t\tSlamet Islan Al Hidayah\n";
cout << "\t\t\t\t10018075\n";
cout << "\t\t\t\t B\n";
cout << endl;
cout << endl;
cout << "Masukkan bilangan : ";
cin >> bil;
cout << endl;
cout << "Setelah dibalik : " << balik(bil);
cout << endl;
system("PAUSE");
return EXIT_SUCCESS;
}
Hasilnya adalah ........
0 Response to " Program Membalik Angka "
Post a Comment