Steemian Friends,
Today, I will write a teaching assignment for @alejos7ven sir in Week 04 of Teaching Engagement Challenge Session 20. The subject is Basic programming course: Lesson #4 Control structures. Part 1. Conditionals. I hope everyone will like my writing.
Design By Canva
Programming Conditional Structure:
To solve any problem with computer programming language, it is necessary to solve the task with conditions. There are different types of conditions in computer programming. As an example, I will write about If and If else conditions today. There are several other conditional statements in computer programming. Complex problems can be solved easily through conditional statements.
If Conditional Structure:
A condition is given through the If structure. If the function is true, then the code will execute, and if false, then the code will stop. I have given an example of an if-conditional structure below and used the If condition to find an even and odd number. The If condition will execute if the number typed is even. Again, the next If condition will work if it is odd.
if (num1>num2)
printf("Large = %d\n", num1);
#include<stdio.h>
int main()
{
int num;
printf("Enter an integer : ");
scanf("%d",& num);
{
if(num%2==0)
printf("Even\n");
if(num%2!=0)
printf("odd\n");
}
return 0;
}
Else Condition:
Like If, else is a conditional statement. Suppose the If condition is not true then the else condition will execute. Below I have shown an else condition as an example.
else
printf("odd\n");
#include<stdio.h>
int main()
{
int num;
printf("Enter an integer : ");
scanf("%d",& num);
{
if(num%2==0)
printf("Even\n");
else
printf("odd\n");
}
return 0;
}
For example, two input numbers are the same; the else condition is executed instead of the If condition, and the other condition is executed as the output.
#include<stdio.h>
int main()
{
int num1, num2;
printf("Enter first number : ");
scanf("%d", &num1);
printf("Enter second number : ");
scanf("%d", &num2);
if (num1>num2)
printf("Large = %d\n", num1);
if (num1<num2)
printf("Large = %d\n", num2);
else
printf("Number are equal");
return 0;
}
The program uses if-and-else conditions. After typing 1, the program's output will show the text "You have turned on the light. " If you type 2 again, the program's output will show "You have left the room."
#include<stdio.h>
int main()
{
int x;
printf("Enter the value of x: \n");
scanf("%d", &x);
if(x == 2)
{
printf("Welcome to the room what do you want to do\n");
printf("You hsve turned on the light\n");
else
{
printf("Welcome to the room what do you want to do\n");
printf("You have left the room\n");
}
return 0;
}
#include<stdio.h>
int main()
{
int x;
printf("Enter the value of x: \n");
scanf("%d", &x);
if(x == 1)
{
printf("Welcome to the room what do you want to do\n");
printf("You hsve turned on the light\n");
else
{
printf("Welcome to the room what do you want to do\n");
printf("You have left the room\n");
}
return 0;
}
The homework condition was 70 marks high for the program by making four ratings. I created the program by calculating the grades of our country's education system. I apologize for making my condition slightly different from yours.
Marks | Grade |
---|---|
80-100 | A+ |
70-80 | A |
60-70 | A- |
50-60 | B |
40-50 | C |
33-40 | D |
0-33 | Fail |
#include< iostream >
using namespace std;
int main()
{
int mark;
cout<<"Enter mark:";
cin>>mark;
if(mark>100)
{
cout<<"Invalid mark";
}
else if (mark<0)
{
cout<<"Invalid mark";
}
else if (mark>=80)
{
cout<<"A+";
}
else if (mark>=70)
{
cout<<"A";
}
else if (mark>=60)
{
cout<<"A-";
}
else if (mark>=50)
{
cout<<"B";
}
else if (mark>=40)
{
cout<<"C";
}
else if (mark>=33)
{
cout<<"D";
}
else
{
cout<<"Fail"<<endl;
}
}
I input a student's mark of 67, and the grade is A-conditional.
SL No. | My Invited Steemit Friends |
---|---|
1 | @memamun |
2 | @shahariar1 |
3 | @max-pro |
This is my Twitter share link :
https://twitter.com/mahadih83660186/status/1840721477882331210?t=PDVnWmfUvj7QehqzJxqy5g&s=19
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Upvoted. Thank You for sending some of your rewards to @null. It will make Steem stronger.
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
This post has been upvoted/supported by Team 5 via @philhughes. Our team supports content that adds to the community.
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Thank You Dear @philhughes....
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit