Monday, April 28, 2025

C Program - Find Frequency of a Character in a String

This C program prompts the user to enter a string and a character, then calculates and displays the frequency of the character in the string. 

#include <stdio.h>

int main()
{

    char some_string[1000], ch;
    int counter = 0;

    printf("Enter Some String: \n");
    gets(some_string);

    printf("Enter a Character: \n");
    scanf("%c", &ch);

    for (int x = 0; some_string[x] != '\0'; x++)
    {
        if (ch == some_string[x])
        {
            counter++;
            //printf("Counter atm: %d ", counter);
            //printf("Detected :%c \n", ch);
        }
    }

    printf("Frequency of %c character: %d \n", ch, counter);

    return 0;
}

Result: 

Enter Some String:
this is some test
Enter a Character:
t
Frequency of t character: 3

Process returned 0 (0x0)   execution time : 5.396 s
Press any key to continue.

Here's a detailed explanation of each block of code in the program: 

#include <stdio.h>

This line includes the standard input-output library header file. 

int main()
{

This line declares the main function that runs when the program is executed. The int keyword specifies that the function returns an integer value (0 in this case). 

char some_string[1000], ch;
int counter = 0;

This block of code declares three variables:

  • some_string: a character array that can hold up to 1000 characters
  • ch: a single character variable to store the character to be searched for
  • counter: an integer variable that will be used to count the frequency of the character in the string 
printf("Enter Some String: \n");
gets(some_string);

These lines prompt the user to enter a string and then reads the input string into the some_string array using the gets() function. Note that gets() is generally considered unsafe to use because it can cause a buffer overflow if the user inputs more than the allocated space for some_string. It is recommended to use fgets() instead, which limits the amount of input read. 

printf("Enter a Character: \n");
scanf("%c", &ch);

These lines prompt the user to enter a character and then reads the input character into the ch variable using the scanf() function. 

for (int x = 0; some_string[x] != '\0'; x++)
{
    if (ch == some_string[x])
    {
        counter++;
    }
}

This block of code is a for loop that iterates over the characters in the some_string array using an index variable x. The loop continues until it reaches the null character '\0', which marks the end of the string. Inside the loop, the program checks if the current character at index x is equal to the character ch. If it is, the counter variable is incremented. 

printf("Frequency of %c character: %d \n", ch, counter);

This line uses printf() to display the frequency of the character in the string. The %c format specifier is used to print the character ch, and the %d format specifier is used to print the integer counter

return 0;

This line returns an integer value of 0 to the operating system to indicate that the program executed successfully.

C Program - Get the String Length with While Loop

This C program prompts the user to enter a string and then calculates and displays the length of the string. 

#include <stdio.h>

int main()
{

    char some_string[100];
    int x;

    printf("Enter Some String: \n");
    scanf("%s", some_string);

    while (some_string[x] != '\0')
    {
        x++;
    }
    printf("Total Length: %d \n", x);

    return 0;
}

Result: 

Enter Some String:
something
Total Length: 9

Process returned 0 (0x0)   execution time : 2.677 s
Press any key to continue.
Line by line explanation: 
#include <stdio.h>

This line includes the standard input-output library header file, which is needed for using standard functions like printf() and scanf()

int main()
{

This is the starting point of the program where the main() function is defined. This function is required in every C program and serves as the entry point of the program. The function signature int main() indicates that the function returns an integer value upon completion. 

    char some_string[100];
    int x;

This code block declares two variables: some_string, which is a character array of size 100 and x, which is an integer variable. 

    printf("Enter Some String: \n");
    scanf("%s", some_string);

These lines of code print a prompt to the user to enter a string using printf() and then reads in the input string using scanf(). %s format specifier in the scanf() function indicates that it will read in a string of characters from the user. 

    while (some_string[x] != '\0')
    {
        x++;
    }

This code block uses a while loop to iterate through the character array some_string until it reaches the null character '\0'. The null character marks the end of a C-style string. In each iteration, the loop increments the value of the x variable, which keeps track of the number of characters in the string. 

    printf("Total Length: %d \n", x);
    return 0;
}

Finally, this code block uses printf() to display the length of the string by printing the value of the x variable. The program then returns 0 to indicate successful execution of the program.

C Program – Find Length of a String without strlen() Function

This program takes a string input from the user using the scanf() function and stores it in the some_string character array. It then uses a for loop to iterate over the characters of the string until it encounters the null terminator character '\0'. During each iteration of the loop, it prints the length of the string up to that point using the printf() function.

Therefore, the program calculates and outputs the length of the input string entered by the user.

#include <stdio.h>

int main()
{

    char some_string[100];
    int x;

    printf("Enter Some String: \n");
    scanf("%s", some_string);

    for(x = 0; some_string[x]!='\0'; x++)
    {
        printf("Length atm: %d \n", x+1);
    }

    return 0;
}

Result: 

Enter Some String:
test
Length atm: 1
Length atm: 2
Length atm: 3
Length atm: 4

Process returned 0 (0x0)   execution time : 1.031 s
Press any key to continue.

Here's a line-by-line explanation of the code: 

#include <stdio.h>

This line includes the standard input/output library, which contains functions for input/output operations. 

int main()
{

This is the beginning of the main function, which is the entry point for the program. 

    char some_string[100];
    int x;

Here, we declare a character array variable named some_string that can hold up to 100 characters and an integer variable named x that will be used to keep track of the loop iterations. 

    printf("Enter Some String: \n");
    scanf("%s", some_string);

This code prompts the user to enter a string and stores it in the some_string variable using the scanf() function. 

    for(x = 0; some_string[x]!='\0'; x++)
    {
        printf("Length atm: %d \n", x+1);
    }

This is a for loop that iterates through the string some_string until it encounters the null character \0, which marks the end of the string. The loop body simply prints the current length of the string on each iteration, starting from 1 because the x variable starts at 0. 

    return 0;
}

This line simply ends the program and returns 0 to indicate successful execution.

C Program - Power of a Number for Elements inside C Array

This C program calculates the power of each element in an array to a fixed exponent and displays the results. 

#include <stdio.h>
#include <math.h>

int main()
{

    int numbers[] = {2, 3, 4, 5, 6};
    int exponent = 3;

    int number_of_elements = sizeof(numbers)/sizeof(numbers[0]);

    printf("Number of elements: %d \n", number_of_elements);

    for (int x = 0; x < number_of_elements; x++)
    {
        printf("Number: %d, Exponent: %d, Result: %d \n", numbers[x], exponent, (int)pow(numbers[x], exponent));
    }

    return 0;

}

Result: 

Number of elements: 5
Number: 2, Exponent: 3, Result: 8
Number: 3, Exponent: 3, Result: 27
Number: 4, Exponent: 3, Result: 64
Number: 5, Exponent: 3, Result: 125
Number: 6, Exponent: 3, Result: 216

Process returned 0 (0x0)   execution time : 0.078 s
Press any key to continue.

Here's a line-by-line explanation of the code: 

#include <stdio.h>
#include <math.h>

These are header files which provide the necessary libraries to perform input/output operations and mathematical calculations using the pow() function. 

int main()
{
    int numbers[] = {2, 3, 4, 5, 6};
    int exponent = 3;

    int number_of_elements = sizeof(numbers)/sizeof(numbers[0]);

This declares an integer array numbers and initializes it with some values. It also declares an integer variable exponent and initializes it to 3. The number_of_elements variable is initialized to the size of the numbers array divided by the size of one element in the array. 

    printf("Number of elements: %d \n", number_of_elements);

    for (int x = 0; x < number_of_elements; x++)
    {
        printf("Number: %d, Exponent: %d, Result: %d \n", numbers[x], exponent, (int)pow(numbers[x], exponent));
    }

    return 0;
}

This displays the number of elements in the numbers array using printf(). Then, it loops through each element in the numbers array using a for loop, calculates the power of the element raised to the exponent using the pow() function from the math.h library, and displays the result using printf(). Finally, the program ends with a return value of 0.

C Program - Calculate Power of a Number using pow() function

This C program calculates the power of a base number raised to an exponent entered by the user, using the pow() function from the math.h library.

It prompts the user to enter the base number and exponent using printf() and scanf(), respectively. It then uses the pow() function to calculate the power of the base number raised to the exponent and stores the result in the result variable.

After that, it displays the final result using printf() statement.

#include <stdio.h>
#include <math.h>

int main()
{

    int base_number, exponent, result;

    printf("Enter the Base Number: \n");
    scanf("%d", &base_number);

    printf("Enter Exponent: \n");
    scanf("%d", &exponent);

    result = pow(base_number, exponent);

    printf("%d to the Power of %d is: %d \n", base_number, exponent, result);

    return 0;

}

Result: 

Enter the Base Number:
10
Enter Exponent:
3
10 to the Power of 3 is: 1000

Process returned 0 (0x0)   execution time : 2.725 s
Press any key to continue.

Here's an explanation of the code line by line: 

#include <stdio.h>
#include <math.h>

These two lines include the standard input-output library and the math library in C programming. 

int main()
{
    int base_number, exponent, result;

This is the main function of the program. It declares three integer variables: base_number, exponent, and result

    printf("Enter the Base Number: \n");
    scanf("%d", &base_number);

    printf("Enter Exponent: \n");
    scanf("%d", &exponent);

These printf() statements display prompts for the user to enter the base_number and exponent values respectively. The scanf() function reads in integer values for these variables from the user input using the %d format specifier. 

    result = pow(base_number, exponent);

This line uses the pow() function from the math.h library to calculate the power of the base_number raised to the exponent. The pow() function returns a double value, which is then stored in the integer variable result

    printf("%d to the Power of %d is: %d \n", base_number, exponent, result);

    return 0;
}

This printf() statement displays the final result of the calculation, which is the base_number raised to the exponent, using the %d format specifier to print integer values. The program ends with a return value of 0.

C Program - Calculate Power of a Number using While Loop

This C program calculates the power of a base number raised to an exponent entered by the user.

It prompts the user to enter the base number and exponent using printf() and scanf(), respectively. It then uses a while loop to calculate the power of the base number raised to the exponent. Inside the loop, it multiplies the result variable by base_number for each iteration until the temp_exponent reaches 0.

After the loop, it prints the final value of result using printf().

#include <stdio.h>

int main()
{

    int base_number, exponent;
    int result = 1;

    printf("Enter the Base Number: \n");
    scanf("%d", &base_number);

    printf("Enter Exponent: \n");
    scanf("%d", &exponent);

    int temp_exponent = exponent;

    while (temp_exponent != 0)
    {
        result = result * base_number;
        printf("Result atm: %d \n", result);
        printf("Exponent atm: %d \n", temp_exponent);
        --temp_exponent;
    }

    printf("Final Result: %d \n", result);

    return 0;
}

Result: 

Enter the Base Number:
10
Enter Exponent:
3
Result atm: 10
Exponent atm: 3
Result atm: 100
Exponent atm: 2
Result atm: 1000
Exponent atm: 1
Final Result: 1000

Process returned 0 (0x0)   execution time : 4.000 s
Press any key to continue.

Here's an explanation of the code line by line: 

#include <stdio.h>

This line includes the standard input-output library in C programming. 

int main()
{
    int base_number, exponent;
    int result = 1;

This is the main function of the program. It declares three integer variables: base_number, exponent, and result. result is initialized to 1. 

    printf("Enter the Base Number: \n");
    scanf("%d", &base_number);

    printf("Enter Exponent: \n");
    scanf("%d", &exponent);

These printf() statements display prompts for the user to enter the base_number and exponent values respectively. The scanf() function reads in integer values for these variables from the user input using the %d format specifier. 

    int temp_exponent = exponent;

    while (temp_exponent != 0)
    {
        result = result * base_number;
        printf("Result atm: %d \n", result);
        printf("Exponent atm: %d \n", temp_exponent);
        --temp_exponent;
    }

This while loop executes result = result * base_number for each value of temp_exponent from exponent down to 0. The --temp_exponent expression decrements temp_exponent by 1 at the end of each iteration of the loop. Inside the loop, printf() statements display the current value of result and temp_exponent

    printf("Final Result: %d \n", result);

    return 0;
}

After the loop is completed, the final value of result is displayed using printf(). The program ends with a return value of 0.

C Program - Display All Alphabets And SKIP Special Characters

This is a C program that displays the ASCII codes and corresponding characters for all the alphabets in the English language.  

#include <stdio.h>

int main()
{

    int x;

    for (x = 65; x <= 122; x++)
    {
        if (x != 91 &&
                x != 92 &&
                x != 93 &&
                x != 94 &&
                x != 95 &&
                x != 96)
        {
            printf("%d <--> %c \n", x, x);
        }
        else
        {
            printf("%d <--> %c character is not an alphabet. \n ", x, x);
        }
    }

    return 0;
}

Result: 

65 <--> A
66 <--> B
67 <--> C
68 <--> D
69 <--> E
70 <--> F
71 <--> G
72 <--> H
73 <--> I
74 <--> J
75 <--> K
76 <--> L
77 <--> M
78 <--> N
79 <--> O
80 <--> P
81 <--> Q
82 <--> R
83 <--> S
84 <--> T
85 <--> U
86 <--> V
87 <--> W
88 <--> X
89 <--> Y
90 <--> Z
91 <--> [ character is not an alphabet.
 92 <--> \ character is not an alphabet.
 93 <--> ] character is not an alphabet.
 94 <--> ^ character is not an alphabet.
 95 <--> _ character is not an alphabet.
 96 <--> ` character is not an alphabet.
 97 <--> a
98 <--> b
99 <--> c
100 <--> d
101 <--> e
102 <--> f
103 <--> g
104 <--> h
105 <--> i
106 <--> j
107 <--> k
108 <--> l
109 <--> m
110 <--> n
111 <--> o
112 <--> p
113 <--> q
114 <--> r
115 <--> s
116 <--> t
117 <--> u
118 <--> v
119 <--> w
120 <--> x
121 <--> y
122 <--> z

Process returned 0 (0x0)   execution time : 0.073 s
Press any key to continue.

Here's a detailed explanation of the code, line by line: 

#include <stdio.h>

This line includes the standard input-output library in C programming.

int main()
{
    int x;

This is the main function of the program. It declares an integer variable x

    for (x = 65; x <= 122; x++)
    {

This is a for loop that starts with x being assigned a value of 65, which is the ASCII code for the uppercase letter "A". The loop will continue as long as x is less than or equal to the ASCII code for the lowercase letter "z", which is 122. 

        if (x != 91 && x != 92 && x != 93 && x != 94 && x != 95 && x != 96)
        {
            printf("%d <--> %c \n", x, x);
        }

This block of code uses if statements to check if x is not one of the ASCII codes for the non-alphabetic characters '[', '', ']', '^', '_', and ''. If xis not one of these characters, theprintf()function will print the ASCII code and the corresponding character using the%dand%c` format specifiers. 

        else
        {
            printf("%d <--> %c character is not an alphabet. \n ", x, x);
        }

If x is one of the non-alphabetic characters, the printf() function will print the ASCII code and the corresponding character along with the message "character is not an alphabet". 

    }
    return 0;
}

