Introduction to condition and switch

  

example of how to use condition in c

  

Different example of condition in c programming

  

example of how to use switch in c programming

  

example of different qauestion using switch in c programming

  

Introduction to Loop in c programming

  

Different question of using loop in c programming

  

Introduction to array in c programming

  

Different question and answer in array

  

Introduction to Condition and switch


program to check wheather a number is even or odd in c programming



1. Conditional Statements:


Conditional statements in C allow you to execute different blocks of code based on whether a certain condition is true or false. The most commonly used conditional statement is the "if-else" statement.


example of if stament


It's used to execute a block of code if a condition is true. For example:


#include <stdio.h>
int main() {
int num;
printf("Enter a number: ");
scanf("%d", &num);
if (num % 2 == 0)
printf("The number is even.\n");
return 0;
}



example of if-else Statement:


It's used to execute one block of code if a condition is true and another block if it's false. For example:


#include <stdio.h>
int main() {
int num;
printf("Enter a number: ");
scanf("%d", &num);
if (num % 2 == 0)
printf("The number is even.\n");
else
printf("The number is odd.\n");
return 0;
}



example of else-if Statement:


It's used to check multiple conditions one by one. The first condition that is true will execute its corresponding block of code. For example:
this is example of question going to show how to use else- if statement

here is question to check wheather a number is positive or negative


#include <stdio.h>
int main() {
int num;
printf("Enter a number: ");
scanf("%d", &num);
if (num > 0)
printf("The number is positive.\n");
else if (num < 0)
printf("The number is negative.\n");
else
printf("The number is zero.\n");
return 0;
}



Contact Us

Email: info@learn.co.rw
Phone: +250723709880
Whatsap: +250725527181

we will try to reply to your message as quickly as we can. please be aware that because of many messages we receive it take us same time to respond