diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..6e3efe2 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "C_Cpp.default.compilerPath": "/bin/gcc" +} \ No newline at end of file diff --git a/__pycache__/matplotlib.cpython-312.pyc b/__pycache__/matplotlib.cpython-312.pyc new file mode 100644 index 0000000..c0243a4 Binary files /dev/null and b/__pycache__/matplotlib.cpython-312.pyc differ diff --git a/a.out b/a.out new file mode 100755 index 0000000..fb853b0 Binary files /dev/null and b/a.out differ diff --git a/issue1.c b/issue1.c index 05a1df5..ac79cf7 100644 --- a/issue1.c +++ b/issue1.c @@ -1,20 +1,23 @@ -// Make sure the function reverse actually reverses the string +// Made sure the function reverse actually reverses the string -#include -#include -#include +#include +#include +#include -char* reverse(char* str){ - char* rev = (char*)malloc(sizeof(str)); +char *reverse(char *str) +{ + char *rev = (char *)malloc(sizeof(str)); int size = strlen(str); - for(int i=0;i -int main(){ +int main() +{ int even = 0; - for(int i = 0; i <= 20; i++){ - even *= 2; + for (int i = 1; i <= 20; i++) + { + even += 2; printf("%d\t", even); } printf("\n"); diff --git a/issue3.c b/issue3.c index 7a9f3df..ad832d3 100644 --- a/issue3.c +++ b/issue3.c @@ -1,21 +1,23 @@ -// Make sure the program prints the string correctly +// Made sure the program prints the string correctly #include -int main(){ +int main() +{ // Printing all the characters in an array char z[] = {'h', 'e', 'l', 'l', 'o', '!'}; - char new[50] = ""; + char new[50] = ""; - for(int i = 0; i < 6; i++){ - new[i] = z; + for (int i = 0; i < 6; i++) + { + new[i] = z[i]; } - for(int i = 0; i < 6; i++){ + for (int i = 0; i < 6; i++) + { printf("%c", new[i]); } printf("\n"); return 0; - } \ No newline at end of file diff --git a/issue4.c b/issue4.c index 5fe7765..6421193 100644 --- a/issue4.c +++ b/issue4.c @@ -1,11 +1,15 @@ -// Make sure the sorting algorithm is correct +// Made sure the sorting algorithm is correct #include -void sort(int a[], int b){ - for(int i = 0; i < b; i++){ - for(int j = 1; j < b; j++){ - if(a[i] > a[j]){ +void ascending_sort(int a[], int b) +{ + for (int i = 0; i < b; i++) + { + for (int j = i; j < b; j++) + { + if (a[i] > a[j]) + { int temp = a[i]; a[i] = a[j]; a[j] = temp; @@ -14,12 +18,14 @@ void sort(int a[], int b){ } } -int main(){ +int main() +{ // Sort in ascending order int numbers[] = {4, 2, 3, 1, 8, 7}; - sort(numbers, 6); - - for(int i = 0; i < 6; i++){ + ascending_sort(numbers, 6); + + for (int i = 0; i < 6; i++) + { printf("%d", numbers[i]); } } \ No newline at end of file diff --git a/issue5.c b/issue5.c index 2ff3dd5..2d8225a 100644 --- a/issue5.c +++ b/issue5.c @@ -1,29 +1,39 @@ -// Make sure you only get the desired output +// Made sure you only get the desired output -#include -int main(void){ +#include +int main(void) +{ int flag = 0; - + printf("Choose the operation:-\n1. Multiples of 2\n2. Multiples of 3\n3. Multiples of 4\n"); scanf(" %d", &flag); - switch(flag){ - case 1 : - for(int i=1;i<6;i++){ - printf("%d\t", 2*i); - } - printf("\n"); - case 2 : - for(int i=1;i<6;i++){ - printf("%d\t", 3*i); - } - printf("\n"); - case 3 : - for(int i=1;i<6;i++){ - printf("%d\t", 4*i); - } - printf("\n"); - default : - printf("Choose a valid option!!!\n"); + switch (flag) + { + case 1: + for (int i = 1; i < 6; i++) + { + printf("%d\t", 2 * i); + } + printf("\n"); + break; + case 2: + for (int i = 1; i < 6; i++) + { + printf("%d\t", 3 * i); + } + printf("\n"); + break; + case 3: + for (int i = 1; i < 6; i++) + { + printf("%d\t", 4 * i); + } + printf("\n"); + break; + + default: + printf("Choose a valid option!!!\n"); + break; } } \ No newline at end of file diff --git a/issue6.c b/issue6.c index 94a0656..37e7080 100644 --- a/issue6.c +++ b/issue6.c @@ -1,12 +1,13 @@ -// Make sure the program is working correct logically +// Made sure the program is working correct logically -#include -#include -int main(void){ - char* str1 = "This is a string"; - char* str2 = "This is another string"; +#include +#include +int main(void) +{ + char *str1 = "This is a string"; + char *str2 = "This is another string"; - if(strcmp(str1, str2)) + if (!strcmp(str1, str2)) printf("Strings are same.\n"); else printf("Strings are not same.\n"); diff --git a/issue7.c b/issue7.c index fc3d230..b6b0b3c 100644 --- a/issue7.c +++ b/issue7.c @@ -1,11 +1,12 @@ -// Make sure the output is the correct sum of a and b +// Made sure the output is the correct sum of a and b -#include -#include +#include +#include -int main(void){ +int main(void) +{ int a = 5; - int* b = (int*)malloc(sizeof(int)); + int *b = (int *)malloc(sizeof(int)); *b = 7; - printf("%d\n", (a+b)); + printf("%d\n", (a + *b)); } \ No newline at end of file diff --git a/issue8.c b/issue8.c index 4876a9b..bf9fc66 100644 --- a/issue8.c +++ b/issue8.c @@ -1,11 +1,13 @@ -// Only print the given string, nothing more -// Bonus if you don't count the number of characters in the string manually +// Only printed the given string, nothing more +// didn't count the number of characters in the string manually -#include -#include -int main(void){ - char* str = "Welcome to IEEE\n"; - for(int i=0;i<100;i++){ +#include +#include +int main(void) +{ + char *str = "Welcome to IEEE\n"; + for (int i = 0; i < strlen(str) - 1; i++) + { printf("%c", str[i]); } printf("\n"); diff --git a/issue9.c b/issue9.c index f28b571..f985ab6 100644 --- a/issue9.c +++ b/issue9.c @@ -1,8 +1,8 @@ -// print correct factorial of the variable "num" +// printed correct factorial of the variable "num" #include int factorial(int n){ - if(n == 2) + if(n == 1) return 1; else return n*factorial(n-1); diff --git a/makefile b/makefile new file mode 100644 index 0000000..1e36859 --- /dev/null +++ b/makefile @@ -0,0 +1,3 @@ +all: + g++ ncurses.cpp -lncurses + ./a.out diff --git a/matplotlib.py b/matplotlib.py new file mode 100644 index 0000000..c7ceac8 --- /dev/null +++ b/matplotlib.py @@ -0,0 +1,9 @@ +import matplotlib.pyplot as pt + +x=[1,2,3,4,5,6,7] +y=[1,2,3,4,5,6,7] + +pt.plot(x,y) +pt.xlable("x") +pt.ylable("y") +pt.show() \ No newline at end of file diff --git a/ncurses.c b/ncurses.c new file mode 100644 index 0000000..8a9f739 --- /dev/null +++ b/ncurses.c @@ -0,0 +1,53 @@ +#include + + +int main() +{ + // initating a terminal window + initscr(); + // to start reciveing input immideateliy but on by default + cbreak(); + // to pritnt to window + printw("hello world"); + printw("enter the pin:"); + // to hide the keystrokes + noecho(); + for (int i = 0; i < 4; i++) + { + getch(); + } + // to show the keystrokes + echo(); + + int height = 10, width = 20, start_y = 1, start_x = 1; + + // created a window + WINDOW *win = newwin(height, width, start_y, start_x); + //to refresh the window + refresh(); + + //to add border to created sub window + box(win, 0, 0); + mvwprintw(win, 1, 1, "frame 1"); + wrefresh(win); + + + // getting environment info + int y, x, ybeg, xbeg, ymax, xmax; + getyx(stdscr, y, x); + getmaxyx(stdscr, ymax, xmax); + getbegyx(win, ybeg, xbeg); + + move(10, 10); + box(win, 10, 10); + + wrefresh(win); + + printw("%d %d %d %d %d %d", y, x, ybeg, xbeg, ymax, xmax); + wrefresh(win); + getch(); + + endwin(); + + return 0; +} diff --git a/proc.sh b/proc.sh new file mode 100644 index 0000000..5196dce --- /dev/null +++ b/proc.sh @@ -0,0 +1,24 @@ +#! /bin/bash + +# showinf uptime +a=($(cat /proc/uptime)) +h=$( echo "${a[0]}/3600" | bc ) +min=$(echo "((${a[0]}%3600)/60)" | bc ) + +echo "uptime: $h hr and $min min" + +# showing load average +l=($(cat /proc/loadavg)) +echo "loadavg" +for num in {0..2} +do +c=$( echo "${l[num]}*100" | bc ) + +echo " $c % " +done +echo " running processes/total : ${l[3]} " +echo " most recent process (ID) : ${l[4]} " + + + + diff --git a/process_view.c b/process_view.c new file mode 100644 index 0000000..ec31ec0 --- /dev/null +++ b/process_view.c @@ -0,0 +1,61 @@ +#include +#include +#include +#include + +#define MAX_LINE 1024 + +void draw_processes(WINDOW *win) { + FILE *fp; + char line[MAX_LINE]; + int row = 1; + + werase(win); // Clear window + box(win, 0, 0); + mvwprintw(win, 0, 2, " Process Viewer(Press E to Exit)"); + mvwprintw(win, 1, 2, "PID TTY TIME CMD"); + + fp = popen("ps -a", "r"); + if (fp == NULL) { + mvwprintw(win, 2, 2, "Failed to run ps command"); + wrefresh(win); + return; + } + + fgets(line, sizeof(line), fp); // Skip the header line + + while (fgets(line, sizeof(line), fp) != NULL && row < LINES - 2) { + mvwprintw(win, ++row, 2, "%.*s", COLS - 4, line); // prevent overflow + } + + pclose(fp); + wrefresh(win); +} + +int main() { + initscr(); + noecho(); + cbreak(); + curs_set(0); + nodelay(stdscr, TRUE); // Don't block on getch() + keypad(stdscr, TRUE); // Enable function keys + + WINDOW *win = newwin(LINES, COLS, 0, 0); + int ch; + + while (1) { + draw_processes(win); + + ch = getch(); // Non-blocking key check + if (ch == 'E' || ch == 'e') { + break; + } + + usleep(2000000); // Refresh every 2 seconds + } + + delwin(win); + endwin(); + return 0; +} +