This is the end of the for loop. After the loop is completed, the program ends with a return value of 0.

C Program - Convert Uppercase String to Lowercase String

This is a C program that converts uppercase letters in a string to lowercase letters.

#include <stdio.h>
#include <string.h>

int main()
{

    char some_string[100];
    int x;

    printf("Enter the String: \n");
    scanf("%s", some_string);

    for (x = 0; x <= strlen(some_string); x++)
    {
        if (some_string[x] >= 65 && some_string[x] <= 90)
        {
            some_string[x] = some_string[x] + 32;
            printf("Individual character: %d <--> %c \n", some_string[x], some_string[x]);
        }
    }

    printf("Lowercase: %s\n", some_string);

    return 0;
}

Result :

Enter the String:
SOMETHING
Individual character: 115 <--> s
Individual character: 111 <--> o
Individual character: 109 <--> m
Individual character: 101 <--> e
Individual character: 116 <--> t
Individual character: 104 <--> h
Individual character: 105 <--> i
Individual character: 110 <--> n
Individual character: 103 <--> g
Lowercase: something

Process returned 0 (0x0)   execution time : 4.172 s
Press any key to continue.

Let's go through the code line by line to understand how it works: 

#include <stdio.h>
#include <string.h>

These are header files that are needed to use standard input/output functions and string manipulation functions. 

