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
41 changes: 40 additions & 1 deletion 06-conditional-statements.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,22 @@ Practice Program
Check if a number is negative
*/

#include <stdio.h>

int main()
{
int n;
printf("Enter a number\n");
scanf("%d", &n);

if (n < 0)
{
printf("%d is a negative number\n", n);
}




/*

C if...else Statement
Expand All @@ -42,6 +58,23 @@ Practice Program
Check whether a number is odd or even
*/


int p;
printf("Enter a number\n");
scanf("%d", &p);

if (p % 2 == 0)
{
printf("%d is an even number\n", p);
}

else
{
printf("%d is an odd number\n", p);
}
return (0);
}

/*
C if...else Ladder
The if...else statement executes two different codes depending
Expand Down Expand Up @@ -70,4 +103,10 @@ else {
Practice Program
Program to relate two integers using ==, > or < symbol

*/


=*=*=*=*=*= Please explain this practice task =*=*=*=*=*=*=



*/
44 changes: 43 additions & 1 deletion 07-loops.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,20 @@ Print Numbers 1 - 10
Calculate the sum
*/

#include <stdio.h>

int main()
{
int sum = 0;

for ( int i = 1; i <= 10; ++i)
{
printf("%d ", i);
sum += i;
}

printf("\nsum = %d\n", sum);

/*
C while loop
The syntax of the while loop is:
Expand All @@ -51,6 +65,14 @@ Practice Program
Print Numbers 1 - 10
*/

int n = 0;

while (n < 10)
{
++n;
printf("%d ", n);
}

/*
do...while loop
The do..while loop is similar to the while loop with one important
Expand All @@ -72,4 +94,24 @@ How do...while loop works?

Practice Program
Ask for correct input continously
*/
*/


int num;
printf("Enter a number from 1 to 3\n");
scanf("%d", &num);

do
{
printf("Enter the correct input\n");
scanf("%d", &num);
}
while (num > 3);

if (num < 3)
printf("%d is correct", num);


return (0);

}
16 changes: 15 additions & 1 deletion 08-Ternary-Operator.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,18 @@ Syntax
condition ? value_if_true : value_if_false

Ternary operator can also be nested
*/
*/

#include <stdio.h>

int main()
{
int num;

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

num % 2 == 0 ? printf("%d is an even number", num) : printf("%d is an odd number", num);

return (0);
}
28 changes: 27 additions & 1 deletion 09-Nested-Loops.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,32 @@ Practice Problem
FizzBuzz
*/


#include <stdio.h>

int main(void)
{
int i;

for (i=1; i<=100; i++)
{
if (i%15 == 0)
printf ("FizzBuzz\t");

else if (i%3 == 0)
printf("Fizz\t");

else if (i%5 == 0)
printf("Buzz\t");

else
printf("%d\t", i);
}

return 0;
}


/*
int n = 6;// variable declaration
//printf("Enter the value of n :");
Expand All @@ -46,4 +72,4 @@ int n = 6;// variable declaration
}
printf("\n");
}
*/
*/
2 changes: 1 addition & 1 deletion 10-Break-and-Continue.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,4 @@ for (i = 0; i < 10; i++) {
printf("%d\n", i);
}

*/
*/
51 changes: 50 additions & 1 deletion 11-Switch-Statement.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,53 @@ The default clause inside the switch statement is optional.

Practice Program
Create a calculator
*/
*/

#include <stdio.h>

int main()
{

double n1, n2, result;
char opp;


scanf("%c", &opp);
scanf("%lf %lf", &n1, &n2);

/*if (opp != '*' && opp != '+' && opp != '%' && opp != '-')
{
printf("Enter a valid operator");
scanf("%c", &opp);
}*/


switch (opp)
{
case '+':
result = n1 + n2;
printf("%lf", result);
break;


case '-':
result = n1 - n2;
printf("%lf", result);
break;

case '/':
result = n1 / n2;
printf("%lf", result);
break;

case '*':
result = n1 * n2;
printf("%lf", result);
break;

default:
printf("Enter a valid operator");
}

return (0);
}
18 changes: 17 additions & 1 deletion TASKS/Task 001.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,20 @@ 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()
{


for ( char i = 'a'; i <= 'z' ; i++)
{
if (i != 'e' && i != 'q')
{
printf("%c\n", i);
}
}
return (0);
}
24 changes: 23 additions & 1 deletion TASKS/Task 002.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,26 @@ 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()
{
int score;

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

if (score >= 80)
{
printf("You are eligible to enrole");
}
else
{
printf("you are not eligible to enrole");
}


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

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

*/
*/

#include <stdio.h>

int main()
{
int num;

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

if (num >= 1)
{
if (num % 2 == 0)
{
printf("%d is Odd number", num);
}
else
{
printf("%d is Even number", num);
}
}
else if (num == 0)
{
printf("This is zero");
}
else
{
printf("\"Error!\" Enter a positive number");
}

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

*/
*/


#include <stdio.h>

int main()
{
char age[5], name[10];

printf("What is your name:\n");
scanf("%s", &name);
printf("How old are you\n");
scanf("%s", &age);

printf("Your name is %s and you are %s years old.", name, age);

return (0);
}
18 changes: 17 additions & 1 deletion TASKS/Task 005.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,20 @@
/*
Write a program in C to find the square of any number
using the function.
*/
*/

#include <stdio.h>
#include <math.h>

int main()
{
int x;
printf("Enter a number to find the square root\n");
scanf("%d", &x);

float res;
res = sqrt(x);
printf (" The square root of %d is: %.2f", x, res);

return 0;
}
Loading