Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add 2023 Feb Tutorials and Answers #109

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions Tutorials/2023 Feb Tutorials/Tutorial-01/Tute1ex3-1.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// Exercise 3 - 2
// Traveling Expenditure Calculator

#include <stdio.h>

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;
// }
19 changes: 19 additions & 0 deletions Tutorials/2023 Feb Tutorials/Tutorial-01/Tute1ex3-2.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Exersice 3 - 3
// Bonus Calculate

#include <stdio.h>

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;
}
19 changes: 19 additions & 0 deletions Tutorials/2023 Feb Tutorials/Tutorial-01/Tute1ex3-3.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Exersice 3 - 1
// Fahrehite to Celsius Calculate

#include <stdio.h>

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;
}

26 changes: 26 additions & 0 deletions Tutorials/2023 Feb Tutorials/Tutorial-02/Tute2ex1.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
//Exercise 1: Practice how to use variables in printf statement

#include <stdio.h>

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;
}
26 changes: 26 additions & 0 deletions Tutorials/2023 Feb Tutorials/Tutorial-02/Tute2ex3.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Exercise 3: Practice scanf statement in a C program

#include <stdio.h>

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
40 changes: 40 additions & 0 deletions Tutorials/2023 Feb Tutorials/Tutorial-02/Tute2ex4.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#include <stdio.h>

// 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
28 changes: 28 additions & 0 deletions Tutorials/2023 Feb Tutorials/Tutorial-03/Tute3ex2.c
Original file line number Diff line number Diff line change
@@ -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 <stdio.h>

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;

}
28 changes: 28 additions & 0 deletions Tutorials/2023 Feb Tutorials/Tutorial-03/Tute3ex3.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#include<stdio.h>

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;
}



22 changes: 22 additions & 0 deletions Tutorials/2023 Feb Tutorials/Tutorial-03/Tute3ex4-1.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#include <stdio.h>

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;

}
33 changes: 33 additions & 0 deletions Tutorials/2023 Feb Tutorials/Tutorial-03/Tute3ex4-2(extended).c
Original file line number Diff line number Diff line change
@@ -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 <stdio.h>
#include <string.h>

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;

}
26 changes: 26 additions & 0 deletions Tutorials/2023 Feb Tutorials/Tutorial-03/Tute3ex4-3.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
Enter the mark obtained for IP module and display the grade based on the
*/

#include<stdio.h>

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;
}
27 changes: 27 additions & 0 deletions Tutorials/2023 Feb Tutorials/Tutorial-04/Tute4ex1.c
Original file line number Diff line number Diff line change
@@ -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 <stdio.h>

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
Loading