int main()
{
    char some_string[100];
    int x;
    
    printf("Enter the String: \n");
    scanf("%s", some_string);

This is the main function of the program. It declares a character array called some_string of size 100 and an integer variable x. The printf function displays the message "Enter the String: " on the screen. The scanf function reads a string input from the user and stores it in the some_string array. 

    for (x = 0; x <= strlen(some_string); x++)
    {
        if (some_string[x] >= 65 && some_string[x] <= 90)
        {
            some_string[x] = some_string[x] + 32;
            printf("Individual character: %d <--> %c \n", some_string[x], some_string[x]);
        }
    }

This is a for loop that iterates through each character in the some_string array using an index variable x. The strlen function returns the length of the string in some_string.

The loop checks if the current character in some_string is an uppercase letter by comparing its ASCII value to the ASCII values of 'A' (65) and 'Z' (90). If the character is an uppercase letter, it is converted to lowercase by adding 32 to its ASCII value, which corresponds to the difference between the uppercase and lowercase letters in the ASCII table.

The printf function displays the individual character that has been converted to lowercase along with its ASCII code. 

    printf("Lowercase: %s\n", some_string);
    return 0;
}

After the for loop has finished iterating through the characters in the string, the final lowercase string is displayed using the printf function, and the program ends with a return value of 0.

