Wednesday, 17 September 2025

SPARSE MATRIX

  • A matrix is just a table of numbers (rows × columns).

  • A sparse matrix is a matrix where most of the elements are 0.

  • Instead of storing all elements (including 0s), we store only the non-zero elements with their row, column, and value.


Matrix (4 × 4):  

         0 1   2  3

   0    0  0  3  0

   1    0  0  0  0

   2   0  4  0  5

   3   7  0  0  0

 most values are 0.

Only these are non-zero:

   Value at(Row,Col)

  • 3 at (0,2)

  • 4 at (2,1)

  • 5 at (2,3)

  • 7 at (3,0)

   

        0           1      2

        Row   Col   Value

   0      0          2     3

    1     2          1     4

    2     2          3     5

    3     3           0     7



[

 At(Row,column)                                                                                   Value

At (0,2) → compact[0][0]=0, compact[1][0]=2, compact[2][0]=3]




#include <stdio.h>


int main() {

    int rows = 4, cols = 4;

    

    // Original sparse matrix

    int sparse[4][4] = {

        {0, 0, 3, 0},

        {0, 0, 0, 0},

        {0, 4, 0, 5},

        {7, 0, 0, 0}

    };


// Count non-zero elements

    int size = 0; //size is used to count how many non-zero elements

    for (int i = 0; i < rows; i++)

        for (int j = 0; j < cols; j++)

            if (sparse[i][j] != 0)

                size++;


   [    //Value at(Row,Col)

  • 3 at (0,2)                value = 3 → not zero → size = 1

  • 4 at (2,1)                value = 4 → not zero → size = 2

  • 5 at (2,3)                value = 5 → not zero → size = 3

  • 7 at (3,0)                value = 7 → not zero → size = 4 ]


 


 // Compact matrix (3 × size)

    int compact[3][size];// 3-> row,column,value

    int k = 0; // k keeps track of which column we are filling in the compact matrix


for (int i = 0; i < rows; i++) {

    for (int j = 0; j < cols; j++) {

        if (sparse[i][j] != 0) {

            compact[0][k] = i;             //  store Row index

            compact[1][k] = j;             // store Column index

            compact[2][k] = sparse[i][j];  // store  Value

            k++; //k++ → move to next column

        }

    }

}

[

 At(Row,column)                                                                                   Value

At (0,2) → compact[0][0]=0, compact[1][0]=2, compact[2][0]=3]


 // Print compact matrix

 printf("Row  Col  Value");

 for (int i = 0; i < size; i++) 

{

printf("%d    %d    %d\n", compact[0][i], compact[1][i], compact[2][i]);

    }

    return 0;

}








Tuesday, 9 September 2025

Print addition symbol in polynomials


#include <stdio.h>

int main() {

    int n; // Degree of the polynomial + 1

    printf("Enter the number of terms in the polynomial: ");

    scanf("%d", &n);


    int poly1[100]; // Array for polynomial coefficients


    // Input for the polynomial

    printf("Enter the coefficients of the polynomial:\n");

    for (int i = 0; i < n; i++) {

        printf("Coefficient of x^%d: ", i);

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

    }


    // Print polynomial

    printf("\nPolynomial is: ");

      for (int i = 0; i < n; i++) {

        printf("%d", poly1[i]);

        if (i != 0) {

            printf("x^%d", i); // Display power of x

        }

        if (i != n - 1) {

            printf(" + "); // Display '+' between terms in result

        }

    }   

    return 0;

}


Accept Coefficient value

 

#include<stdio.h>

int main() {

    int n; // Degree of the polynomial + 1

    printf("Enter the number of terms in the polynomials: ");

    scanf("%d", &n);

 

    int poly1[100]; // Arrays for the two polynomials and the result

 

    // Input for the first polynomial

    printf("Enter the coefficients of the first polynomial:\n");

    for (int i = 0; i < n; i++) {

        printf("Coefficient of x^%d: ", i);

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

    }

  

    return 0;

}

 

Accept Array and display array

#include <stdio.h>

 

int main() {

    int n, i;

 

    printf("Enter size of array: ");

    scanf("%d", &n);   // accept size

 

    int arr[n];   // declare array of size n

 

    // Input elements

    printf("Enter %d elements:\n", n);

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

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

    }

 

    // Output elements

    printf("Array elements are:\n");

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

        printf("%d ", arr[i]);

    }

 

    return 0;

}



 

Monday, 12 May 2025

Write four test cases for payment through a debit card option for an interactive web app, considering various positive and negative scenarios

 

  • Write four test cases for payment through a debit card option for an interactive web app, considering various positive and negative scenarios 
                                                                             
    Test Case 1: Valid Debit Card Details (Positive Scenario)
  • Test Case ID: TC001
  • Scenario: Successful payment with valid card details.
  • Test Steps:

1.      Navigate to the payment page.

2.      Select the "Debit Card" payment option.

3.      Enter valid debit card details:

§  Card Number: 16 digits

§  Expiry Date: Future date

§  CVV: 3 digits

4.      Click "Pay Now."

  • Expected Result:-Payment is processed successfully, and the user is redirected to the order confirmation page. A success message is displayed, and a confirmation email is sent to the user.

 

Test Case 2: Invalid Card Number (Negative Scenario)

  • Test Case ID: TC002
  • Scenario: Payment with an invalid card number.
  • Test Steps:

1.      Navigate to the payment page.

2.      Select the "Debit Card" payment option.

3.      Enter invalid debit card details:

§  Card Number: Less than 16 digits or contains alphabets/special characters

§  Expiry Date: Future date

§  CVV: 3 digits

4.      Click "Pay Now."

  • Expected Result:-Payment is not processed. An error message such as "Invalid card number. Please check and try again" is displayed.









Test Case 3: Expired Card (Negative Scenario)

  • Test Case ID: TC_DebitCard_003
  • Scenario: Payment with an expired debit card.
  • Test Steps:

1.      Navigate to the payment page.

2.      Select the "Debit Card" payment option.

3.      Enter debit card details:

§  Card Number: 16 digits

§  Expiry Date: Past date

§  CVV: 3 digits

4.      Click "Pay Now."

  • Expected Result:-Payment is not processed. An error message such as "Card has expired. Please use a valid card" is displayed.

 

Test Case 4: Insufficient Funds (Negative Scenario)

  • Test Case ID: TC_DebitCard_004
  • Scenario: Payment with a valid card but insufficient account balance.
  • Test Steps:

1.      Navigate to the payment page.

2.      Select the "Debit Card" payment option.

3.      Enter valid debit card details:

§  Card Number: 16 digits

§  Expiry Date: Future date

§  CVV: 3 digits

4.      Ensure the account associated with the card has insufficient funds.

5.      Click "Pay Now."

  • Expected Result:-Payment is not processed. An error message such as "Transaction declined due to insufficient funds" is displayed.