Code Examples

Example snippets and stuff

For loop

for(int i = 1; i < 65; i++) {
    printf("Current count is: %d\nCurrent total is: %llu\n", i, total);
    total += square(i);
}

While loop

Get number of digits in an int, then use the length to assign the memory for the char array

//Identify the number of digits in a number
nDigits = floor(log10(abs(num))) + 1;
printf("Number of digits is %d\n\n",nDigits);
total = 0;
//assign an array based on the number of digits
char Digits[nDigits];
//assign number as string in char pointer
sprintf((char*)Digits,"%u",num);

Convert each digit in an int to a char array

Last updated