C Program - Convert Lowercase String to Uppercase String

 This program takes a string input from the user and converts all the lowercase characters in the string to uppercase characters.

#include<stdio.h>
#include<string.h>

int main()
{

    char some_string[100];
    int x;

    printf("Enter the String:");
    scanf("%s", some_string);

    for(x = 0; x <= strlen(some_string); x++)
    {
        if (some_string[x] >= 97 && some_string[x] <= 122)
            some_string[x] = some_string[x] - 32;
    }

    printf("\nUppercase is: %s", some_string);

    return 0;
}

Result: 

Enter the String:something

Uppercase is: SOMETHING
Process returned 0 (0x0)   execution time : 4.734 s
Press any key to continue.

Here is a block by block explanation of the code: 

#include <stdio.h>
#include <string.h>

int main()
{

This code block includes the necessary header files and declares the main function. 

    char some_string[100];
    int x;

This declares a character array to store the input string and an integer variable to iterate over the string. 

    printf("Enter the String:");
    scanf("%s", some_string);

This prompts the user to enter a string and reads the input string into the some_string character array. 

    for(x = 0; x <= strlen(some_string); x++)
    {
        if (some_string[x] >= 97 && some_string[x] <= 122)
            some_string[x] = some_string[x] - 32;
    }

This loop iterates through the input string and converts any lowercase characters to uppercase. The strlen() function is used to determine the length of the string. The if statement checks whether the character is a lowercase letter by comparing its ASCII code to the values for lowercase letters. If it is, it is converted to uppercase by subtracting 32 from its ASCII code. 

    printf("\nUppercase is: %s", some_string);

    return 0;
}

