Skip to content
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
7 changes: 7 additions & 0 deletions 00-introduction-to-c.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
# Introduction To C
What is C?
C is a compiled programming language.
Who invented c?
C was invented by Denis Ritchie
What year was c invented?
C was invented back in seventies
Why are we learning to program in c?

What's special about c?

What is c used for?

Why did we start with C?

34 changes: 32 additions & 2 deletions 06-conditional-statements.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#include <stdio.h>
int main (void)
{
/*
C if Statement
The syntax of the if statement in C programming is:
Expand All @@ -17,6 +20,14 @@ Practice Program
Check if a number is negative
*/

int num;
printf("Check if your number is positive or negative\nEnter a number : ");
scanf("%d", &num);
if (num > 0)
printf("%d is positive\n", num);
else
printf("%d is negative\n", num);

/*

C if...else Statement
Expand All @@ -41,7 +52,13 @@ statements inside the body of if are skipped from execution.
Practice Program
Check whether a number is odd or even
*/

int num1;
printf("Check if a number is Even or Odd\nEnter a number : ");
scanf("%d", &num1);
if (num1 % 2 == 0)
printf("%d is Even\n", num1);
else
printf("%d is Odd\n", num1);
/*
C if...else Ladder
The if...else statement executes two different codes depending
Expand Down Expand Up @@ -70,4 +87,17 @@ else {
Practice Program
Program to relate two integers using ==, > or < symbol

*/
*/
int age;
printf("Check your age\nEnter an age : ");
scanf("%d", &age);
if (age < 13)
printf("you are too young\n");
else if (age >= 13 && age <= 18)
printf("You are a teenager\n");
else
printf("you are an adult\n");


return (0);
}
29 changes: 26 additions & 3 deletions 07-loops.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
#include <stdio.h>

int main(void)
{
/*
In programming, a loop is used to repeat a
block of code until the specified condition is met.
Expand Down Expand Up @@ -32,7 +36,10 @@ Practice Program
Print Numbers 1 - 10
Calculate the sum
*/

printf("let's print numbers from 1 to 10 using for loop\n");
for (int i = 1; i <= 10; i++)
printf("%d ",i);
putchar('\n');
/*
C while loop
The syntax of the while loop is:
Expand All @@ -50,7 +57,14 @@ If testExpression is false, the loop terminates (ends).
Practice Program
Print Numbers 1 - 10
*/

printf("let's print numbers from 1 to 10 using while loop\n");
int i = 1;
while(i<=10)
{
printf("%d ", i);
i++;
}
putchar('\n');
/*
do...while loop
The do..while loop is similar to the while loop with one important
Expand All @@ -72,4 +86,13 @@ How do...while loop works?

Practice Program
Ask for correct input continously
*/
*/
int num;
do{
printf("Enter a random number, or 0 to quit : ");
scanf("%d", &num);
printf("You entered %d\n", num);
}while(num !=0);

return (0);
}
11 changes: 10 additions & 1 deletion 08-Ternary-Operator.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,13 @@ Syntax
condition ? value_if_true : value_if_false

Ternary operator can also be nested
*/
*/
#include <stdio.h>
int main(void)
{
int num;
printf("Enter an number : ");
scanf("%d",&num);
(num % 2 == 0) ? printf("%d is Even\n",num) : printf("%d is Odd\n", num);
return(0);
}
24 changes: 22 additions & 2 deletions 09-Nested-Loops.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
#include <stdio.h>

