# Utils

<details>

<summary>string to int</summary>

```
// no special include statement required

int num = stoi("23");

// num is 23 now
```

</details>

<details>

<summary>int to string</summary>

```
// no special include statement required

string s = to_string(12345);

// s is "12345" now
```

</details>

<details>

<summary>int to char</summary>

```
// no special include statement required

char itoc(int number) {
   return char('0' + number);
}

char c = itoc(5);

// c is '5' now

```

</details>

<details>

<summary>char to int</summary>

```
// no special include statement required

int ctoi(char c){
    return c - '0';
}

int i = ctoi('6');

// i is 6 now
```

</details>

<details>

<summary>is small case char (a-z) ?</summary>

```
bool isSmallCaseChar(char c){
  return islower(c);
}

isSmallCaseChar('a') // true
isSmallCaseChar('z') // true
isSmallCaseChar('G') // false
isSmallCaseChar('0') // false
isSmallCaseChar('9') // false
isSmallCaseChar('%') // false
isSmallCaseChar('?') // false
```

</details>

<details>

<summary>is upper case char (A-Z) ?</summary>

```
bool isUpperCaseChar(char c){
  return isupper(c);
}

isUpperCaseChar('a') // false
isUpperCaseChar('z') // false
isUpperCaseChar('A') // true
isUpperCaseChar('G') // true
isUpperCaseChar('0') // false
isUpperCaseChar('9') // false
isUpperCaseChar('%') // false
isUpperCaseChar('?') // false
```

</details>

<details>

<summary>is digit ?</summary>

```
#include <cctype>

bool result = isdigit('6');
// result is true

bool result = isdigit('g');
// result is false
```

</details>

<details>

<summary>is alphaNumeric ?</summary>

```
isalnum('a') // true
isalnum('z') // true
isalnum('G') // true
isalnum('0') // true
isalnum('9') // true
isalnum('%') // false
isalnum('?') // false
```

</details>

<details>

<summary>get ascii value of character</summary>

```
// no special include statement required

int getAsciiValue(char c){
	return int(c);
}

getAsciiValue('a')      // 97
getAsciiValue('D') 	// 68
getAsciiValue('5')      // 53 
getAsciiValue('\n')     // 10


```

</details>

<details>

<summary>gcd</summary>

```
// GCD aka HCF
int gcd(int a, int b){
    if(a < b) return gcd(b,a);

    if(b == 0) return a;

    return gcd(b, a%b);
}
```

</details>

<details>

<summary>NCR   (i.e. N-choose-R)</summary>

```
// N-choose-R
int NCR(int N, int R){
    double ans = 1;
    R = min(R, N-R);
    for (int numer=N-R+1, denom = 1; denom <= R; numer++,denom++){
        ans = (ans * numer) / denom;
    }
    return (int)ans;
}
```

</details>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://blog.gomchik.com/tech/c++/utils.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