Finally, this code block prints the converted string to the console and returns 0 to indicate successful program execution.

C Program - Check whether an Alphabet is Vowel or Consonant

This C program checks whether a given character is a vowel or a consonant.

#include <stdio.h>
#include <stdbool.h>

int main()
{
    char ch;
    bool isVowel = false;

    printf("Enter Character: \n");
    scanf("%c",&ch);

    if(ch =='a'||ch=='A'||ch=='e'||ch=='E'||ch=='i'||ch=='I'
            ||ch=='o'||ch=='O'||ch=='u'||ch=='U')
    {
        isVowel = true;
    }

    if (isVowel == true)
    {
        printf("%c is a Vowel", ch);
    }
    else
    {
        printf("%c is a Consonant", ch);
    }

    return 0;
}

Result: 

Enter Character:
b
b is a Consonant
Process returned 0 (0x0)   execution time : 3.969 s
Press any key to continue.

One more time:

Enter Character:
e
e is a Vowel
Process returned 0 (0x0)   execution time : 1.785 s
Press any key to continue.

Here's a line-by-line explanation: 

#include <stdio.h>
#include <stdbool.h>

These lines include the standard input/output library header file and the header file for the bool data type. 

int main()
{
    char ch;
    bool isVowel = false;

This declares the main function and two variables ch and isVowel. ch is a character variable to store the input character and isVowel is a boolean variable to store whether the input character is a vowel or not. 

    printf("Enter Character: \n");
    scanf("%c",&ch);

These lines prompt the user to enter a character and read its value from the standard input using the scanf() function. 

    if(ch =='a'||ch=='A'||ch=='e'||ch=='E'||ch=='i'||ch=='I'
            ||ch=='o'||ch=='O'||ch=='u'||ch=='U')
    {
        isVowel = true;
    }

This if statement checks if the input character is a vowel. If the character is a vowel, the boolean variable isVowel is set to true

    if (isVowel == true)
    {
        printf("%c is a Vowel", ch);
    }
    else
    {
        printf("%c is a Consonant", ch);
    }

This if-else statement checks the value of the isVowel variable. If it is true, the program prints that the input character is a vowel; otherwise, it prints that the input character is a consonant. 

    return 0;
}

This line indicates the end of the main() function and returns 0, indicating that the program has executed successfully.

C Program - Check if Numbers are Even in Range from 1 to n

This C program prints all even numbers in the range from 1 to n.  

#include <stdio.h>

int main ()
{

    int x, number;

    printf("Range from 1 to n: \n");
    scanf("%d", &number);

    for (x = 1; x <= number; x++)
    {
        if (x % 2 == 0)
        {
            printf("%d \n", x);
        }
    }

    return 0;
}

Result:

Range from 1 to n:
10
2
4
6
8
10

Process returned 0 (0x0)   execution time : 1.031 s
Press any key to continue.

Here's a line-by-line explanation: 

#include <stdio.h>

This line includes the standard input/output library header file. 

int main ()
{

This line defines the main function of the program. 

    int x, number;

This line declares two integer variables x and number

    printf("Range from 1 to n: \n");
    scanf("%d", &number);

These lines prompt the user to enter the value of number and read its value from the standard input using the scanf() function. 

    for (x = 1; x <= number; x++)
    {
        if (x % 2 == 0)
        {
            printf("%d \n", x);
        }
    }

This for loop iterates over all integers from 1 to number (inclusive) and prints the even numbers using the printf() function. The if statement checks whether x is even or not by checking whether x % 2 is equal to 0. If x is even, it is printed to the standard output. 

    return 0;
}

This line indicates the end of the main() function and returns 0, indicating that the program has executed successfully.

C Program - Check if Number is Even or Odd

 This C program takes an integer as input and checks whether it is an even or odd number.

#include<stdio.h>

int main()
{

    int number;

    printf("Enter an Integer: ");
    scanf("%d",&number);

    if ( number % 2 == 0 )
    {
        printf("%d is an even number", number);
    }
    else
    {
        printf("%d is an odd number", number);
    }

    return 0;
}

Result:

Enter an Integer: 2
2 is an even number
Process returned 0 (0x0)   execution time : 2.739 s
Press any key to continue.

One more time: 

Enter an Integer: 5
5 is an odd number
Process returned 0 (0x0)   execution time : 1.359 s
Press any key to continue.

Let's go through it line by line:

 
#include<stdio.h>

 

This line includes the standard input/output header file.

 
int main()
{

 

This line defines the main function of the program.

 
    int number;

 

This line declares an integer variable number which will store the user input.

 
    printf("Enter an Integer: ");
    scanf("%d",&number);

 

These lines print a message asking the user to enter an integer and read the integer input from the user using the scanf() function. %d is the format specifier used to read an integer input from the user.

 
    if ( number % 2 == 0 )
    {
        printf("%d is an even number", number);
    }
    else
    {
        printf("%d is an odd number", number);
    }

 

This if-else statement checks whether the entered number is even or odd. The % operator calculates the remainder of dividing the entered number by 2. If the remainder is 0, the number is even, and the program prints the message "number is an even number" using the printf() function. If the remainder is not 0, the number is odd, and the program prints the message "number is an odd number" using the printf() function.

 
    return 0;
}

 

