C Program: Multiply Two 4×4 Matrices

#include <stdio.h>


int main() {

    int A[4][4], B[4][4], C[4][4];

    int i, j, k;


    // Input for first matrix A

    printf("Enter elements of first 4x4 matrix (A):\n");

    for(i = 0; i < 4; i++) {

        for(j = 0; j < 4; j++) {

            scanf("%d", &A[i][j]);

        }

    }


    // Input for second matrix B

    printf("Enter elements of second 4x4 matrix (B):\n");

    for(i = 0; i < 4; i++) {

        for(j = 0; j < 4; j++) {

            scanf("%d", &B[i][j]);

        }

    }


    // Multiply matrices A and B, store in C

    for(i = 0; i < 4; i++) {

        for(j = 0; j < 4; j++) {

            C[i][j] = 0;

            for(k = 0; k < 4; k++) {

                C[i][j] += A[i][k] * B[k][j];

            }

        }

    }


    // Display the result matrix C

    printf("Result of multiplication (A x B) is:\n");

    for(i = 0; i < 4; i++) {

        for(j = 0; j < 4; j++) {

            printf("%d\t", C[i][j]);

        }

        printf("\n");

    }


    return 0;

 Two Categories of Constants in C   

Primary Constants

These are the basic constants we use directly in a C program.

Types of Primary Constants:

  • Integer Constant → Example: 5, -10, 100

  • Float Constant → Example: 3.14, -2.5

  • Character Constant → Example: 'A', 'z', '9'

  • String Constant → Example: "Hello", "C programming"

Used for storing direct values in variables like:

c
int a = 10; // 10 is an integer constant 

char ch = 'A'; // 'A' is a character constant 

Secondary Constants

These are user-defined or derived constants.

Types of Secondary Constants:

  • Symbolic Constants → Created using #define
    Example: #define PI 3.14

  • Enumerations (enum) → Set of named integer constants
     Example:

    c
    enum day { SUN, MON, TUE };

In Simple Words:

CategoryWhat it isExample
PrimaryBasic constant values10, 'A', "C"
Secondary Defined by the user/programmer#define, enum



 C Program to Find Sum of the Series (1 + 4 + 7 + ... up to 20 terms)

#include <stdio.h>

int main() {

int n = 20;
int Sum = 0;
int Term 1; 
for(i = 1; i <= 20; i++) {
 sum += term;

  term += 3;         // Next term (add common difference)

    }

    // Print the result

    printf("Sum of the series up to 20 terms is: %d\n", sum);


    return 0;

}

C Program to Find the Length of a String Using Pointers

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

int main() {
char str [] = "Hello World";
int length;
length = strlen (str);

printf("Length of the string is: %d\n", length);


    return 0;

}

c

 #include <stdio.h>


int main() {

    int numbers[10];

    int i, search, found = 0;


    // Taking 10 numbers from user

    printf("Enter 10 numbers:\n");

    for(i = 0; i < 10; i++) {

        scanf("%d", &numbers[i]);

    }


    // Number to search

    printf("Enter a number to search: ");

    scanf("%d", &search);


    // Search the number in array

    for(i = 0; i < 10; i++) {

        if(numbers[i] == search) {

            found = 1;

            break;

        }

    }

    // Print result

    if(found) {

        printf("Square of %d is %d\n", search, search * search);

    } else {

        printf("The value is missing.\n");

    }


    return 0;

}

 Store and Display Student Details Using Structure

#include <stdio.h>

// Create structure for student

struct Student {

    char name[50];

    int roll;

    char address[100];

    char course[10];

};

int main() {

    struct Student s[10];

    int i;


    // Get student details

    for(i = 0; i < 10; i++) {

        printf("\nEnter details of student %d:\n", i + 1);


        printf("Name: ");

        scanf(" %[^\n]", s[i].name);


        printf("Roll Number: ");

        scanf("%d", &s[i].roll);


        printf("Address: ");

        scanf(" %[^\n]", s[i].address);


        printf("Course (BCA/MCA): ");

        scanf(" %[^\n]", s[i].course);

    }


    // Show student details

    printf("\n--- Student Details ---\n");

    for(i = 0; i < 10; i++) {

        printf("\nStudent %d\n", i + 1);

        printf("Name   : %s\n", s[i].name);

        printf("Roll   : %d\n", s[i].roll);

        printf("Address: %s\n", s[i].address);

        printf("Course : %s\n", s[i].course);

    }


    return 0;

 Algorithm to Calculate Simple Interest

Algorithm Steps

  1. Start

  2. Read Principal Amount, Time, and Rate 

  3. Calculate interest using the formula ((P*T*R)/100)

  4. Print Simple Interest

  5. Stop

    Flowchart:

    Start

    Input P, T, R

    Calculate SI = (P × T × R) / 100

    Display SI

    Stop