diff --git a/.github/workflows/npm-publish-github-packages.yml b/.github/workflows/npm-publish-github-packages.yml new file mode 100644 index 0000000..ea2d329 --- /dev/null +++ b/.github/workflows/npm-publish-github-packages.yml @@ -0,0 +1,36 @@ +# This workflow will run tests using node and then publish a package to GitHub Packages when a release is created +# For more information see: https://docs.github.com/en/actions/publishing-packages/publishing-nodejs-packages + +name: Node.js Package + +on: + release: + types: [created] + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 + with: + node-version: 20 + - run: npm ci + - run: npm test + + publish-gpr: + needs: build + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 + with: + node-version: 20 + registry-url: https://npm.pkg.github.com/ + - run: npm ci + - run: npm publish + env: + NODE_AUTH_TOKEN: ${{secrets.GITHUB_TOKEN}} diff --git a/5 student.c b/5 student.c new file mode 100644 index 0000000..fc278b1 --- /dev/null +++ b/5 student.c @@ -0,0 +1,32 @@ +//A C program that reads the names and marks of 5 students +#include +#include + +int main() { + FILE *fptr; + char name[50]; + int marks, i; + + // Open the file in write mode + fptr = fopen("C:\\Users\\clemoh\\OneDrive\\Desktop\\cfiles\\students.txt", "w"); + if (fptr == NULL) { + printf("Error opening the file.\n"); + exit(1); + } + + // Loop to read name and marks of 5 students and store them in the file + for (i = 1; i <= 5; i++) { + printf("Enter name of student %d: ", i); + scanf("%s", name); + printf("Enter marks of student %d: ", i); + scanf("%d", &marks); + + // Write the name and marks to the file + fprintf(fptr, "Student %d: Name = %s, Marks = %d\n", i, name, marks); + } + + fclose(fptr); + printf("Data written successfully to students.txt.\n"); + return 0; +} +} diff --git a/Appending c file.c b/Appending c file.c new file mode 100644 index 0000000..d661989 --- /dev/null +++ b/Appending c file.c @@ -0,0 +1,29 @@ +//appending a sentence in a file +#include +#include + +void appendToFile() { + FILE *fptr; + char sentence[100]; + + // Open the file in append mode + fptr = fopen("C:\\Users\\clemoh\\OneDrive\\Desktop\\cfiles\\data.txt", "a"); + if (fptr == NULL) { + printf("Error opening file for appending.\n"); + exit(1); + } + + // Get a second sentence from the user + printf("Enter another sentence to append (up to 100 characters): "); + fgets(sentence, sizeof(sentence), stdin); + + // Append the sentence to the file + fprintf(fptr, "%s", sentence); + fclose(fptr); + printf("Sentence appended to file successfully.\n"); +} + +int main() { + appendToFile(); + return 0; +} diff --git a/C program to check whether a number is even.c b/C program to check whether a number is even.c new file mode 100644 index 0000000..d936724 --- /dev/null +++ b/C program to check whether a number is even.c @@ -0,0 +1,13 @@ +//C program to check whether a number is even +#include +int main() { + int number; + printf("Enter the number"); + scanf("%d", &number); + if(number % 2 == 0){ + printf("The number is even\n"); + }else { + printf("The number is odd\n"); + } + return 0; +} diff --git a/Employee program.c b/Employee program.c new file mode 100644 index 0000000..0881501 --- /dev/null +++ b/Employee program.c @@ -0,0 +1,27 @@ +//C structure program +#include + +struct Employee{ + char name[25]; + char email[50]; + char department[20]; + float salary; + int ID; +}employee; +int main(){ + struct Employee employee={ + "john Doe", + "john.doe@company.com", + "Human Resources", + 55000.50, + 12345, + +}; + + printf("name:%s\n",&employee.name); + printf("email:%s\n",&employee.email); + printf("department:%s\n",&employee.department); + printf("salary:%f\n",&employee.salary); + printf("ID:%d\n",&employee.ID); + + return 0; diff --git a/Prompt variables.c b/Prompt variables.c new file mode 100644 index 0000000..2cc52d8 --- /dev/null +++ b/Prompt variables.c @@ -0,0 +1,38 @@ +//c variables and data types +//pre-processor directive +#include scanf(), printf() +int main(){ + //declaration and intialization + char a; + char name[]={}; + int age; + float area; + double salary; + + printf("enter character: "); + scanf("%s",&a); +printf("the character is %c \n",a); + + printf("enter name: "); + scanf("%s",&name); + printf("the string is %s \n",name); + + printf("enter age: "); + scanf("%d",&age); +printf("the integer is %d years \n",age); + + +printf("enter area: "); + scanf("%f",&area); +printf("the float is %.3f meters squared \n",area); + + + printf("enter salary: "); + scanf("%lf",&salary); + printf("the double is Ksh,%.2lf \n",salary); + + + printf(""); + + return 0; +} diff --git a/area of a rectangle.c b/area of a rectangle.c new file mode 100644 index 0000000..94f6c43 --- /dev/null +++ b/area of a rectangle.c @@ -0,0 +1,12 @@ +//program to find the area of a rectangle +#include +int main() { +int length, width, area; +printf("length: "); +scanf("%d", &length); +printf("width: "); +scanf("%d", &width); +area = length * width; +printf("area %.d\n", area); +return 0; +} diff --git a/area of arectangle.c b/area of arectangle.c new file mode 100644 index 0000000..94f6c43 --- /dev/null +++ b/area of arectangle.c @@ -0,0 +1,12 @@ +//program to find the area of a rectangle +#include +int main() { +int length, width, area; +printf("length: "); +scanf("%d", &length); +printf("width: "); +scanf("%d", &width); +area = length * width; +printf("area %.d\n", area); +return 0; +} diff --git a/bank loan qualification.c b/bank loan qualification.c new file mode 100644 index 0000000..6131df3 --- /dev/null +++ b/bank loan qualification.c @@ -0,0 +1,16 @@ +//bank loan +#include +int main(){ +int age,income; +printf("enter your age:"); +scanf ("%d",&age); +printf ("enter income:"); +scanf("%d",&income); +if(age>=21&& income>21000){ +printf("congratulations you qualify for the loan\n"); +} +else{ +printf("you don't qualify for the loan\n"); +} +return 0; +} diff --git a/c file program.c b/c file program.c new file mode 100644 index 0000000..0ee7bd1 --- /dev/null +++ b/c file program.c @@ -0,0 +1,22 @@ +//C file handling :writing to a file +#include //scanf(),printf(),fprintf(),fscanf(),fclose() +#include //exit() + +int main () { + int number; + FILE *fptr; //declare pointer + + fptr = fopen("C:\\users\\JonaN\\Desktop\\C program\\file.txt","w"); + if (fptr==NULL){ + printf("Error opening the file"); + exit(1); + } + printf("Enter a random number:"); + scanf("%d", &number); + + fprintf(fptr, "The number entered is %d",number); + fclose(fptr); + printf("Number written succesfully"); + + return 0; //execution successfully +} diff --git a/c structures book.c b/c structures book.c new file mode 100644 index 0000000..7b1cb46 --- /dev/null +++ b/c structures book.c @@ -0,0 +1,32 @@ +// c structures +#include +#include //strcpy +stuct book { + char title[30] + char name[30] + char ISBN[13] + int publication_year; + float price; +} + int main() { + //initializing variable (operators) + strcpy(book1.title,"introducction to c structure"); + strcpy(book1.name,"john smith"); + strcpy(book1.ISBN,"701_354603975"); + Book1.publication_year=2022; + book1.price=49.99; + + printf("Title;%s\n",book1.introduction to c programming); + printf("Author %s\n",book1.john smith); + printf("publication_year %s\n",book1.2022); + printf("ISBN %s \n",book1.701_35460395); + printf("price %s\n",book1.49.99) + + //printf("enter name ") + //scanf("%s",&introduction to c structure); + + return 0; + + + + diff --git a/do while program.c b/do while program.c new file mode 100644 index 0000000..8de064b --- /dev/null +++ b/do while program.c @@ -0,0 +1,18 @@ +//Do while program +#include + +int main() { + int i = 1, n; + + // Prompt user for input + printf("Enter the number of terms: "); + scanf("%d", &n); + + // Do..while loop to calculate and print the cube of each number + do { + printf("Number is : %d and cube of %d is : %d\n", i, i, i * i * i); + i++; + } while (i <= n); + + return 0; +} diff --git a/for loop.c b/for loop.c new file mode 100644 index 0000000..bc4fd2c --- /dev/null +++ b/for loop.c @@ -0,0 +1,17 @@ +//For loop program +#include + +int main() { + int i, n; + + // Prompt user for input + printf("Enter the number of terms: "); + scanf("%d", &n); + + // For loop to calculate and print the cube of each number + for (i = 1; i <= n; i++) { + printf("Number is : %d and cube of %d is : %d\n", i, i, i * i * i); + } + + return 0; +} diff --git a/library program.c b/library program.c new file mode 100644 index 0000000..0436c24 --- /dev/null +++ b/library program.c @@ -0,0 +1,30 @@ + #include +int main(){ +int bookid; +double duedate,returndate; +double finerate,fineamount,daysoverdue; +printf("enter the bookid:"); +scanf("%d",&bookid); +printf("enter the duedate:"); +scanf("%lf",&duedate); +printf("enter the returndate:"); +scanf("%lf",&returndate); +daysoverdue=returndate-duedate; +if(daysoverdue<=7){ +finerate=20; +} +else if(daysoverdue<=14){ +finerate=50; +} +else { +finerate=100; +} +fineamount=finerate*daysoverdue; +printf("bookid:%d\n",bookid); +printf("duedate:%lf\n",duedate); +printf("returndate:%lf\n",returndate); +printf("daysoverdue:%lf\n",daysoverdue); +printf("finerate:%lf\n",finerate); +printf("fineamount:%lf\n",fineamount); +return 0; +} diff --git a/n students.c b/n students.c new file mode 100644 index 0000000..a895eff --- /dev/null +++ b/n students.c @@ -0,0 +1,35 @@ +//A C program that reads the names and marks of an n number of students +#include +#include + +int main() { + FILE *fptr; + char name[50]; + int marks, i, n; + + // Open the file in append mode + fptr = fopen("C:\\Users\\clemoh\\OneDrive\\Desktop\\cfiles\\students.txt", "a"); + if (fptr == NULL) { + printf("Error opening the file.\n"); + exit(1); + } + + // Prompt user for number of students + printf("Enter the number of students: "); + scanf("%d", &n); + + // Loop to read name and marks of n students and append them to the file + for (i = 1; i <= n; i++) { + printf("Enter name of student %d: ", i); + scanf("%s", name); + printf("Enter marks of student %d: ", i); + scanf("%d", &marks); + + // Append the name and marks to the file + fprintf(fptr, "Student %d: Name = %s, Marks = %d\n", i, name, marks); + } + + fclose(fptr); + printf("Data written successfully to students.txt.\n"); + return 0; +} diff --git a/students grading system.c b/students grading system.c new file mode 100644 index 0000000..a07e3c3 --- /dev/null +++ b/students grading system.c @@ -0,0 +1,32 @@ +// grading system of students +#include + +int main() { + int marks1, marks2, marks3, average; + + printf("Enter marks for subject 1: "); + scanf("%d", &marks1); + + printf("Enter marks for subject 2: "); + scanf("%d", &marks2); + + printf("Enter marks for subject 3: "); + scanf("%d", &marks3); + + average = (marks1 + marks2 + marks3) / 3; + printf("Average Marks = %.d\n", average); + + if (average >= 70) { + printf("Grade: A\n"); + } else if (average >= 60) { + printf("Grade: B\n"); + } else if (average >= 50) { + printf("Grade: C\n"); + } else if (average >= 40) { + printf("Grade: D\n"); + } else { + printf("Grade: E (Fail)\n"); + } + + return 0; + } diff --git a/write to a file.c b/write to a file.c new file mode 100644 index 0000000..1e27e9b --- /dev/null +++ b/write to a file.c @@ -0,0 +1,28 @@ +//write a sentence into a file +#include +#include + +void writeToFile() { + FILE *fptr; + char sentence[100]; + + // Open the file in write mode + fptr = fopen("C:\\Users\\clemoh\\OneDrive\\Desktop\\cfiles\\data.txt", "w"); + if (fptr == NULL) { + printf("Error opening file for writing.\n"); + exit(1); + } + + // Get a sentence from the user + printf("Enter a sentence (up to 100 characters): "); + fgets(sentence, sizeof(sentence), stdin); + + // Write the sentence to the file + fprintf(fptr, "%s", sentence); + fclose(fptr); + printf("Sentence written to file successfully.\n"); +} + +int main() { + writeToFile(); + return 0;