Binary conversion #include<iostream> #include <stdlib.h>using namespace Std;int main (void) {cout << Please enter an integer: "< < Endl;int x = 0;cin >> x;cout << Oct << x << endl;cout << Dec << x << endl;c Out << hex << x << endl;cout << "Please enter a Boolean value (0, 1):" <<endl;bool y = false;cin >> y;cout &l t;< boolalpha << y << endl;system ("pause"); return 0;}
code explanation of namespace #include <stdlib.h> #include <iostream> Using namespace std;namespace a{int x = 1;void fun () {cout << "A" &NBSP;<<&NBSP;ENDL;}} Namespace b{int x = 2;void fun () {cout << "B" &NBSP;<<&NBSP;ENDL; Void fun2 () {cout << "2B" &NBSP;<<&NBSP;ENDL;} Using namespace b;int main (void) {cout << A::x << endl; Fun2 (); System ("pause"); return 0;}
judging odd or even codes #include <iostream> #include <stdlib.h> using namespace std;namespace mynum //fill in the namespace keyword {int x = 106;} Int main () {// uses the bool type to define the isodd as the status bit bool isflag = false;if (mynum::x % 2 == 0) {//change the value of the status bit so that it is falsemynum::x = 0;} else{//change the value of the status bit to truemynum::x = 1;} Determines the value of the status bit if (bool (mynum::x)) {// If the value of the status bit is true, the print variable x is odd cout << "x is odd" < < endl;} else{// if the value of the status bit is False, the print variable x is even cout << "x is even" &NBSP;<<&NBSP;ENDL;} System ("pause"); return 0;}
Determine the maximum and minimum values in the array #include<iostream> #include <stdlib.h>using namespace std;int getmaxormin (int *arr, int count, BOOL Ismax) {int temp = arr[0];for (int i = 0; i < count; i++) {if (Ismax) {if (temp < arr[i]) {temp = Arr[i];}} Else{if (Temp > Arr[i]) {temp = Arr[i];}}} return temp;} int main (void) {int arr1[4] = {3,5,1,7};bool Ismax = false;cin >> ismax;cout << getmaxormin (arr1, 4, Ismax) < ;< Endl;system ("pause"); return 0;}
This article from "Itaustins" blog, declined reprint!
The basics in C + +