This line indicates the end of the main() function and returns 0, indicating that the program has executed successfully.

C Program - Display Characters from A to Z Using For Loop

This C code block is a program that prints the ASCII codes and corresponding characters for uppercase and lowercase alphabets.

#include <stdio.h>

int main()
{

    char char_atm;

    printf("----------- \n");
    printf("Uppercase:  \n");
    printf("----------- \n");

    for (char_atm = 'A'; char_atm <= 'Z'; char_atm++)
    {
        printf("%d <--> %c \n", char_atm, char_atm);
    }

    printf("----------- \n");
    printf("Loweracse:  \n");
    printf("----------- \n");

    for (char_atm = 'a'; char_atm <= 'z'; char_atm++)
    {
        printf("%d <--> %c \n", char_atm, char_atm);
    }

    return 0;
}

Result: 

-----------
Uppercase:
-----------
65 <--> A
66 <--> B
67 <--> C
68 <--> D
69 <--> E
70 <--> F
71 <--> G
72 <--> H
73 <--> I
74 <--> J
75 <--> K
76 <--> L
77 <--> M
78 <--> N
79 <--> O
80 <--> P
81 <--> Q
82 <--> R
83 <--> S
84 <--> T
85 <--> U
86 <--> V
87 <--> W
88 <--> X
89 <--> Y
90 <--> Z
-----------
Loweracse:
-----------
97 <--> a
98 <--> b
99 <--> c
100 <--> d
101 <--> e
102 <--> f
103 <--> g
104 <--> h
105 <--> i
106 <--> j
107 <--> k
108 <--> l
109 <--> m
110 <--> n
111 <--> o
112 <--> p
113 <--> q
114 <--> r
115 <--> s
116 <--> t
117 <--> u
118 <--> v
119 <--> w
120 <--> x
121 <--> y
122 <--> z

Process returned 0 (0x0)   execution time : 0.109 s
Press any key to continue.

Let's go through it line by line: 

#include <stdio.h>

This line includes the standard input/output header file. 

int main()
{

This line defines the main function of the program. 

    char char_atm;

This line declares a character variable char_atm which will be used to store the alphabets. 

    printf("----------- \n");
    printf("Uppercase:  \n");
    printf("----------- \n");

These lines print a header indicating the following output will show the ASCII codes and corresponding characters for uppercase alphabets. 

    for (char_atm = 'A'; char_atm <= 'Z'; char_atm++)
    {
        printf("%d <--> %c \n", char_atm, char_atm);
    }

This for loop iterates through each uppercase alphabet from 'A' to 'Z', and for each alphabet, it prints the corresponding ASCII code and character using the printf() function. %d represents the ASCII code and %c represents the corresponding character. 

    printf("----------- \n");
    printf("Loweracse:  \n");
    printf("----------- \n");

These lines print a header indicating the following output will show the ASCII codes and corresponding characters for lowercase alphabets. 

    for (char_atm = 'a'; char_atm <= 'z'; char_atm++)
    {
        printf("%d <--> %c \n", char_atm, char_atm);
    }

This for loop iterates through each lowercase alphabet from 'a' to 'z', and for each alphabet, it prints the corresponding ASCII code and character using the printf() function. %d represents the ASCII code and %c represents the corresponding character. 

    return 0;
}

This line indicates the end of the main() function and returns 0, indicating that the program has executed successfully.

C Program - Multiplication Table of a Numbers in a Given Range

This C code block is a program that prints the multiplication table for a given starting number and stopping number.  

#include <stdio.h>

