From dbfafdcd1a9e3feef3cd501ccecc66dc66d25a66 Mon Sep 17 00:00:00 2001 From: aadit_lab Date: Tue, 13 Aug 2024 11:27:43 +0530 Subject: [PATCH 1/3] More interactive code --- DS/C/Lab/Week4/circq.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/DS/C/Lab/Week4/circq.c b/DS/C/Lab/Week4/circq.c index 9c9eb83..baacf85 100644 --- a/DS/C/Lab/Week4/circq.c +++ b/DS/C/Lab/Week4/circq.c @@ -1,6 +1,6 @@ #include -#define MAX_SIZE 5 +#define MAX_SIZE 4 int queue[MAX_SIZE]; int front = 0; @@ -8,7 +8,7 @@ int rear = 0; void enqueue(int data) { if ((rear + 1) % MAX_SIZE == front) { - printf("Queue is full\n"); + printf("\n\nQueue is full\n\n\n"); return; } queue[rear] = data; @@ -41,11 +41,12 @@ void printQueue() { int main() { int choice, data; while (1) { + printf("Choose the Circular Queue option you would like to perform:\n"); printf("1. Enqueue\n2. Dequeue\n3. Print Queue\n4. Exit\n"); scanf("%d", &choice); switch (choice) { case 1: - printf("Enter data: "); + printf("Enter the value for the latest element: "); scanf("%d", &data); enqueue(data); break; @@ -58,6 +59,9 @@ int main() { break; case 4: return 0; + default: + printf("Invalid choice."); + return -1; } } } From f44fd64fd06ef6404daeaef3fd65c151eeec95d1 Mon Sep 17 00:00:00 2001 From: aadit_lab Date: Tue, 13 Aug 2024 11:28:31 +0530 Subject: [PATCH 2/3] Update DS/C/Lab/Week4/fasttranspose.c --- DS/C/Lab/Week4/fasttranspose.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/DS/C/Lab/Week4/fasttranspose.c b/DS/C/Lab/Week4/fasttranspose.c index ca43420..61712c7 100644 --- a/DS/C/Lab/Week4/fasttranspose.c +++ b/DS/C/Lab/Week4/fasttranspose.c @@ -31,10 +31,19 @@ int main() { struct Element b[MAX_TERMS]; int m = 4, n = 3, num = 4; + printf("The Original Matrix is:\n\n"); + printf("row col val\n"); + for (int i = 0; i < num; i++) + printf("%d\t%d\t%d\n", a[i].row, a[i].col, a[i].value); + + printf("\n\n"); fastTranspose(a, b, m, n, num); + printf("The Transpose Matrix is:\n\n"); + printf("row col val\n"); for (int i = 0; i < num; i++) - printf("%d %d %d\n", b[i].row, b[i].col, b[i].value); + printf("%d\t%d\t%d\n", b[i].row, b[i].col, b[i].value); return 0; } + From f8aace509b0cd9f7282325da49040520c653cc60 Mon Sep 17 00:00:00 2001 From: Aadit Agrawal Date: Sat, 31 Aug 2024 01:22:13 +0530 Subject: [PATCH 3/3] Update OOP/Java/Lab/Week3/Armstrong.java --- OOP/Java/Lab/Week3/Armstrong.java | 63 +++++++++++++------------------ 1 file changed, 26 insertions(+), 37 deletions(-) diff --git a/OOP/Java/Lab/Week3/Armstrong.java b/OOP/Java/Lab/Week3/Armstrong.java index 9f49448..7f8837b 100644 --- a/OOP/Java/Lab/Week3/Armstrong.java +++ b/OOP/Java/Lab/Week3/Armstrong.java @@ -1,37 +1,26 @@ -import java.util.Scanner; -import java.lang.Math; - -class Armstrong{ - public static void main(String args[]){ - Scanner sc = new Scanner(System.in); - - int a,b,digit; - int digisum=0; - int c=0; - - System.out.println("Enter the number you went to check for Armstrong-ness:"); - a = sc.nextInt(); - - b = a; - - while(b!=0){ - c++; - b/=10; - } - - b = a; - - while(b!=0){ - digit = b%10; - digisum += Math.pow(digit, c); - b /= 10; - } - - if(digisum == a){ - System.out.println("The number is an armstrong number."); - }else{ - System.out.println("The number is not an armstrong number."); - } - - } -} \ No newline at end of file +import java.util.Scanner; + +class Armstrong { + + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + + System.out.println("Enter a number"); + + int n = sc.nextInt(); + int b = String.valueOf(n).length(); + int sum = 0; + int temp = n; + while (temp > 0) { + int r = temp % 10; + sum += Math.pow(r, b); + temp /= 10; + } + if (sum == n) { + System.out.println("The given number is an Armstrong Number."); + } else { + System.out.println("The given number is not an Armstrong Number."); + } + sc.close(); + } +}