diff --git a/Tutorials/2023 Feb Tutorials/Tutorial-01/Tute1ex3-1.c b/Tutorials/2023 Feb Tutorials/Tutorial-01/Tute1ex3-1.c new file mode 100644 index 0000000..93ffaf8 --- /dev/null +++ b/Tutorials/2023 Feb Tutorials/Tutorial-01/Tute1ex3-1.c @@ -0,0 +1,43 @@ +// Exercise 3 - 2 +// Traveling Expenditure Calculator + +#include + +int main(void) +{ + int bus1, bus2, bus3, expenditure; //declaration + + //initialize + bus1 = 50; // bus1 fare + bus2 = 60; // bus2 fare + bus3 = 70; // bus3 fare + + expenditure = (bus1 + bus2 + bus3) * 5 * 14; // Calculate expenditure for semester + + printf("Bus 01 fare = Rs.%d\n", bus1); + printf("Bus 02 fare = Rs.%d\n", bus2); + printf("Bus 03 fare = Rs.%d\n", bus3); + printf("Traveling Expenditure for Entire semester = Rs.%d\n", expenditure); + + return 0; +} + +// Method 2 - Using Functions + +// int expend(int bus1, int bus2, int bus3) +// { +// int e; +// e = (bus1 + bus2 + bus3) * 5 * 14; +// return e; +// } + +// int main(void) +// { +// int bus1, bus2, bus3; + +// printf("enter buses fare: "); +// scanf("%d%d%d", &bus1, &bus2, &bus3); +// printf("Traveling Expenditure for Entire semester = %d\n", expend(bus1, bus2, bus3)); + +// return 0; +// } diff --git a/Tutorials/2023 Feb Tutorials/Tutorial-01/Tute1ex3-2.c b/Tutorials/2023 Feb Tutorials/Tutorial-01/Tute1ex3-2.c new file mode 100644 index 0000000..dc3ceae --- /dev/null +++ b/Tutorials/2023 Feb Tutorials/Tutorial-01/Tute1ex3-2.c @@ -0,0 +1,19 @@ +// Exersice 3 - 3 +// Bonus Calculate + +#include + +int main (void) +{ + int salary, bonus; //declaration + + printf("Enter your salary: "); //initialization + scanf("%d", &salary); + + bonus = (salary / 100) * 20; // Calculate Bonus + + // printf("Salary = %d\n", salary); + printf("Bonus = %d\n", bonus); // output + + return 0; +} diff --git a/Tutorials/2023 Feb Tutorials/Tutorial-01/Tute1ex3-3.c b/Tutorials/2023 Feb Tutorials/Tutorial-01/Tute1ex3-3.c new file mode 100644 index 0000000..b1fd850 --- /dev/null +++ b/Tutorials/2023 Feb Tutorials/Tutorial-01/Tute1ex3-3.c @@ -0,0 +1,19 @@ +// Exersice 3 - 1 +// Fahrehite to Celsius Calculate + +#include + +int main (void) +{ + int fa, cels; //declaration + + printf("Enter Temperature(Celsius): "); //initialization + scanf("%d", &cels); + + fa = (cels * 9/5) + 32; // Calculate Fahrehite Value + + printf("Fahrehite = %d\n", fa); // output + + return 0; +} + diff --git a/Tutorials/2023 Feb Tutorials/Tutorial-02/Tute2ex1.c b/Tutorials/2023 Feb Tutorials/Tutorial-02/Tute2ex1.c new file mode 100644 index 0000000..af9f1a5 --- /dev/null +++ b/Tutorials/2023 Feb Tutorials/Tutorial-02/Tute2ex1.c @@ -0,0 +1,26 @@ +//Exercise 1: Practice how to use variables in printf statement + +#include + +int main(void) +{ + int x =2, y = 3; + float z = 45.567; + + printf("*\n**\n***\n****\n*****\n"); + + printf("%d\n", x + x); + + printf("x = \n"); + + printf("x=%d\n", x); + + printf("%d = %d", x+y, y+x); + /* printf( "%d", x+y ); */ + + printf("\n"); + + printf("value is %.2f\n", z); + + return 0; +} diff --git a/Tutorials/2023 Feb Tutorials/Tutorial-02/Tute2ex3.c b/Tutorials/2023 Feb Tutorials/Tutorial-02/Tute2ex3.c new file mode 100644 index 0000000..d0bcd46 --- /dev/null +++ b/Tutorials/2023 Feb Tutorials/Tutorial-02/Tute2ex3.c @@ -0,0 +1,26 @@ +// Exercise 3: Practice scanf statement in a C program + +#include + +int main(void) +{ + int mark1,mark2,total; // declaration + + printf("Enter Your Marks: "); + scanf("%d", &mark1); // get mark one input + + printf("Enter Your Marks: "); + scanf("%d", &mark2); // get mark two input + + total = mark1+mark2; // calculate total marks + + printf("Total Marks = %d\n", total); // display total marks + + // calculate and display Average marks (convert int to float using type conversion.) + + printf("Average Marks = %.1f\n", (float)total / 2); // with type conversion + + // printf("Average Marks = %d\n", total / 2); // without tyoe conversion + + return 0; +} // end function main diff --git a/Tutorials/2023 Feb Tutorials/Tutorial-02/Tute2ex4.c b/Tutorials/2023 Feb Tutorials/Tutorial-02/Tute2ex4.c new file mode 100644 index 0000000..9888d7f --- /dev/null +++ b/Tutorials/2023 Feb Tutorials/Tutorial-02/Tute2ex4.c @@ -0,0 +1,40 @@ +#include + +// Structure +struct item { + int itemNo; + float price; + int quantity; +} item1, item2; + +// Main Function +int main(void) { + + // get item1 details + printf("Enter item 1 itemNo: "); + scanf("%d", &item1.itemNo); + printf("Enter item 1 price: "); + scanf("%f", &item1.price); + printf("Enter item 1 quantity: "); + scanf("%d", &item1.quantity); + + printf("\n"); // for blank line + + //get item2 details + printf("Enter item 2 itemNo: "); + scanf("%d", &item2.itemNo); + printf("Enter item 2 price: "); + scanf("%f", &item2.price); + printf("Enter item 2 quantity: "); + scanf("%d", &item2.quantity); + + printf("\n"); // for blank line + + // output + printf("|%-9s|%-10s|%-11s|\n", "Item No", "Price", "Quantity"); + + printf("|%9d|%10.2f|%11d|\n", item1.itemNo, item1.price , item1.quantity); + printf("|%9d|%10.2f|%11d|\n", item2.itemNo, item2.price , item2.quantity); + + return 0; +} // end of main Function diff --git a/Tutorials/2023 Feb Tutorials/Tutorial-03/Tute3ex2.c b/Tutorials/2023 Feb Tutorials/Tutorial-03/Tute3ex2.c new file mode 100644 index 0000000..0f1374d --- /dev/null +++ b/Tutorials/2023 Feb Tutorials/Tutorial-03/Tute3ex2.c @@ -0,0 +1,28 @@ +/* +Exercise 2: Practice arithmetic operators in C +Write a program that inputs one five-digit number, separates the number into its individual +*/ + +#include + +int main(void) +{ + int num; + + printf("Enter your (Five-Digit) Number: "); + scanf("%d", &num); // input + + // check number digits + if (num > 9999 && num <= 99999) { + printf("%d ", (num / 10000) % 10); //get the first Number + printf("%d ", (num / 1000) % 10); // get the second number + printf("%d ", (num / 100) % 10); // get the third number + printf("%d ", (num / 10) % 10); // get the fourth number + printf("%d \n", num % 10); // get the fifth number + } + else + printf("Five digit numbers only\n"); + + return 0; + +} diff --git a/Tutorials/2023 Feb Tutorials/Tutorial-03/Tute3ex3.c b/Tutorials/2023 Feb Tutorials/Tutorial-03/Tute3ex3.c new file mode 100644 index 0000000..8cd6db4 --- /dev/null +++ b/Tutorials/2023 Feb Tutorials/Tutorial-03/Tute3ex3.c @@ -0,0 +1,28 @@ +#include + +int main(void) +{ + int i, j, k, m; + + i = 1; + j = 2; + k = 4; + m = 0; + + printf("%d\n", i == 1); + + printf("%d\n", j == 3); + + printf("%d\n", i >= 1 && j < 4); + + printf("%d\n", k + m < j || 3 - j >= k); + + printf("%d\n", !m); + + printf("%d\n", !( j - m )); + + return 0; +} + + + diff --git a/Tutorials/2023 Feb Tutorials/Tutorial-03/Tute3ex4-1.c b/Tutorials/2023 Feb Tutorials/Tutorial-03/Tute3ex4-1.c new file mode 100644 index 0000000..1f6bb1c --- /dev/null +++ b/Tutorials/2023 Feb Tutorials/Tutorial-03/Tute3ex4-1.c @@ -0,0 +1,22 @@ +#include + +int main(void) +{ + int mark1, mark2, avg; + + printf("Enter Sub 1 Mark: "); + scanf("%d", &mark1); + + printf("Enter Sub 2 Mark: "); + scanf("%d", &mark2); + + avg = (mark1 + mark2) /2; + + if ( avg >= 45) + printf("Pass\n"); + else + printf("Fail\n"); + + return 0; + +} diff --git a/Tutorials/2023 Feb Tutorials/Tutorial-03/Tute3ex4-2(extended).c b/Tutorials/2023 Feb Tutorials/Tutorial-03/Tute3ex4-2(extended).c new file mode 100644 index 0000000..9890c0b --- /dev/null +++ b/Tutorials/2023 Feb Tutorials/Tutorial-03/Tute3ex4-2(extended).c @@ -0,0 +1,33 @@ +/* +Enter the gender and the age of a person from the keyboard and display +“SeniorMale” or “SeniorFemale”. Age greater than or equal to 65 is taken as +*/ +#include +#include + +int main(void) +{ + int age; + char gen[10]; + char ma[10] = "male"; + char fe[10] = "female"; + + printf("Enter age: "); + scanf("%d", &age); + + printf("Enter Gender: "); + scanf("%s", gen); + + int comp = strcmp(gen, ma); + int comp2 = strcmp(gen, fe); + + if (age >= 65 && comp == 0) + printf("Senior Male\n"); + else if (age >= 65 && comp2 == 0) + printf("Senior Female\n"); + else + printf("Failed"); + + return 0; + +} diff --git a/Tutorials/2023 Feb Tutorials/Tutorial-03/Tute3ex4-3.c b/Tutorials/2023 Feb Tutorials/Tutorial-03/Tute3ex4-3.c new file mode 100644 index 0000000..e66bda7 --- /dev/null +++ b/Tutorials/2023 Feb Tutorials/Tutorial-03/Tute3ex4-3.c @@ -0,0 +1,26 @@ +/* +Enter the mark obtained for IP module and display the grade based on the +*/ + +#include + +int main(void) +{ + int mark; + + printf("Enter Your Marks: "); + scanf("%d", &mark); + + if (100 >= mark && 80 <= mark) + printf("Your Grade is A\n"); + else if (79 >= mark && 70 <= mark) + printf("Your Grade is B\n"); + else if (69 >= mark && 45 <= mark) + printf("Your Grade is C\n"); + else if (45 > mark) + printf("Your Grade is F\n"); + else + printf("Invalid Input\n"); + + return 0; +} diff --git a/Tutorials/2023 Feb Tutorials/Tutorial-04/Tute4ex1.c b/Tutorials/2023 Feb Tutorials/Tutorial-04/Tute4ex1.c new file mode 100644 index 0000000..250ea5b --- /dev/null +++ b/Tutorials/2023 Feb Tutorials/Tutorial-04/Tute4ex1.c @@ -0,0 +1,27 @@ +/* +Write a C program to input an integer from the keyboard and convert the number into a positive +number, if the user input is a negative value. + +Hint : if x is negative , -x is positive; + +Eg: if user enters 5, display 5 + if user enters -2, display 2 +*/ +#include + +int main(void) +{ + int num; + + printf("Enter Number: "); + scanf("%d", &num); // get input for num + + if (num < 0) { + num = -num; + } + + printf("%d\n", num); + + return 0; + +} //end of main function diff --git a/Tutorials/2023 Feb Tutorials/Tutorial-04/Tute4ex2.c b/Tutorials/2023 Feb Tutorials/Tutorial-04/Tute4ex2.c new file mode 100644 index 0000000..2223a53 --- /dev/null +++ b/Tutorials/2023 Feb Tutorials/Tutorial-04/Tute4ex2.c @@ -0,0 +1,57 @@ +/* +Exercise 2: Practice to write if… else statement + +Assume that you are supposed to write a C program to update the bank balance of a customer +based on the transactions performed (withdrawals/ deposits) by the customer. + +Implement the program by following the given steps. +i. Prompt the user to input transaction type (Withdrawal/ Deposit) +ii. Read the user input from the keyboard using getchar( ) function (w – withdrawals, d – +deposits) +iii. If the user input ‘w’ or ‘W’ , display message “You have selected to withdraw money”. +If the user input‘d’ or ‘D’, display message “You have selected to deposit money”. +Otherwise display an error message “You have selected an invalid transaction type” +and terminate the program. +iv. Modify the above program to input the bank balance and the amount. +v. Based on the selected transaction type (withdrawal or deposit), display the new balance. +*/ + +#include + +int main(void) +{ + char tran; + // int tran; + // Characters are normally stored in variable type char. + // Characters can be stored in any integer type variable too + float balance,amount; + + printf("Input transaction type(w-Withdrawal,d-Deposit): "); + tran = getchar(); // for get transaction Type + printf("\n"); // for blank line + + if (tran == 'w' || tran == 'W') + { + printf("You Have Selected to withdraw money.\n\n"); + printf("Enter Bank balance: Rs. "); + scanf("%f", &balance); // for get balance + printf("Enter Withdrawal amount: Rs. "); + scanf("%f", &amount); + printf("New Balance: Rs. %.2f\n", (balance - amount)); // calculate & show new balance + } + else if (tran == 'd' || tran == 'D') + { + printf("You have selected to deposit money.\n\n"); + printf("Enter Bank balance: Rs. "); + scanf("%f", &balance); // for get balance + printf("Enter Deposit amount: Rs. "); + scanf("%f", &amount); + printf("New Balance: Rs. %.2f\n", (balance + amount)); // calculate & show new balance + } + else + printf("You have selected invalid transaction type.\n"); // show error message. + + return 0; + +} // end of main function + diff --git a/Tutorials/2023 Feb Tutorials/Tutorial-04/Tute4ex3-and-4.c b/Tutorials/2023 Feb Tutorials/Tutorial-04/Tute4ex3-and-4.c new file mode 100644 index 0000000..566ad04 --- /dev/null +++ b/Tutorials/2023 Feb Tutorials/Tutorial-04/Tute4ex3-and-4.c @@ -0,0 +1,35 @@ +#include + +int main(void) +{ + char opera; // delacration of variable + float num1, num2; + + printf("Enter your operator(+ - / *): "); + opera = getchar(); // for get operator + printf("\nEnter number one: "); + scanf("%f", &num1); // for get num1 + printf("\nEnter Number two: "); + scanf("%f", &num2); // for get num2 + + // switch statement + switch(opera) + { + case '+': + printf("Result: %.2f\n",(num1 + num2)); + break; + case '-': + printf("Result: %.2f\n",(num1 - num2)); + break; + case '*': + printf("Result: %.2f\n",(num1 * num2)); + break; + case '/': + printf("Result: %.2f\n",(num1 / num2)); + break; + default: + printf("invalid operator..!"); // show error massage + } + + return 0; +} // end of main function diff --git a/Tutorials/2023 Feb Tutorials/Tutorial-05/Tute5ex1-1.c b/Tutorials/2023 Feb Tutorials/Tutorial-05/Tute5ex1-1.c new file mode 100644 index 0000000..e99ee6e --- /dev/null +++ b/Tutorials/2023 Feb Tutorials/Tutorial-05/Tute5ex1-1.c @@ -0,0 +1,13 @@ +#include + +int main(void) +{ + int num = 1; //declaring variables + + while (num <= 20) { + printf("%d\n", num); + ++num; // increment value + } + + return 0; +} // end of main function diff --git a/Tutorials/2023 Feb Tutorials/Tutorial-05/Tute5ex1-2-and-3.c b/Tutorials/2023 Feb Tutorials/Tutorial-05/Tute5ex1-2-and-3.c new file mode 100644 index 0000000..7e53b19 --- /dev/null +++ b/Tutorials/2023 Feb Tutorials/Tutorial-05/Tute5ex1-2-and-3.c @@ -0,0 +1,31 @@ +#include + + +//without if statement + +int main(void) +{ + int count; + float sum, num; + + printf("Enter Number: "); + scanf("%f", &num); + + while (num >= 0) { + + sum = sum + num; + printf("Sum: %.2f\n", sum); + + printf("Enter Number: "); + scanf("%f", &num); + + count++; + } + + printf("Average: %.2f\n", (sum / count)); + + return 0; + +} + + diff --git a/Tutorials/2023 Feb Tutorials/Tutorial-05/Tute5ex3-1.c b/Tutorials/2023 Feb Tutorials/Tutorial-05/Tute5ex3-1.c new file mode 100644 index 0000000..3826f47 --- /dev/null +++ b/Tutorials/2023 Feb Tutorials/Tutorial-05/Tute5ex3-1.c @@ -0,0 +1,19 @@ +#include + +int main(void) +{ + int marks, sum = 0, i = 1; + + while (i <= 4) + { + printf("Enter Module Marks: "); + scanf("%d", &marks); + + sum = sum + marks; + i++; + } + + printf("Total Marks = %d\n", sum); + + return 0; +} diff --git a/Tutorials/2023 Feb Tutorials/Tutorial-05/Tute5ex3-2.c b/Tutorials/2023 Feb Tutorials/Tutorial-05/Tute5ex3-2.c new file mode 100644 index 0000000..c60f015 --- /dev/null +++ b/Tutorials/2023 Feb Tutorials/Tutorial-05/Tute5ex3-2.c @@ -0,0 +1,26 @@ +#include + +int main(void) +{ + int marks, sum = 0, moduleCount = 1, stdCount = 1; + + while (stdCount <= 3) + { + while (moduleCount <= 4) + { + printf("Enter Student 0%d Module %d Marks: ", stdCount, moduleCount); + scanf("%d", &marks); + + sum += marks; + moduleCount++; // increment moduleCount + } + + printf("Student 0%d Total Marks = %d\n\n", stdCount, sum); + + moduleCount = 1; // reset moduleCount + sum = 0; // reset sum value + stdCount++; // increment stdCount + } + + return 0; +} diff --git a/Tutorials/2023 Feb Tutorials/Tutorial-05/Tute5ex3-3.c b/Tutorials/2023 Feb Tutorials/Tutorial-05/Tute5ex3-3.c new file mode 100644 index 0000000..30ad71e --- /dev/null +++ b/Tutorials/2023 Feb Tutorials/Tutorial-05/Tute5ex3-3.c @@ -0,0 +1,73 @@ +#include + +// begin main function +int main(void) +{ + int modCount = 1, marks, sum1 = 0, sum2 = 0, sum3 = 0; //declaration variables + + // for Get Student 01 Total marks + while (modCount <= 4) + { + printf("Enter Student 01 Module %d Marks: ", modCount); + scanf("%d", &marks); + + sum1 += marks; + modCount++; // increment modCount + } + + modCount = 1; // reset ModuleCount + printf("Student 01 Total Marks = %d\n\n", sum1); // Display Student 1 toatal marks + + + // for get Student 02 Total Marks + while (modCount <= 4) + { + printf("Enter Student 02 Module %d Marks: ", modCount); + scanf("%d", &marks); + + sum2 += marks; + modCount++; // increment ModuleCount + } + modCount = 1; // reset ModuleCount + printf("Student 02 Total Marks = %d\n\n", sum2); + + // for get student 03 Total marks + while (modCount <= 4) + { + printf("Enter Student 03 Module %d Marks: ", modCount); + scanf("%d", &marks); + + sum3 = sum3 + marks; + modCount++; // increment ModuleCount + } + modCount = 1; // reset ModuleCount + printf("Student 03 Total Marks = %d\n\n", sum3); + + // For find Highest Marks and Student + if (sum1 > sum2 && sum2 > sum3) + printf("Highest Marks = %d By Student 01\n", sum1); + + else if (sum2 > sum1 && sum2 > sum3) + printf("Highest Marks = %d By Student 02\n", sum2); + + else if (sum3 > sum1 && sum3 > sum2) + printf("Highest Marks = %d By Student 03\n", sum3); + + else if (sum1 == sum2 && sum2 > sum3) + printf("Highest Marks = %d By Student 01 and 02\n", sum1); + + else if (sum1 == sum3 && sum3 > sum2) + printf("Highest Marks = %d By Student 01 and 03\n", sum1); + + else if (sum2 == sum3 && sum3 > sum1) + printf("highest Marks = %d By Student 02 and 03\n", sum2); + + else if (sum1 == sum2 && sum2 == sum3) + printf("All students gets Equal marks\n"); + + else + printf("error\n"); + + return 0; + +} diff --git a/Tutorials/2023 Feb Tutorials/Tutorial-05/Tute5ex4.c b/Tutorials/2023 Feb Tutorials/Tutorial-05/Tute5ex4.c new file mode 100644 index 0000000..2391839 --- /dev/null +++ b/Tutorials/2023 Feb Tutorials/Tutorial-05/Tute5ex4.c @@ -0,0 +1,54 @@ +#include + +int main(void) +{ + int j, l; + + // printf("Enter Number: "); + // scanf("%d", &i); + + // i = 7; + + // for Print First 7 Lines + for (j = 1; j <= 7; j++) { // line break + for (l = 1; l <= j; l++) { // add astericks mark + printf("* "); + } + printf("\n"); // go to new line + } + + // for Print next 4 lines. + for (j = 7; j >= 0; j -= 2) { // line break * note 01 + for (l = 1; l <= j; l++) { // add astericks mark + printf("* "); + } + printf("\n");// go to new line + } + + return 0; +} + +// Note 01 via Beej's guide to c programming +/* +It’s split into three parts, separated by semicolons. The first is the initialization, the second is the loop +condition, and the third is what should happen at the end of the block if the loop condition is true. All +three of these parts are optional. + +for (initialize things; loop if this is true; do this after each loop) +Note that the loop will not execute even a single time if the loop condition starts off false. + +** for-loop fun fact! + +* You can use the comma operator to do multiple things in each clause of the for loop! + +for (i = 0, j = 999; i < 10; i++, j--) { +printf("%d, %d\n", i, j); +} + +* An empty for will run forever: + +for(;;) { // "forever" + printf("I will print this again and again and again\n" ); + printf("for all eternity until the heat-death of the universe.\n"); + +*/ diff --git a/Tutorials/2023 Feb Tutorials/Tutorial-06/Tute6ex1.c b/Tutorials/2023 Feb Tutorials/Tutorial-06/Tute6ex1.c new file mode 100644 index 0000000..a6f9f08 --- /dev/null +++ b/Tutorials/2023 Feb Tutorials/Tutorial-06/Tute6ex1.c @@ -0,0 +1,17 @@ +// Math library functions + +#include +#include + +int main(void) +{ + printf("floor = %.2f\n", floor(7.5)); + printf("ceil = %.2f\n", ceil(0.0)); + printf("ceil with negative = %.2f\n", ceil(-6.4)); + printf("log10 = %.2f\n", log10(100)); + printf("ceil,floor = %.2f\n", ceil(floor(-5.5))); + + return 0; +} + +// for more info >> ../codexample/mathstdlib.c diff --git a/Tutorials/2023 Feb Tutorials/Tutorial-06/Tute6ex2.c b/Tutorials/2023 Feb Tutorials/Tutorial-06/Tute6ex2.c new file mode 100644 index 0000000..bdaac2e --- /dev/null +++ b/Tutorials/2023 Feb Tutorials/Tutorial-06/Tute6ex2.c @@ -0,0 +1,68 @@ +/* +Write a function called circleArea() that take the radius of a circle as an argument and calculate and return the area. +In the main program read the radius value from the user, call circleArea() and display the result. + +Extended program : program extend with do-while loop & if statement. +basic program : not Extended, only exercise answer. +*/ + +//------------------------------------------------------------------------------ + +// Extended program + +#include + +float circleArea(float radius); // this is function prototype () + +// begin main function +int main(void) +{ + float circleRadius, area = 0; // declare variables + + // for looping + do{ + printf("Enter circle radius(enter '0' to exit): "); + scanf("%f", &circleRadius); + + if(circleRadius == 0) // check circleRadius is 0,(if circleRadius == 0,stop running following statements & loop) + break; + + printf("circle Area = %.2f\n\n", circleArea(circleRadius)); // calling circleArea function & print output. + + } while(circleRadius); // check circleRadius is not equal to 0, if circleRadius is 0 program exit. + + printf("\nProgram Exited..\n"); + + return 0; +} // end of main function + +// begin circleArea function +float circleArea(float radius) // this is function definition +{ + return radius * radius * (22.0/7.0); + +} // end of circleArea function + +// ------------------------------------------------------------------ + +/* +// Basic program + +#include + +float circleArea(float radius); + +int main(void) +{ + float r; + printf("Enter Radius : "); + scanf("%f",&r); //input radius + printf("Area = %.2f",circleArea(r)); //print area +} + +float circleArea(float radius) +{ + return (22/7.0)*radius*radius; +} //end of main function + +*/ diff --git a/Tutorials/2023 Feb Tutorials/Tutorial-06/Tute6ex3.c b/Tutorials/2023 Feb Tutorials/Tutorial-06/Tute6ex3.c new file mode 100644 index 0000000..7fb04a5 --- /dev/null +++ b/Tutorials/2023 Feb Tutorials/Tutorial-06/Tute6ex3.c @@ -0,0 +1,39 @@ +/* +Write three functions do the following + add - add two integers pass as parameters and return the result + multiply - multiply two integers pass as parameters and return the result + square – receive an integer as a parameter and return the result after multiplying the +number by itself. +Use these functions in the main program to calculate the result of the following mathematical +expression. +(3*4 + 5*7)^2 +*/ + +#include + +int addNumber(int num, int num1); // function prototype +int multNumber(int num, int num1); +int powerNumber(int num); + +// begin main function +int main(void) +{ + printf("Result: %d\n", powerNumber(addNumber(multNumber(3, 4),multNumber(5, 7)))); + + return 0; +} // end of main function + +int addNumber(int num, int num1) // function definition +{ + return num + num1; +} + +int multNumber(int num, int num1) // function definition +{ + return num * num1; +} + +int powerNumber(int num) // function definition +{ + return num * num; +} diff --git a/Tutorials/2023 Feb Tutorials/Tutorial-07/Tute7ex1.c b/Tutorials/2023 Feb Tutorials/Tutorial-07/Tute7ex1.c new file mode 100644 index 0000000..926af5c --- /dev/null +++ b/Tutorials/2023 Feb Tutorials/Tutorial-07/Tute7ex1.c @@ -0,0 +1,42 @@ +#include +#include + +int qualityPoints(int); // function prtotype +void testQualityPoints(void); + +int main(void) +{ + testQualityPoints(); + printf("Point = %d\n", qualityPoints(-50)); +} + +int qualityPoints(int num) +{ + if(num >= 90 && num <= 100) + return 4; + else if(num >= 80 && num <= 89) + return 3; + else if(num>= 70 && num <= 79) + return 2; + else if(num >= 60 && num <= 69) + return 1; + else if(num < 60 && num >= 0) + return 0; + else + printf("invalid input\n"); + return -1; +} + +void testQualityPoints(void) +{ + assert(qualityPoints(100) == 4); + assert(qualityPoints(90) == 4); + assert(qualityPoints(89) == 3); + assert(qualityPoints(80) == 3); + assert(qualityPoints(79) == 2); + assert(qualityPoints(70) == 2); + assert(qualityPoints(69) == 1); + assert(qualityPoints(60) == 1); + assert(qualityPoints(59) == 0); + +} diff --git a/Tutorials/2023 Feb Tutorials/Tutorial-07/Tute7ex2.c b/Tutorials/2023 Feb Tutorials/Tutorial-07/Tute7ex2.c new file mode 100644 index 0000000..5e88e9c --- /dev/null +++ b/Tutorials/2023 Feb Tutorials/Tutorial-07/Tute7ex2.c @@ -0,0 +1,36 @@ +#include +#include +#include + +double hypetenuse(double side1, double side2); // function prototype + +int main(void) +{ + double side1, side2; + + printf("Enter side 1: "); + scanf("%lf", &side1); + + printf("Enter side 2: "); + scanf("%lf", &side2); + + // Using fabs() for getting absolute value + // https://www.geeksforgeeks.org/fabs-function-in-c/ << More-info + + assert(fabs(hypetenuse(3.0, 4.0)-5.0) <= 0.001); + assert(fabs(hypetenuse(5.0, 12.0)-13.0) <= 0.001); + assert(fabs(hypetenuse(8.0, 15.0)-17.0) <= 0.001); + printf("%lf\n", hypetenuse(side1, side2)); + + return 0; + +} + +double hypetenuse(double side1, double side2) +{ + double hypeten; + + hypeten = sqrt(pow(side1, 2) + pow(side2, 2)); + + return hypeten; +} diff --git a/Tutorials/2023 Feb Tutorials/Tutorial-07/Tute7ex3.c b/Tutorials/2023 Feb Tutorials/Tutorial-07/Tute7ex3.c new file mode 100644 index 0000000..3f14ff2 --- /dev/null +++ b/Tutorials/2023 Feb Tutorials/Tutorial-07/Tute7ex3.c @@ -0,0 +1,40 @@ +#include +#include +#include + +double hypetenuse(double side1, double side2); // function prototype +void testHypetenuse(void); + +int main(void) +{ + double side1, side2; //declare variables + + printf("Enter side 1: "); + scanf("%lf", &side1); + + printf("Enter side 2: "); + scanf("%lf", &side2); + + testHypetenuse(); + + printf("%lf\n", hypetenuse(side1, side2)); + + return 0; + +} + +double hypetenuse(double side1, double side2) +{ + double hypeten; + + hypeten = sqrt(pow(side1, 2) + pow(side2, 2)); // calculation + + return hypeten; +} + +void testHypetenuse(void) // assert function +{ + assert(fabs(hypetenuse(3.0, 4.0)-5.0) <= -0.001); + assert(fabs(hypetenuse(5.0, 12.0)-13.0) <= 0.001); + assert(fabs(hypetenuse(8.0, 15.0)-17.0) <= 0.001); +} diff --git a/Tutorials/2023 Feb Tutorials/Tutorial-08/Tute8ex1extended.c b/Tutorials/2023 Feb Tutorials/Tutorial-08/Tute8ex1extended.c new file mode 100644 index 0000000..2426099 --- /dev/null +++ b/Tutorials/2023 Feb Tutorials/Tutorial-08/Tute8ex1extended.c @@ -0,0 +1,43 @@ +// Please refer 2021 Feb Tutorial 8 Answer.... +// https://www.programiz.com/c-programming/c-arrays-functions + + +#include + +#define SIZE 10 + +void outputMarks(int stdMarks[SIZE]); //function prototype + +int main(void) +{ + int stdMarks[SIZE], i,marks; + + for(i = 0; i < SIZE; i++) + { + printf("Enter Student %d marks: ", i + 1); + scanf("%d", &marks); + + if(marks > 0 && marks <= 20) // check marks is valid or not. + stdMarks[i] = marks; + else + { + printf("Invalid Input\n"); + i = i - 1; // to re-prompt + continue; + } + } + + outputMarks(stdMarks); //calling the function + + return 0; +} + +void outputMarks(int stdMarks[SIZE]) // stdMarks[] <-- also correct(bgc 6.2.2) +{ + printf("\n%10s %10s\n","Student Num", "Marks"); + + for(int i = 0; i < SIZE; i++) + { + printf("%10d %10d\n", i + 1, stdMarks[i]); + } +} diff --git a/Tutorials/2023 Feb Tutorials/Tutorial-08/Tute8ex2.c b/Tutorials/2023 Feb Tutorials/Tutorial-08/Tute8ex2.c new file mode 100644 index 0000000..ce83f5c --- /dev/null +++ b/Tutorials/2023 Feb Tutorials/Tutorial-08/Tute8ex2.c @@ -0,0 +1,54 @@ +#include + +int outputMarks(int stdMarks[10]); //function prototype +int mean(int stdMarks[10]); + +int main(void) +{ + int stdMarks[10], i,marks; + + for(i = 0; i < 10; i++) + { + printf("Enter Student %d marks: ", i + 1); + scanf("%d", &marks); + + if(marks > 0 && marks <= 20) // check marks is valid or not. + stdMarks[i] = marks; + else + { + printf("Invalid Input\n"); + i = i - 1; // to re-prompt + continue; + } + } + + outputMarks(stdMarks); //calling the function + + printf("Mean = %d\n", mean(stdMarks)); + + return 0; +} + +int outputMarks(int stdMarks[10]) // stdMarks[] <-- also correct(bgc 6.2.2) +{ + printf("\n%10s %10s\n","Student Num", "Marks"); + + for(int i = 0; i < 10; i++) + { + printf("%10d %10d\n", i + 1, stdMarks[i]); + } + + return 0; +} + +int mean(int stdMarks[10]) +{ + int sum = 0; + + for(int i = 0; i < 10; i++) + { + sum = sum + stdMarks[i]; + } + + return sum / 10; +} diff --git a/Tutorials/2023 Feb Tutorials/Tutorial-08/Tute8ex3.c b/Tutorials/2023 Feb Tutorials/Tutorial-08/Tute8ex3.c new file mode 100644 index 0000000..51a6082 --- /dev/null +++ b/Tutorials/2023 Feb Tutorials/Tutorial-08/Tute8ex3.c @@ -0,0 +1,43 @@ +#include + +int main(void) +{ + int motion[5]; + int temp; + + for(int i = 0; i < 5; i++) + { + printf("Enter Value %d: ", i + 1); + scanf("%d", &motion[i]); + } + + printf("Initial Value\t"); + + for(int i = 0; i < 5; i++) + { + printf("%d ", motion[i]); + } + + temp = motion[0]; + + for(int j = 0; j < 5; j++) + { + if(j == 4) + { + motion[j] = temp; + } + else + { + motion[j] = motion[j + 1]; + } + } + + printf("\nRotated Value\t"); + + for(int i = 0; i < 5; i++) + { + printf("%d ", motion[i]); + } + + return 0; +} diff --git a/Tutorials/2023 Feb Tutorials/Tutorial-08/Tute8ex4.c b/Tutorials/2023 Feb Tutorials/Tutorial-08/Tute8ex4.c new file mode 100644 index 0000000..96d02ee --- /dev/null +++ b/Tutorials/2023 Feb Tutorials/Tutorial-08/Tute8ex4.c @@ -0,0 +1,22 @@ +#include + +int main(void) +{ + int numbers[10] = { 19, 3, 15, 7, 11, 9, 13, 5, 17, 1}; + + printf("%-9s %-7s %s \n", "Element", "Value", "Histogram"); + + for(int i = 0; i < 10; i++) + { + printf("%-9d %-7d ", i, numbers[i]); + + for(int j = 1; j <= numbers[i]; j++) + { + printf("*"); + } + + printf("\n"); + } + + return 0; +} diff --git a/Tutorials/2023 Feb Tutorials/Tutorial-08/readme.md b/Tutorials/2023 Feb Tutorials/Tutorial-08/readme.md new file mode 100644 index 0000000..a7ed440 --- /dev/null +++ b/Tutorials/2023 Feb Tutorials/Tutorial-08/readme.md @@ -0,0 +1 @@ + Please refer 2021 Feb Tutorial 8 Answer diff --git a/Tutorials/2023 Feb Tutorials/Tutorial-09/Tute9ex1.c b/Tutorials/2023 Feb Tutorials/Tutorial-09/Tute9ex1.c new file mode 100644 index 0000000..d907506 --- /dev/null +++ b/Tutorials/2023 Feb Tutorials/Tutorial-09/Tute9ex1.c @@ -0,0 +1,25 @@ +#include +#include + +int main(void) +{ + char word[100]; + + printf("Input word: "); + scanf("%99s", word); // https://www.youtube.com/watch?v=fjMrDDj47E8 + + int len = strlen(word); + int len2 = strlen(word) / 2; + + for(int i = 0; i < len2; i++) + { + if(word[i] != word[--len]) + { + printf("\"%s\" is not Palindrome\n", word); + return 0; + } + } + printf("\"%s\" is a Palindrome\n", word); + + return 0; +} diff --git a/Tutorials/2023 Feb Tutorials/Tutorial-09/readme.md b/Tutorials/2023 Feb Tutorials/Tutorial-09/readme.md new file mode 100644 index 0000000..f195acd --- /dev/null +++ b/Tutorials/2023 Feb Tutorials/Tutorial-09/readme.md @@ -0,0 +1 @@ + Please refer 2021 Feb Tutorial 9 Answer diff --git a/Tutorials/2023 Feb Tutorials/Tutorial-10/Tute10ex1.c b/Tutorials/2023 Feb Tutorials/Tutorial-10/Tute10ex1.c new file mode 100644 index 0000000..30391f1 --- /dev/null +++ b/Tutorials/2023 Feb Tutorials/Tutorial-10/Tute10ex1.c @@ -0,0 +1,37 @@ +#include + +int main(void) +{ + FILE *number; + + int num, input; + + number = fopen("number.dat", "r+"); + + if (number == NULL) + { + printf("File cannot be open"); + return -1; + } + + printf("Enter Number: "); + scanf("%d", &input); + + do + { + fscanf(number, "%d", &num); + + if(num == input) + { + printf("Number Already in the file.!"); + return 0; + } + + } while(!feof(number)); + + fprintf(number,"%d", input); + + fclose(number); + + return 0; +} diff --git a/Tutorials/2023 Feb Tutorials/Tutorial-10/Tute10ex2.c b/Tutorials/2023 Feb Tutorials/Tutorial-10/Tute10ex2.c new file mode 100644 index 0000000..655b5b0 --- /dev/null +++ b/Tutorials/2023 Feb Tutorials/Tutorial-10/Tute10ex2.c @@ -0,0 +1,67 @@ +#include + +int main(void) +{ + FILE *app; //File Pointer + + char name[15]; // declare character array + char type; + int i, countT = 0, countS = 0, countC = 0; + + app = fopen("appoinment.dat", "w"); // open file to write + + if(app == NULL) // check file opening + { + printf("File Not Opened.\n"); + return -1; // if file not opening correctly exit the program + } + + for(i = 0; i <5; i++) // looping getting the use input + { + printf("Enter Name: "); + scanf("%s", name); + + printf("Enter Type: "); + scanf(" %c", &type); + + fprintf(app, "%-15s %c\n", name, type); // print data in to file + } + fclose(app); // close the opened file + + app = fopen("appoinment.dat", "r"); // opeb file for the reading content + + if(app == NULL) // check file opening + { + printf("File Not Opened.\n"); + return -1; // if file not opening correctly exit the program + } + + fscanf(app,"%c", &type); // reading the file contents + + while(!feof(app)) + { + if(type == 'C') + { + countC++; + } + else if(type == 'S') + { + countS++; + } + else if(type == 'T') + { + countT++; + } + + fscanf(app,"%c", &type); // reading the file contents + } + + fclose(app); + + printf("%-20s %-20s\n", "Appoinment Type", "Number of Patients"); + printf("%-20s %-20d\n", "Consulting", countC); + printf("%-20s %-20d\n", "Scanning", countS); + printf("%-20s %-20d\n", "Testing", countT); + + return 0; +} diff --git a/Tutorials/2023 Feb Tutorials/Tutorials-pdf/Tutorial-1.pdf b/Tutorials/2023 Feb Tutorials/Tutorials-pdf/Tutorial-1.pdf new file mode 100644 index 0000000..98ca3a8 Binary files /dev/null and b/Tutorials/2023 Feb Tutorials/Tutorials-pdf/Tutorial-1.pdf differ diff --git a/Tutorials/2023 Feb Tutorials/Tutorials-pdf/Tutorial-10.pdf b/Tutorials/2023 Feb Tutorials/Tutorials-pdf/Tutorial-10.pdf new file mode 100644 index 0000000..f2f92ea Binary files /dev/null and b/Tutorials/2023 Feb Tutorials/Tutorials-pdf/Tutorial-10.pdf differ diff --git a/Tutorials/2023 Feb Tutorials/Tutorials-pdf/Tutorial-2.pdf b/Tutorials/2023 Feb Tutorials/Tutorials-pdf/Tutorial-2.pdf new file mode 100644 index 0000000..6c69536 Binary files /dev/null and b/Tutorials/2023 Feb Tutorials/Tutorials-pdf/Tutorial-2.pdf differ diff --git a/Tutorials/2023 Feb Tutorials/Tutorials-pdf/Tutorial-3.pdf b/Tutorials/2023 Feb Tutorials/Tutorials-pdf/Tutorial-3.pdf new file mode 100644 index 0000000..eb28ad9 Binary files /dev/null and b/Tutorials/2023 Feb Tutorials/Tutorials-pdf/Tutorial-3.pdf differ diff --git a/Tutorials/2023 Feb Tutorials/Tutorials-pdf/Tutorial-4.pdf b/Tutorials/2023 Feb Tutorials/Tutorials-pdf/Tutorial-4.pdf new file mode 100644 index 0000000..af016eb Binary files /dev/null and b/Tutorials/2023 Feb Tutorials/Tutorials-pdf/Tutorial-4.pdf differ diff --git a/Tutorials/2023 Feb Tutorials/Tutorials-pdf/Tutorial-5.pdf b/Tutorials/2023 Feb Tutorials/Tutorials-pdf/Tutorial-5.pdf new file mode 100644 index 0000000..2aa3af9 Binary files /dev/null and b/Tutorials/2023 Feb Tutorials/Tutorials-pdf/Tutorial-5.pdf differ diff --git a/Tutorials/2023 Feb Tutorials/Tutorials-pdf/Tutorial-6.pdf b/Tutorials/2023 Feb Tutorials/Tutorials-pdf/Tutorial-6.pdf new file mode 100644 index 0000000..2c6ab72 Binary files /dev/null and b/Tutorials/2023 Feb Tutorials/Tutorials-pdf/Tutorial-6.pdf differ diff --git a/Tutorials/2023 Feb Tutorials/Tutorials-pdf/Tutorial-7.pdf b/Tutorials/2023 Feb Tutorials/Tutorials-pdf/Tutorial-7.pdf new file mode 100644 index 0000000..50f4401 Binary files /dev/null and b/Tutorials/2023 Feb Tutorials/Tutorials-pdf/Tutorial-7.pdf differ diff --git a/Tutorials/2023 Feb Tutorials/Tutorials-pdf/Tutorial-8.pdf b/Tutorials/2023 Feb Tutorials/Tutorials-pdf/Tutorial-8.pdf new file mode 100644 index 0000000..934a53b Binary files /dev/null and b/Tutorials/2023 Feb Tutorials/Tutorials-pdf/Tutorial-8.pdf differ diff --git a/Tutorials/2023 Feb Tutorials/Tutorials-pdf/Tutorial-9.pdf b/Tutorials/2023 Feb Tutorials/Tutorials-pdf/Tutorial-9.pdf new file mode 100644 index 0000000..d658fe5 Binary files /dev/null and b/Tutorials/2023 Feb Tutorials/Tutorials-pdf/Tutorial-9.pdf differ