commit ef10c588088cb5142c3934ac58f56b7c9f550945
parent 4258166ff396066bb906d70ccedc0f5e46643b7e
Author: Amit Dutta <amitdutta4255@gmail.com>
Date: Wed, 3 Jun 2026 20:15:47 +0530
added more
Diffstat:
3 files changed, 71 insertions(+), 0 deletions(-)
diff --git a/semester_1/practice-c/external_6.c b/semester_1/practice-c/external_6.c
@@ -0,0 +1,28 @@
+// 6. Write a program to compute the factors of a given number.
+
+#include<stdio.h>
+
+void factor(int);
+
+int main() {
+ int n;
+ printf("Enter a number: ");
+ scanf("%d", &n);
+ factor(n);
+ return 0;
+}
+
+void factor(int n) {
+ int i;
+ printf("\nThe factors of %d = ", n);
+ if(n == 0) {
+ printf("Infinite.");
+ return;
+ }
+ if (n < 0) n = -n;
+ for(i = 1; i <= n; i++) {
+ if(n % i == 0) {
+ printf("%d %d ", i, -i);
+ }
+ }
+}+
\ No newline at end of file
diff --git a/semester_1/practice-c/external_7.c b/semester_1/practice-c/external_7.c
@@ -0,0 +1,20 @@
+// 7. Write a program to swap two numbers using a macro.
+
+#include<stdio.h>
+
+#define SWAP(a, b) \
+ do { \
+ __typeof__(a) temp = a; \
+ a = b; \
+ b = temp; \
+ } while (0) \
+
+int main() {
+ int a, b;
+ printf("Enter two number: ");
+ scanf("%d %d", &a, &b);
+ printf("\nA = \'%d\', B = \'%d\'", a, b);
+ SWAP(a, b);
+ printf("\nA = \'%d\', B = \'%d\'", a, b);
+ return 0;
+}+
\ No newline at end of file
diff --git a/semester_1/practice-c/external_8.c b/semester_1/practice-c/external_8.c
@@ -0,0 +1,21 @@
+// 8. Write a program to print a triangle of stars (take number of lines from user).
+
+#include <stdio.h>
+
+int main() {
+ int rows, i, j, k;
+
+ printf("Enter the number of lines: ");
+ scanf("%d", &rows);
+
+ for (i = 1; i <= rows; i++) {
+ for(j = 1; j <= rows - i; j++) {
+ printf(" ");
+ }
+ for (k = 1; k <= i; k++) {
+ printf("* ");
+ }
+ printf("\n");
+ }
+ return 0;
+}