int main (void)
{

/*
Nested Loops
A nested loop means a loop statement inside another
Expand Down Expand Up @@ -33,7 +38,19 @@ while(condition) {
Practice Problem
FizzBuzz
*/

printf("FizzBuzz if divided by both 5 & 3.\nFizz is divided by 3.\nBuzz if divided by 5\n");
for (int i = 1; i <= 100; i++)
{
if ( i % 3 == 0 && i % 5 == 0)
printf("FizzBuzz ");
else if (i % 5 == 0)
printf("Buzz ");
else if (i % 3 == 0)
printf("Fizz ");
else
printf("%d ", i);
}
putchar('\n');
/*
int n = 6;// variable declaration
//printf("Enter the value of n :");
Expand All @@ -46,4 +63,7 @@ int n = 6;// variable declaration
}
printf("\n");
}
*/
*/

return (0);
}
46 changes: 45 additions & 1 deletion 11-Switch-Statement.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,48 @@ The default clause inside the switch statement is optional.

Practice Program
Create a calculator
*/
*/
#include <stdio.h>

int main (void)
{
printf("This is a basic calculator [a sign b]\nwhere 'a' & 'b' are numbers and 'sign' is one of those [+, -, *, /, %%]: \n");
double a,b;
char sign;
printf("Enter number a : ");
scanf("%lf", &a);

printf("Enter number b : ");
scanf("%lf", &b);

printf("Enter the operaion you want to perform : ");
scanf(" %c", &sign);

switch(sign)
{
case '+':
printf("%.2lf %c %.2lf = %.2lf\n", a, sign, b, a + b);
break;
case '-':
printf("%.2lf %c %.2lf = %.2lf\n", a, sign, b, a - b);
break;
case '*':
printf("%.2lf %c %.2lf = %.2lf\n", a, sign, b, a * b);
break;
case '/':
printf("%.2lf %c %.2lf = %.2lf\n", a, sign, b, a / b);
break;
case '%':
printf("%.2lf %c %.2lf = %d\n", a, sign, b, (int) a % (int) b);
break;

default :
printf("Error, please enter a correct operation\n");
}




return (0);
}

19 changes: 18 additions & 1 deletion TASKS/Task 001.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,21 @@ Write a program that prints the alphabet in lowercase, followed by a new line.
Print all the letters except q and e

use printf
*/
*/
#include <stdio.h>
int main (void)
{
printf("Alpahbet letters in lowercase from a to z : \n");
char c;
for (c = 97; c <= 122; c++)
printf("%c ",c);
putchar('\n');

printf("Alpahbet letters in lowercase from a to z exept e and q : \n");
for (c = 97; c <= 122; c++)
if (c != 'e' && c != 'q')
printf("%c ",c);
putchar('\n');

return (0);
}
21 changes: 20 additions & 1 deletion TASKS/Task 002.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,23 @@ Write a program that asks and reads the score of a user
If the score is less than 80, display to the user that they
are not elgible to be enrolled.
If the score is greater than or equal 80, they can be enrolled.
*/
*/

#include <stdio.h>

int main (void)
{
int score;

printf("Enter your score : ");
scanf("%d", &score);

if (score >= 0 && score < 80)
printf("your score is %d, wich is under 80\nYou are not eligible to enroll to the program.\n", score);
else if (score >= 80 && score <=100)
printf("your score is %d\nYou can enroll to the program\n", score);
else if (score < 0 || score > 100)
printf("Error... please enter a valid score\n");

return (0);
}
20 changes: 19 additions & 1 deletion TASKS/Task 003.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,22 @@ If the number is zero, display 'This is zero'

NOTE: 'userInput' should be the number entered by the user.

*/
*/
#include <stdio.h>

int main (void)
{
int num;

printf("Enter a number : ");
scanf("%d", &num);

if (num == 0)
printf("%d is Zero\n", num);
else if (num % 2 == 0)
printf("%d is Even\n", num);
else
printf("%d is Odd\n", num);

return (0);
}
18 changes: 17 additions & 1 deletion TASKS/Task 004.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,20 @@ How old are you?: 65
Output:
Your name is David and you are 65 years old.

*/
*/

#include <stdio.h>

int main (void)
{
char name[100];
int age;

printf("Enter your name : ");
scanf("%s", name);
printf("Enter your age : ");
scanf("%d", &age);

printf("Your name is %s, and you are %d years old.\n", name, age);
return (0);
}