int main()
{

    int num1, num2;

    printf("Enter Starting Point: \n");
    scanf("%d", &num1);

    while (num2 <= 0)
    {
        printf("Enter Stoping Point: \n");
        scanf("%d", &num2);
    }

    printf("Multiplication rable for %d and %d \n", num1, num2);

    for (int x = 1; x <= num2; x++)
    {
        printf("%d * %d = %d \n", num1, x, num1 * x);
    }

    return 0;
}

Result: 

Enter Starting Point:
5
Enter Stoping Point:
15
Multiplication rable for 5 and 15
5 * 1 = 5
5 * 2 = 10
5 * 3 = 15
5 * 4 = 20
5 * 5 = 25
5 * 6 = 30
5 * 7 = 35
5 * 8 = 40
5 * 9 = 45
5 * 10 = 50
5 * 11 = 55
5 * 12 = 60
5 * 13 = 65
5 * 14 = 70
5 * 15 = 75

Process returned 0 (0x0)   execution time : 5.813 s
Press any key to continue.

Let's go through it line by line: 

#include <stdio.h>

This line includes the standard input/output header file. 

int main()
{

This line defines the main function of the program. 

    int num1, num2;

This line declares two integer variables num1 and num2 which will be used to store the starting and stopping points of the multiplication table. 

    printf("Enter Starting Point: \n");
    scanf("%d", &num1);

These lines prompt the user to enter the starting point of the multiplication table and store it in the variable num1 using the scanf() function. 

    while (num2 <= 0)
    {
        printf("Enter Stoping Point: \n");
        scanf("%d", &num2);
    }

These lines prompt the user to enter the stopping point of the multiplication table and store it in the variable num2 using the scanf() function. If the user enters a non-positive number, the program will continue prompting the user until a positive number is entered. 

    printf("Multiplication rable for %d and %d \n", num1, num2);

This line prints the starting and stopping points of the multiplication table. 

    for (int x = 1; x <= num2; x++)
    {
        printf("%d * %d = %d \n", num1, x, num1 * x);
    }

These lines use a for loop to iterate through each number in the multiplication table, from 1 to num2. For each number, the program calculates the product of num1 and the current number and prints it in the format of num1 * x = product

    return 0;
}

This line indicates the end of the main() function and returns 0, indicating that the program has executed successfully.

C Program - Generate Multiplication Table with User Input

 This program aims to generate a multiplication table for a given number that the user enters.

#include <stdio.h>

int main()
{

    int number, x;

    printf("Enter an integer: ");
    scanf("%d", &number);

    printf("Multiplication table of %d: \n", number);

    for (x = 1; x <= 10; x++)
    {
        printf("%d * %d = %d \n", number, x, number * x);
    }

    return 0;
}

Result: 

Enter an integer: 1
Multiplication table of 1:
1 * 1 = 1
1 * 2 = 2
1 * 3 = 3
1 * 4 = 4
1 * 5 = 5
1 * 6 = 6
1 * 7 = 7
1 * 8 = 8
1 * 9 = 9
1 * 10 = 10

Process returned 0 (0x0)   execution time : 4.505 s
Press any key to continue.

At first, the program declares two variables, number and x, both of type int. number is the input integer that the user enters, and x is used as a loop variable to iterate over the multiplication table.

Next, the program prompts the user to enter an integer by printing the message "Enter an integer: " using the printf function. Then, the scanf function is used to read the integer entered by the user and store it in the variable number.

After that, the program prints a message using printf to indicate the start of the multiplication table for the entered integer. It uses the value of number to generate the message by using a format specifier %d which is replaced by the value of number in the output message.

The core of the program is a for loop, which iterates over the multiplication table from 1 to 10. Within the for loop, the printf function is used to print the multiplication table of the entered number. It uses format specifiers %d and %d * %d = %d \n to generate the output message. %d is replaced by the value of number and x, and %d * %d = %d \n is replaced by the result of the multiplication. The \n at the end of the format specifier indicates that a new line should be added after each iteration of the loop.

Finally, the program ends by returning 0 to the operating system to indicate that the program has completed successfully.

Tkinter Introduction - Top Widget, Method, Button

First, let's make shure that our tkinter module is working ok with simple  for loop that will spawn 5 instances of blank Tk window .  ...