• June 12, 2021

PHSARIT

Bring Technology Ideas with you

 What is a comments in C++?

All the programming in the world always use comments. Comment is the way of programming language can execute without any action affect to the line or block of code which already put comments.

Comments can be putting in the single line or multi lines of code. In C++ comment is using the sign // for single line and the /*…*/ as the example below:

Comment in single line:

    comments in single line

    Comment in multi line:

      comments in multi lines

      The real code looks like:

      // sort descending from Largest to smallest
      	for (int i = 0; i < n; ++i)
      	{
      		for (int j = i + 1; j < n; ++j) //compare value again and again
      		{
      			if (arr[i] < arr[j]) // if it is true through value to temp 
      			{
      				valueTemp = arr[i]; //store value tempory in array i
      				arr[i] = arr[j]; //compare i and j, if equal
      				arr[j] = valueTemp; // set J=store value temport
      			}
      		}
      	}
      	cout << "Sorting Descending Array:";
      	for (int i = 0; i < n; ++i)
      		cout << arr[i] << endl;
      	//find array element base on user input
      	/*int searchValue;
      	cout << "Please enter element value:";
      	cin >> searchValue;
      	for (int i = 0; i < n; i++)
      	{
      		if(arr[i]==searchValue)
      		{
      			cout << "Value is:" << searchValue << "\t in the index:" << i + 1<<endl;
      			break;
      		}else
      		{
      			cout << "There is no element in this array";
      			break;
      		}
      	}*/
      

      ——————————————————————————————————————–

      Related post