FYBCS C Exercise_10

Set A . Write C programs for the following problems. 

 1. Write a program to accept a matrix A of size mXn and store its transpose in matrix B. Display matrix B. Write separate functions. 

 2. Write a program to add and multiply two matrices. Write separate functions to accept,display, add and multiply the matrices. Perform necessary checks before adding and multiplying the matrices. 

Set B . Write C programs for the following problems. 

 1. Write a menu driven program to perform the following operations on a square matrix. Write separate functions for each option. 
i) Check if the matrix is symmetric.
ii) Display the trace of the matrix (sum of diagonal elements).
iii) Check if the matrix is an upper triangular matrix.
iv) Check if the matrix is a lower triangular matrix.
v) Check if it is an identity matrix.

2. Write a program to accept an mXn matrix and display an m+1 X n+1 matrix such that the m+1th row contains the sum of all elements of corresponding row and the n+1th column contains the sum of elements of the corresponding column.  
A                                     B
1      2      3                       1      2      3      6
4      5      6                       4      5      6      15
7      8      9                       7      8      9      24
                                         12    15    18    45

Set C. Write programs to solve the following problems 

 1. Pascal's triangle is a geometric arrangement of the binomial coefficients in a triangle. It is named after Blaise Pascal. Write a program to display n lines of the triangle. 
                  1 
               1    1 
            1   2    1 
         1   3    3   1 
      1   4    6   4   1
   1   5  10  10   5   1
 1  6  15  20  15   6  1 

Post a Comment

9 Comments

  1. import time

    def cls():
    for i in range(38):
    print()
    def red():
    print("RED")
    cls()
    time.sleep(2)
    green()
    def green():
    print("GREEN")
    cls()
    time.sleep(2)
    yellow()
    def yellow():
    print("YELLOW")
    cls()
    time.sleep(1)
    red()
    red()

    ReplyDelete
  2. class animal:
    def speak(self):
    print("Animal is speaking...")
    class dog(animal):
    def speak(self):
    print("Bhow Bhowwwww...")
    class cat(animal):
    def speak(self):
    print("Meow Meowwwww...")

    a = animal()
    d = dog()
    c = cat()
    a.speak()
    d.speak()
    c.speak()

    ReplyDelete
  3. #include
    using namespace std;

    struct Node {
    int data;
    Node* next;
    };

    // Function to create a new node
    Node* createNode(int data) {
    Node* newNode = new Node();
    newNode->data = data;
    newNode->next = nullptr;
    return newNode;
    }

    // Function to insert at the end
    void insertAtEnd(Node*& head, int data) {
    Node* newNode = createNode(data);
    if (head == nullptr) {
    head = newNode;
    newNode->next = head;
    } else {
    Node* temp = head;
    while (temp->next != head) {
    temp = temp->next;
    }
    temp->next = newNode;
    newNode->next = head;
    }
    }

    // Function to delete a node by value
    void deleteNode(Node*& head, int key) {
    if (head == nullptr) {
    cout << "List is empty." << endl;
    return;
    }
    Node* temp = head;
    Node* prev = nullptr;
    do {
    if (temp->data == key) {
    if (temp == head && temp->next == head) {
    delete head;
    head = nullptr;
    } else if (temp == head) {
    while (temp->next != head) temp = temp->next;
    temp->next = head->next;
    Node* toDelete = head;
    head = head->next;
    delete toDelete;
    } else {
    prev->next = temp->next;
    delete temp;
    }
    return;
    }
    prev = temp;
    temp = temp->next;
    } while (temp != head);
    cout << "Key not found." << endl;
    }

    // Function to display the list
    void displayList(Node* head) {
    if (head == nullptr) {
    cout << "List is empty." << endl;
    return;
    }
    Node* temp = head;
    do {
    cout << temp->data << " ";
    temp = temp->next;
    } while (temp != head);
    cout << endl;
    }

    // Main function
    int main() {
    Node* head = nullptr;

    // Insert elements
    insertAtEnd(head, 10);
    insertAtEnd(head, 20);
    insertAtEnd(head, 30);
    cout << "Circular Linked List: ";
    displayList(head);

    // Delete an element
    deleteNode(head, 20);
    cout << "After deleting 20: ";
    displayList(head);

    return 0;
    }

    ReplyDelete
  4. #include
    #include
    #include

    struct Node {
    int data;
    Node* next;
    };
    Node* createNode(int data) {
    Node* newNode = new Node();
    newNode->data = data;
    newNode->next = NULL;
    return newNode;
    }

    void insertAtEnd(Node*& head, int data) {
    Node* newNode = createNode(data);
    if (head == NULL) {
    head = newNode;
    newNode->next = head;
    } else {
    Node* temp = head;
    while (temp->next != head) {
    temp = temp->next;
    }
    temp->next = newNode;
    newNode->next = head;
    }
    }

    void deleteNode(Node*& head, int key) {
    if (head == NULL) {
    cout << "List is empty." << endl;
    return;
    }
    Node* temp = head;
    Node* prev = NULL;
    do {
    if (temp->data == key) {
    if (temp == head && temp->next == head) {
    delete head;
    head = nullptr;
    } else if (temp == head) {
    while (temp->next != head) temp = temp->next;
    temp->next = head->next;
    Node* toDelete = head;
    head = head->next;
    delete toDelete;
    } else {
    prev->next = temp->next;
    delete temp;
    }
    return;
    }
    prev = temp;
    temp = temp->next;
    } while (temp != head);
    cout << "Key not found." << endl;
    }

    void displayList(Node* head) {
    if (head == NULL) {
    cout << "List is empty." << endl;
    return;
    }
    Node* temp = head;
    do {
    cout << temp->data << " ";
    temp = temp->next;
    } while (temp != head);
    cout << endl;
    }

    void main() {
    Node* head =NULL;

    insertAtEnd(head, 10);
    insertAtEnd(head, 20);
    insertAtEnd(head, 30);
    cout << "Circular Linked List: ";
    displayList(head);

    deleteNode(head, 20);
    cout << "After deleting 20: ";
    displayList(head);

    getch();
    }

    ReplyDelete
  5. s = input("Enter a string with even number of characters: ")

    n = len(s)

    # Check even length
    if n % 2 != 0:
    print("Please enter a string with even number of characters.")
    else:
    half = n // 2 # midpoint
    first_half = s[:half] # first half
    second_half = s[half:] # second half
    result = first_half + second_half[::-1] # join with reversed second half

    print("Output:", result)

    ReplyDelete
  6. s = "ShardulJ"
    n = len(s)
    half = n // 2

    for i in range(0, half):
    print(s[i])

    second_half = s[half:]
    rev_second = second_half[::-1]

    for j in range(half, n):
    print(rev_second)

    ReplyDelete
  7. #Count how many object are created
    class Apple:
    count=0;
    def __init__(self):
    Apple.count+=1
    def show(self):
    print("Total object is",Apple.count)
    ob1=Apple()
    ob1.show()

    ob2=Apple()
    ob2.show()

    ob3=Apple()
    ob3.show()

    ReplyDelete
  8. #create two object and compair this and print who is greater
    class Student:
    def __init__(self,name,age):
    self.name=name
    self.age=age

    def compair(self,ref):
    if self.age>ref.age:
    print(self.name,"Is greater")
    else:
    print(ref.name,"Is greater")

    ob1=Student("Samadhan",25)
    ob2=Student("Adi",22)
    ob1.compair(ob2)

    ReplyDelete