diff --git a/C++/Program_25/Queues_Using_Linked_Lists.cpp b/C++/Program_25/Queues_Using_Linked_Lists.cpp new file mode 100644 index 00000000..65cbca63 --- /dev/null +++ b/C++/Program_25/Queues_Using_Linked_Lists.cpp @@ -0,0 +1,82 @@ +//Queues Using Linked List +#include +using namespace std; + +class node{ + public: + int data; + node *link; +}*front=NULL,*rear=NULL; + +void enqueue(int x){ + node *t; + t = new node; + if(t==NULL) + cout<<"Queue is Full"<data = x; + t->link = NULL; + } + if(front==NULL){ + front = rear = t; + } + else{ + rear->link=t; + rear = t; + } +} + +int dequeue(){ + node *p; + int x = -1; + if(front==NULL) + cout<<"Queue is Empty!"<link; + x = p->data; + delete p; + } + return x; +} + +void display(){ + node *p=front; + while(p){ + cout<data<<" "; + p = p->link; + } + cout<>c; + switch (c) + { + case '1': + cout<<"Enter the element : "; + cin>>x; + enqueue(x); + break; + case '2': + x=dequeue(); + if(x!=-1) + cout<<"Deleted element is "< + +int main() +{ + + int array[100], n, c, d, swap; + + printf("Enter number of elements\n"); + scanf("%d", &n); + + printf("Enter %d integers\n", n); + + for (c = 0; c < n; c++) + scanf("%d", &array[c]); + + for (c = 0 ; c < ( n - 1 ); c++) + { + for (d = 0 ; d < n - c - 1; d++) + { + if (array[d] > array[d+1]) + { + swap = array[d]; + array[d] = array[d+1]; + array[d+1] = swap; + } + } + } + + printf("Sorted list in ascending order:\n"); + + for ( c = 0 ; c < n ; c++ ) + printf("%d\n", array[c]); + + printf("\nSorted list in descending order:\n"); + + for ( c = n-1 ; c >= 0; c-- ) + printf("%d\n", array[c]); + return 0; + + /* This Program calulates all the prime between the range of numbers includes the numbers which is provided. diff --git a/C/program-74/program.c b/C/program-74/program.c new file mode 100644 index 00000000..0c61fc16 --- /dev/null +++ b/C/program-74/program.c @@ -0,0 +1,15 @@ +#include + int main() +{ +int n, reverse=0, rem; +printf("Enter a number: "); + scanf("%d", &n); + while(n!=0) + { + rem=n%10; + reverse=reverse*10+rem; + n/=10; + } + printf("Reversed Number: %d",reverse); +return 0; +} \ No newline at end of file diff --git a/C/program-74/readme.md b/C/program-74/readme.md new file mode 100644 index 00000000..abdd17c1 --- /dev/null +++ b/C/program-74/readme.md @@ -0,0 +1 @@ +C Program to reverse a given number \ No newline at end of file diff --git a/C/program-77/program.c b/C/program-77/program.c new file mode 100644 index 00000000..7dcefe58 --- /dev/null +++ b/C/program-77/program.c @@ -0,0 +1,51 @@ +#include + +int main() +{ +int m, n, p, q, c, d, k, sum = 0; +int mat1[10][10], mat2[10][10], mat3[10][10]; + +printf(“Enter number of rows and columns of mat1 matrix\n”); +scanf(“%d%d”, &m, &n); +printf(“Enter elements of matrix 1\n”); + +for (c = 0; c < m; c++) +for (d = 0; d < n; d++) +scanf(“%d”, &mat1[c][d]); + +printf(“\nEnter number of rows and columns of mat2 matrix\n”); +scanf(“%d%d”, &p, &q); + +if (n != p) +printf(“\nThe matrices can’t be multiplied with each other.\n”); +else +{ +printf(“\nEnter elements of matrix2\n”); + +for (c = 0; c < p; c++) +for (d = 0; d < q; d++) +scanf(“%d”, &mat2[c][d]); + +for (c = 0; c < m; c++) { +for (d = 0; d < q; d++) { +for (k = 0; k < p; k++) { +sum = sum + mat1[c][k]*mat2[k][d]; +} + +mat3[c][d] = sum; +sum = 0; +} +} + +printf(“\nProduct of the matrices:\n”); + +for (c = 0; c < m; c++) { +for (d = 0; d < q; d++) +printf(“%d\t”, mat3[c][d]); + +printf(“\n”); +} +} + +return 0; +} \ No newline at end of file diff --git a/C/program-77/readme.md b/C/program-77/readme.md new file mode 100644 index 00000000..41afd4c7 --- /dev/null +++ b/C/program-77/readme.md @@ -0,0 +1 @@ +C program to multiply matrices \ No newline at end of file diff --git a/C/program-78/program.c b/C/program-78/program.c new file mode 100644 index 00000000..c82cb20b --- /dev/null +++ b/C/program-78/program.c @@ -0,0 +1,24 @@ +#include + +int main() +{ + printf("\n\n\t\tStudytonight - Best place to learn\n\n\n"); + int h, b; + float area; + printf("\n\nEnter the height of the Triangle: "); + scanf("%d", &h); + printf("\n\nEnter the base of the Triangle: "); + scanf("%d", &b); + + /* + Formula for the area of the triangle = (height x base)/2 + + Also, typecasting denominator from int to float + to get the output in float + */ + area = (h*b)/(float)2; + printf("\n\n\nThe area of the triangle is: %f", area); + + printf("\n\n\t\t\tCoding is Fun !\n\n\n"); + return 0; +} \ No newline at end of file diff --git a/C/program-78/readme.md b/C/program-78/readme.md new file mode 100644 index 00000000..e8e927d0 --- /dev/null +++ b/C/program-78/readme.md @@ -0,0 +1 @@ +C Program to find the Area of Triangle using Base and Height \ No newline at end of file diff --git a/C/program-79/program.c b/C/program-79/program.c new file mode 100644 index 00000000..1a3a9094 --- /dev/null +++ b/C/program-79/program.c @@ -0,0 +1,22 @@ +#include + +void main() +{ + printf("\n\n\t\tStudytonight - Best place to learn\n\n\n"); + float principal_amt, rate, simple_interest; + int time; + printf("Enter the value of principal amount, rate and time\n\n\n"); + scanf("%f%f%d", &principal_amt, &rate, &time); + + // considering rate is in percentage + simple_interest = (principal_amt*rate*time)/100.0; + + // usually used to align text in form of columns in table + printf("\n\n\t\t\tAmount = Rs.%7.3f\n ", principal_amt); + + printf("\n\n\t\t\tRate = Rs.%7.3f\n ", rate); + printf("\n\n\t\t\tTime= %d years \n", time); + printf("\n\n\t\t\tSimple Interest = Rs.%7.3f\n ", simple_interest); + printf("\n\n\t\t\tCoding is Fun !\n\n\n"); + return 0; +} \ No newline at end of file diff --git a/C/program-79/readme.md b/C/program-79/readme.md new file mode 100644 index 00000000..ec5e5b99 --- /dev/null +++ b/C/program-79/readme.md @@ -0,0 +1 @@ +C Program to calculate Simple Interest \ No newline at end of file diff --git a/Java/program-3/program.java b/Java/program-3/program.java index 95be6346..d9a3b280 100644 --- a/Java/program-3/program.java +++ b/Java/program-3/program.java @@ -1,3 +1,63 @@ +//Java Program to Find Transpose of a Matrix// + + + + + + +import java.util.Arrays; + +public class Matrix { + + // main method + public static void main(String[] args) { + + // declare and initialize a matrix + int a[][] = { { 1, 2 }, { 8, 9 } }; + + // find row and column size + int row = a.length; + int column = a[0].length; + + // declare new matrix to store result + int transpose[][] = new int[row][column]; + + // Transpose of matrix + transpose = transposeMatrix(a); + + // display all matrices + System.out.println("A = " + Arrays.deepToString(a)); + System.out.println("Transpose = " + + Arrays.deepToString(transpose)); + } + + // method to calculate the transpose of a matrix + public static int[][] transposeMatrix(int[][] a) { + + // calculate row and column size + int row = a.length; + int column = a[0].length; + + // declare a matrix to store resultant + int temp[][] = new int[row][column]; + + // calculate transpose of matrix + // outer loop for row + for (int i = 0; i < row; i++) { + // inner loop for column + for (int j = 0; j < column; j++) { + // formula + temp[i][j] = a[j][i]; + } + } + + // return resultant matrix + return temp; + } + +} + + import java.io.*; import java.util.*; class Prg{ diff --git a/Javascript/program-7/program.js b/Javascript/program-7/program.js new file mode 100644 index 00000000..ee78770a --- /dev/null +++ b/Javascript/program-7/program.js @@ -0,0 +1,17 @@ +// program to sort words in alphabetical order + +// take input +const string = prompt('Enter a sentence: '); + +// converting to an array +const words = string.split(' '); + +// sort the array elements +words.sort(); + +// display the sorted words +console.log('The sorted words are:'); + +for (const element of words) { + console.log(element); +} \ No newline at end of file diff --git a/Python/program-5/program.py b/Python/program-5/program.py new file mode 100644 index 00000000..0b2242ab --- /dev/null +++ b/Python/program-5/program.py @@ -0,0 +1,10 @@ +rows = int(input("Enter Same Number Rows & Columns Square Pattern Rows = ")) + +print("===Printing Same Number in Rows and Columns of a Square Pattern===") + +for i in range(1, rows + 1): + for j in range(i, rows + 1): + print(j, end = ' ') + for k in range(1, i): + print(k, end = ' ') + print() \ No newline at end of file