The basics in C + +

Source: Internet
Author: User

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 + +

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.