From 7c6e15b96144f02803142e443948eb8c64ddc852 Mon Sep 17 00:00:00 2001 From: "github-classroom[bot]" <66690702+github-classroom[bot]@users.noreply.github.com> Date: Tue, 2 Sep 2025 09:02:52 +0000 Subject: [PATCH 01/27] Setting up GitHub Classroom Feedback From 3bcbf66dad7be976273512ebb970da797e78d497 Mon Sep 17 00:00:00 2001 From: "github-classroom[bot]" <66690702+github-classroom[bot]@users.noreply.github.com> Date: Tue, 2 Sep 2025 09:02:55 +0000 Subject: [PATCH 02/27] add deadline --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 2b5538a..d3af9be 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,4 @@ +[![Review Assignment Due Date](https://classroom.github.com/assets/deadline-readme-button-22041afd0340ce965d47ae6ef1cefeee28c7c493a6346c4f15d667ab976d596c.svg)](https://classroom.github.com/a/LBh0h0yx) # Assignment 1: C Programming Basics ## Instructions From e6010d7093c00dbf22e8617c9b3bd7c15cea1dcb Mon Sep 17 00:00:00 2001 From: aadhikari-design Date: Thu, 4 Sep 2025 17:59:18 +0545 Subject: [PATCH 03/27] q1.c --- src/q1.c | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/src/q1.c b/src/q1.c index e9adc59..04a3465 100644 --- a/src/q1.c +++ b/src/q1.c @@ -1,6 +1,15 @@ -/* Write a C program that takes an integer input from the user and determines if it is positive, negative, or zero. -Expected Output: -If n > 0, print Positive (case-insensitive, extra messages allowed). -If n < 0, print Negative (case-insensitive, extra messages allowed). -If n == 0, print Zero (case-insensitive, extra messages allowed). -*/ \ No newline at end of file +#include +int main() { + int n; + printf("Enter an integer: "); + scanf("%d", &n); + + if (n > 0) + printf("The number is Positive.\n"); + else if (n < 0) + printf("The number is Negative.\n"); + else + printf("The number is Zero.\n"); + + return 0; +} From 5c3478193b664abe2b6ce12f806eecbcd6facb04 Mon Sep 17 00:00:00 2001 From: aadhikari-design Date: Thu, 4 Sep 2025 18:04:44 +0545 Subject: [PATCH 04/27] q2.c --- src/q2.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/q2.c b/src/q2.c index 30e6fa0..9b192e0 100644 --- a/src/q2.c +++ b/src/q2.c @@ -1,5 +1,13 @@ -/* Write a C program that prompts the user for their age and determines if they are eligible to vote (consider the legal voting age in your country). -Expected Output: -If age >= 18, print Eligible to vote (case-insensitive, extra messages allowed). -If age < 18, print Not eligible to vote (case-insensitive, extra messages allowed). -*/ \ No newline at end of file +#include +int main() { + int age; + printf("Enter your age: "); + scanf("%d", &age); + + if (age >= 18) + printf("Eligible to vote.\n"); + else + printf("Not eligible to vote.\n"); + + return 0; +} From 4757e152af2ca950d6eee319be70795b47bfcc1f Mon Sep 17 00:00:00 2001 From: aadhikari-design Date: Thu, 4 Sep 2025 18:05:48 +0545 Subject: [PATCH 05/27] q3.c --- src/q3.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/q3.c b/src/q3.c index f74a4ac..39bbca8 100644 --- a/src/q3.c +++ b/src/q3.c @@ -1 +1,12 @@ -// Write a C program that calculates the absolute value of a given number without using the built-in absolute value function. \ No newline at end of file +#include +int main() { + int n; + printf("Enter a number: "); + scanf("%d", &n); + + if (n < 0) + n = -n; + + printf("Absolute value: %d\n", n); + return 0; +} From 35649ef59585f611a0844d8438185135e4577b6e Mon Sep 17 00:00:00 2001 From: aadhikari-design Date: Thu, 4 Sep 2025 18:08:22 +0545 Subject: [PATCH 06/27] q4.c --- src/q4.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/q4.c b/src/q4.c index 35772e9..1a931a4 100644 --- a/src/q4.c +++ b/src/q4.c @@ -1 +1,13 @@ -// Write a C program that prints all even numbers between 1 and 100 using a for loop. \ No newline at end of file +#include +int main() { + int i; + + printf("Even numbers between 1 and 100 are:\n"); + + for(i = 2; i <= 100; i += 2) { + printf("%d ", i); + } + + printf("\n"); + return 0; +} From 3241a23629156ca8e8021487e290332c118dbb15 Mon Sep 17 00:00:00 2001 From: aadhikari-design Date: Thu, 4 Sep 2025 18:10:02 +0545 Subject: [PATCH 07/27] q5.c --- src/q5.c | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/src/q5.c b/src/q5.c index f89ed1d..92bcee5 100644 --- a/src/q5.c +++ b/src/q5.c @@ -1 +1,23 @@ -// Write a C program that prompts the user for a positive integer and calculates the factorial of that number using a while loop. \ No newline at end of file +#include + +int main() { + int n, i = 1; + unsigned long long factorial = 1; + + printf("Enter a positive integer: "); + scanf("%d", &n); + + if(n < 0) { + printf("Factorial is not defined for negative numbers.\n"); + return 1; + } + + while(i <= n) { + factorial *= i; + i++; + } + + printf("Factorial of %d is %llu\n", n, factorial); + + return 0; +} From ef2eba367e973d4db76d1e620aeb5e01967eb7f1 Mon Sep 17 00:00:00 2001 From: aadhikari-design Date: Thu, 4 Sep 2025 18:12:06 +0545 Subject: [PATCH 08/27] q4.c --- src/q4.c | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/src/q4.c b/src/q4.c index 1a931a4..1f4b51f 100644 --- a/src/q4.c +++ b/src/q4.c @@ -1,13 +1,10 @@ #include int main() { - int i; - - printf("Even numbers between 1 and 100 are:\n"); - - for(i = 2; i <= 100; i += 2) { - printf("%d ", i); +int i; +printf("Even numbers between 1 and 100 are:\n"); +for(i = 2; i <= 100; i += 2) { +printf("%d ", i); } - - printf("\n"); - return 0; + printf("\n"); +return 0; } From a6cf2347f447dcbb9b058e2f22ea13fea9e93718 Mon Sep 17 00:00:00 2001 From: aadhikari-design Date: Thu, 4 Sep 2025 18:16:06 +0545 Subject: [PATCH 09/27] q6.c --- src/q6.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/q6.c b/src/q6.c index 6b94dca..0ce436d 100644 --- a/src/q6.c +++ b/src/q6.c @@ -1 +1,17 @@ -// Write a C program that prompts the user for a number and prints its multiplication table up to 10 using a do-while loop. \ No newline at end of file +#include + +int main() { + int num, i = 1; + + printf("Enter a number: "); + scanf("%d", &num); + + printf("Multiplication table of %d:\n", num); + + do { + printf("%d x %d = %d\n", num, i, num * i); + i++; + } while(i <= 10); + + return 0; +} From c2db0df75cab2b37d8c381fc1ca7b15a6d2c7305 Mon Sep 17 00:00:00 2001 From: aadhikari-design Date: Thu, 4 Sep 2025 18:17:03 +0545 Subject: [PATCH 10/27] q7.c --- src/q7.c | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/src/q7.c b/src/q7.c index 3678e6f..d5afe42 100644 --- a/src/q7.c +++ b/src/q7.c @@ -1,11 +1,19 @@ -/* Write a C program that prints a pattern of asterisks. - * - ** - *** - **** - ***** - **** - *** - ** - * -*/ \ No newline at end of file +#include + +int main() { + int i, j; + int n = 5; +for(i = 1; i <= n; i++) { + for(j = 1; j <= i; j++) { + printf("*"); + } + printf("\n"); + } +for(i = n-1; i >= 1; i--) { + for(j = 1; j <= i; j++) { + printf("*"); + } + printf("\n"); + } +return 0; +} From 6425d43dcb3ba9d6e12e76e7da689c212b477bdf Mon Sep 17 00:00:00 2001 From: aadhikari-design Date: Thu, 4 Sep 2025 18:17:57 +0545 Subject: [PATCH 11/27] q8.c --- src/q8.c | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/src/q8.c b/src/q8.c index d9575f4..27a8031 100644 --- a/src/q8.c +++ b/src/q8.c @@ -1,7 +1,15 @@ -/* Write a C program that prints a pattern of asterisks. - * - ** - *** - **** - ***** -*/ \ No newline at end of file +#include + +int main() { + int i, j; + int n = 5; + + for(i = 1; i <= n; i++) { + for(j = 1; j <= i; j++) { + printf("*"); + } + printf("\n"); + } + + return 0; +} From ba3899d23ebcd7e454bb7d064106a8bd685f396a Mon Sep 17 00:00:00 2001 From: aadhikari-design Date: Thu, 4 Sep 2025 18:18:38 +0545 Subject: [PATCH 12/27] q9.c --- src/q9.c | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/src/q9.c b/src/q9.c index f4f89d0..e9cca37 100644 --- a/src/q9.c +++ b/src/q9.c @@ -1,7 +1,15 @@ -/* Write a C program that prints a pattern of asterisks. - ***** - **** - *** - ** - * -*/ \ No newline at end of file +#include + +int main() { + int i, j; + int n = 5; + + for(i = n; i >= 1; i--) { + for(j = 1; j <= i; j++) { + printf("*"); + } + printf("\n"); + } + + return 0; +} From 3faf730c9faf14ad8a99b3323dbc294f20486f4e Mon Sep 17 00:00:00 2001 From: aadhikari-design Date: Thu, 4 Sep 2025 18:19:12 +0545 Subject: [PATCH 13/27] q10.c --- src/q10.c | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/src/q10.c b/src/q10.c index 05a3fd8..2d12955 100644 --- a/src/q10.c +++ b/src/q10.c @@ -1,5 +1,18 @@ -/* Write a C program that prints a pattern of asterisks. - * - *** - ***** -*/ \ No newline at end of file +#include + +int main() { + int i, j, k; + int n = 3; + + for(i = 1; i <= n; i++) { + for(j = 1; j <= n - i; j++) { + printf(" "); + } + for(k = 1; k <= 2*i - 1; k++) { + printf("*"); + } + printf("\n"); + } + + return 0; +} From b7e78a8e36fc916afd1761609a1a90235cfbb43d Mon Sep 17 00:00:00 2001 From: aadhikari-design Date: Thu, 4 Sep 2025 18:24:48 +0545 Subject: [PATCH 14/27] q11.c --- src/q11.c | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/src/q11.c b/src/q11.c index 30824f6..ca9816e 100644 --- a/src/q11.c +++ b/src/q11.c @@ -1,5 +1,18 @@ -/* Write a C program that prints a pattern of asterisks. - ***** - *** - * -*/ \ No newline at end of file +#include + +int main() { + int i, j, k; + int n = 3; + + for(i = n; i >= 1; i--) { + for(j = 1; j <= n - i; j++) { + printf(" "); + } + for(k = 1; k <= 2*i - 1; k++) { + printf("*"); + } + printf("\n"); + } + + return 0; +} From 56911724aa66b727441bb51b3f4c2cc06797c9f2 Mon Sep 17 00:00:00 2001 From: aadhikari-design Date: Thu, 4 Sep 2025 18:25:22 +0545 Subject: [PATCH 15/27] q12.c --- src/q12.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/q12.c b/src/q12.c index ac47268..0047a8e 100644 --- a/src/q12.c +++ b/src/q12.c @@ -1 +1,11 @@ -// Write a C program that prints all numbers from 1 to 100 using a for loop. \ No newline at end of file +#include + +int main() { + int i; + + for(i = 1; i <= 100; i++) { + printf("%d\n", i); + } + + return 0; +} From 901478810740eaf48603e8d6c9260d3e82b3a35b Mon Sep 17 00:00:00 2001 From: aadhikari-design Date: Thu, 4 Sep 2025 18:27:17 +0545 Subject: [PATCH 16/27] q13.c --- src/q13.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/q13.c b/src/q13.c index 8009d54..d666476 100644 --- a/src/q13.c +++ b/src/q13.c @@ -1 +1,15 @@ -// Write a C program that calculates the sum of all even numbers from 1 to 50 using a while loop. \ No newline at end of file +#include + +int main() { + int i = 2; + int sum = 0; + + while(i <= 50) { + sum += i; + i += 2; + } + + printf("Sum of all even numbers from 1 to 50 is %d\n", sum); + + return 0; +} From f3e2074f812a1090e0d465948e6480a8540fbe5d Mon Sep 17 00:00:00 2001 From: aadhikari-design Date: Thu, 4 Sep 2025 18:27:57 +0545 Subject: [PATCH 17/27] q14.c --- src/q14.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/q14.c b/src/q14.c index 8f1a9d5..76834ae 100644 --- a/src/q14.c +++ b/src/q14.c @@ -1 +1,16 @@ -// Write a C program that prompts the user for a positive integer and prints all the factors of that number using a for loop. \ No newline at end of file +#include +int main() { +int num, i; + + printf("Enter a positive integer: "); + scanf("%d", &num); + + printf("Factors of %d are:\n", num); + for(i = 1; i <= num; i++) { + if(num % i == 0) { + printf("%d\n", i); + } + } + + return 0; +} From 3a79d00d79e76ecc374e64492029b71b8cb2a0a2 Mon Sep 17 00:00:00 2001 From: aadhikari-design Date: Thu, 4 Sep 2025 18:28:54 +0545 Subject: [PATCH 18/27] q15.c --- src/q15.c | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/src/q15.c b/src/q15.c index f582057..8316680 100644 --- a/src/q15.c +++ b/src/q15.c @@ -1 +1,27 @@ -// Write a C program that prompts the user for a positive integer and checks if it is a prime number using a while loop. \ No newline at end of file +#include + +int main() { + int num, i = 2, isPrime = 1; + + printf("Enter a positive integer: "); + scanf("%d", &num); + + if(num <= 1) { + isPrime = 0; + } + + while(i < num) { + if(num % i == 0) { + isPrime = 0; + break; + } + i++; + } + + if(isPrime) + printf("%d is a prime number.\n", num); + else + printf("%d is not a prime number.\n", num); + + return 0; +} From 368d2a41c4432edc0449872021145553e2d628ff Mon Sep 17 00:00:00 2001 From: aadhikari-design Date: Thu, 4 Sep 2025 18:29:41 +0545 Subject: [PATCH 19/27] q16.c --- src/q16.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/q16.c b/src/q16.c index af07832..9e51329 100644 --- a/src/q16.c +++ b/src/q16.c @@ -1 +1,18 @@ -// Write a C program that calculates the factorial of a given number using a do-while loop. \ No newline at end of file +#include +int main(){ + int num,i; + unsigned long long factorial=1; + printf("Enter a positive integer: "); + scanf("%d",&num); + i=1; + if(num<0){ + printf("Factorial is not defined for negative numbers.\n"); + }else{ + do{ + factorial*=i; + i++; + }while(i<=num); + printf("Factorial of %d is %llu\n",num,factorial); + } + return 0; +} From 43f89e879de830e71d59701b0b3c1d03823f28e6 Mon Sep 17 00:00:00 2001 From: aadhikari-design Date: Thu, 4 Sep 2025 18:31:36 +0545 Subject: [PATCH 20/27] q17.c --- src/q17.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/q17.c b/src/q17.c index 6858adf..4fe43bf 100644 --- a/src/q17.c +++ b/src/q17.c @@ -1 +1,10 @@ -// Write a C program that prompts the user for a positive integer and prints a countdown from that number to 1 using a for loop. \ No newline at end of file +#include +int main(){ + int num,i; + printf("Enter a positive integer: "); + scanf("%d",&num); + for(i=num;i>=1;i--){ + printf("%d\n",i); + } + return 0; +} From 71a5558f9f7fdc9f2c350e6da5e33d4806c0d7ac Mon Sep 17 00:00:00 2001 From: aadhikari-design Date: Thu, 4 Sep 2025 18:32:27 +0545 Subject: [PATCH 21/27] q18.c --- src/q18.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/q18.c b/src/q18.c index 4229091..1201b38 100644 --- a/src/q18.c +++ b/src/q18.c @@ -1,2 +1,11 @@ -// Write a C program that prompts the user for a positive integer and prints the -// multiplication table for that number up to 10 using a while loop. \ No newline at end of file +#include +int main(){ + int num,i=1; + printf("Enter a positive integer: "); + scanf("%d",&num); + while(i<=10){ + printf("%d x %d = %d\n",num,i,num*i); + i++; + } + return 0; +} From c49f47de42868c7ff896d048cd2a7c291ef897ec Mon Sep 17 00:00:00 2001 From: aadhikari-design Date: Thu, 4 Sep 2025 18:45:06 +0545 Subject: [PATCH 22/27] q19.c --- src/q19.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/q19.c b/src/q19.c index a2b2ae3..0b0b721 100644 --- a/src/q19.c +++ b/src/q19.c @@ -1,5 +1,13 @@ -/* Write a C program that prompts the user for a positive integer and prints a pattern of asterisks (*) in a square shape using nested loops. -Example: User’s Input = 2, then pattern to print will be: - * * - * * -*/ \ No newline at end of file +#include +int main(){ + int n,i,j; + printf("Enter a positive integer: "); + scanf("%d",&n); + for(i=1;i<=n;i++){ + for(j=1;j<=n;j++){ + printf("* "); + } + printf("\n"); + } + return 0; +} From 34d151f0227ad6bcf876c9ac4b08a10edb78f491 Mon Sep 17 00:00:00 2001 From: aadhikari-design Date: Thu, 4 Sep 2025 18:45:50 +0545 Subject: [PATCH 23/27] q20.c --- src/q20.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/q20.c b/src/q20.c index 8d1027a..c909a52 100644 --- a/src/q20.c +++ b/src/q20.c @@ -1 +1,17 @@ -// Write a C program that prompts the user for a number between 1 and 7 and prints the corresponding day of the week using a switch-case statement. \ No newline at end of file +#include +int main(){ + int day; + printf("Enter a number between 1 and 7: "); + scanf("%d",&day); + switch(day){ + case 1: printf("Sunday\n"); break; + case 2: printf("Monday\n"); break; + case 3: printf("Tuesday\n"); break; + case 4: printf("Wednesday\n"); break; + case 5: printf("Thursday\n"); break; + case 6: printf("Friday\n"); break; + case 7: printf("Saturday\n"); break; + default: printf("Invalid input\n"); + } + return 0; +} From a72242d5074866f3e70d9f6cb7d0735d9df9645e Mon Sep 17 00:00:00 2001 From: aadhikari-design Date: Thu, 4 Sep 2025 18:47:38 +0545 Subject: [PATCH 24/27] q13.c --- src/q13.c | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/src/q13.c b/src/q13.c index d666476..a23ab4f 100644 --- a/src/q13.c +++ b/src/q13.c @@ -1,15 +1,10 @@ #include - -int main() { - int i = 2; - int sum = 0; - - while(i <= 50) { - sum += i; - i += 2; +int main(){ + int i=2,sum=0; + while(i<=50){ + sum+=i; + i+=2; } - - printf("Sum of all even numbers from 1 to 50 is %d\n", sum); - + printf("%d\n",sum); return 0; } From bb97d85099738580048602f7b25c7bdb81665be3 Mon Sep 17 00:00:00 2001 From: aadhikari-design Date: Thu, 4 Sep 2025 18:49:19 +0545 Subject: [PATCH 25/27] q4.c --- src/q4.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/q4.c b/src/q4.c index 1f4b51f..47d06ee 100644 --- a/src/q4.c +++ b/src/q4.c @@ -1,10 +1,8 @@ #include -int main() { -int i; -printf("Even numbers between 1 and 100 are:\n"); -for(i = 2; i <= 100; i += 2) { -printf("%d ", i); +int main(){ + int i; + for(i=2;i<=100;i+=2){ + printf("%d ",i); } - printf("\n"); -return 0; + return 0; } From 88d123f4c4fbd6c826319cb907436039370f5532 Mon Sep 17 00:00:00 2001 From: aadhikari-design Date: Thu, 4 Sep 2025 18:54:42 +0545 Subject: [PATCH 26/27] q5.c --- src/q5.c | 25 +++++++------------------ 1 file changed, 7 insertions(+), 18 deletions(-) diff --git a/src/q5.c b/src/q5.c index 92bcee5..286532b 100644 --- a/src/q5.c +++ b/src/q5.c @@ -1,23 +1,12 @@ #include - -int main() { - int n, i = 1; - unsigned long long factorial = 1; - - printf("Enter a positive integer: "); - scanf("%d", &n); - - if(n < 0) { - printf("Factorial is not defined for negative numbers.\n"); - return 1; - } - - while(i <= n) { - factorial *= i; +int main(){ + int n,i=1; + unsigned long long f=1; + scanf("%d",&n); + while(i<=n){ + f*=i; i++; } - - printf("Factorial of %d is %llu\n", n, factorial); - + printf("%llu\n",f); return 0; } From a5640485a7477874d07741f77d2cf9c784c4d87c Mon Sep 17 00:00:00 2001 From: aadhikari-design Date: Thu, 4 Sep 2025 18:55:52 +0545 Subject: [PATCH 27/27] q6.c --- src/q6.c | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/src/q6.c b/src/q6.c index 0ce436d..83ddbed 100644 --- a/src/q6.c +++ b/src/q6.c @@ -1,17 +1,10 @@ #include - -int main() { - int num, i = 1; - - printf("Enter a number: "); - scanf("%d", &num); - - printf("Multiplication table of %d:\n", num); - - do { - printf("%d x %d = %d\n", num, i, num * i); +int main(){ + int num,i=1; + scanf("%d",&num); + do{ + printf("%d x %d = %d\n",num,i,num*i); i++; - } while(i <= 10); - + }while(i<=10); return 0; }