Skip to main content

AI Agents: What They Are and How They Will Change Work

Artificial intelligence has moved beyond simply answering questions and generating text. A new generation of AI systems—known as AI agents—is emerging with the ability to plan tasks, use tools, make decisions, and complete multi-step workflows with less human intervention. From managing emails and analyzing data to writing software and assisting customers, AI agents could significantly change how people work. What Are AI Agents? An AI agent is a software system that can perceive information, reason about a goal, take actions, and adapt based on the results. Traditional AI tools usually respond to a specific instruction. For example, you might ask an AI chatbot to summarize a document, and it provides a summary. An AI agent can go further. You could give an agent a goal such as: "Research three competitors, compare their pricing, summarize their main features, and prepare a report." The agent may then: 1) Understand the objective. 2) Break the task into smaller steps. 3) Searc...

Control statements

CONTROL STATEMENTS
Till now we know that the code in the C program is executed sequentially from the first line of the program to its last line. That is, the second statement is executed after the first, the third statement is executed after the second, so on and so forth. Although this is true, in some cases we want only selected statements to be executed. Control flow statements enable programmers to conditionally execute a particular block of code. There are three types of control statements: decision control (branching), iterative (looping), and jump statements. While branching means deciding what actions have to be taken, looping, on the other hand, decides how many times the action has to be taken. Jump statements transfer control from one point to another point.

Decision Control Statements
C supports decision control statements that can alter the flow of a sequence of instructions. These statements help to jump from one part of the program to another depending on whether a particular condition is satisfied or not. These decision control statements include:
(a) if statement, (b) if–else statement,
(c) if–else–if statement, and (d) switch–case statement.

if Statement
if statement is the simplest decision control statement that is frequently used in decision making. The general form of a simple if statement is shown in Fig. below
fig: if statement construct
The if block may include 1 statement or n statements enclosed within curly brackets. First the test expression is evaluated. If the test expression is true, the statements of the if block are executed, otherwise these statements will be skipped and the execution will jump to statement x.
The statement in an if block is any valid C language statement, and the test expression is any valid C language expression that evaluates to either true or false. In addition to simple relational 
expressions, we can also use compound expressions formed using logical operators. Note that there is no semi-colon after the test expression. This is because the condition and statement should 
be put together as a single statement.
#include <stdio.h>
int main()
{
int x=10;
if (x>0) x++;
printf("\n x = %d", x);
return 0;
}
In the above code, we take a variable x and initialize it to 10. In the test expression, we check if the value of x is greater than 0. As 10 > 0, the test expression evaluates to true, and the value of x is incremented. After that, the value of x is printed on the screen. The output of this program is
x = 11
Observe that the printf statement will be executed even if the test expression is false.
Note In case the statement block contains only one statement, putting curly brackets becomes optional. If there are more than one statement in the statement block, putting curly brackets becomes mandatory.

if–else Statement
We have studied that using if statement plays a vital role in conditional branching. Its usage is very simple. The test expression is evaluated, if the result is true, the statement(s) followed by the 
expression is executed, else if the expression is false, the statement is skipped by the compiler.
What if you want a separate set of statements to be executed if the expression returns a false value? In such cases, we can use an if–else statement rather than using a simple if statement. 
The general form of simple if–else statement is shown in Fig. Below
fig: if-else statement construct
In the if–else construct, first the test expression is evaluated. If the expression is true, statement block 1 is executed and statement block 2 is skipped. Otherwise, if the expression is false, statement 
block 2 is executed and statement block 1 is ignored. In any case after the statement block 1 or 2 gets executed, the control will pass to statement x. Therefore, statement x is executed in every case.
Write a program to find whether a number is even or odd.
#include <stdio.h>
int main()
{
int a;
printf("\n Enter the value of a : ");
scanf("%d", &a);
if(a%2==0)
 printf("\n %d is even", a);
else
 printf("\n %d is odd", a);
return 0;
}
Output
Enter the value of a : 6
6 is even

if–else–if Statement
C language supports if–else–if statements to test additional conditions apart from the initial test expression. The if–else–if construct works in the same way as a normal if statement. Its construct is given in Fig. below
fig: if-else-if statement construct
Note that it is not necessary that every if statement should have an else block as C supports simple if statements. After the first test expression or the first if branch, the programmer can have as many else–if branches as he wants depending on the expressions that have to be tested. For example, the following code tests whether a number entered by the user is negative, positive, or equal to zero.
#include <stdio.h>
int main()
{
int num;
printf("\n Enter any number : ");
scanf("%d", &num);
if(num==0)
 printf("\n The value is equal to zero");
else if(num>0)
 printf("\n The number is positive");
else
 printf("\n The number is negative");
return 0;
}
Note that if the first test expression evaluates to a true value, i.e., num=0, then the rest of the statements in the code will be ignored and after executing the printf statement that displays ‘The value is equal to zero’, the control will jump to return 0 statement. 

switch–case Statement
A switch-case statement is a multi-way decision statement that is a simplified version of an if–else–if block. The general form of a switch statement is shown in Fig.below
fig: switch case statement construct
The power of nested if–else–if statements lies in the fact that it can evaluate more than one expression in a single logical structure. switch statements are mostly used in two situations:
* When there is only one variable to evaluate in the expression
* When many conditions are being tested for
When there are many conditions to test, using the if and else–if constructs becomes complicated and confusing. Therefore, switch case statements are often used as an alternative to long if
statements that compare a variable to several ‘integral’ values (integral values are those values that can be expressed as an integer, such as the value of a char). Switch statements are also used to handle the input given by the user.
We have already seen the syntax of the switch statement. The switch case statement compares the value of the variable given in the switch statement with the value of each case statement that 
follows. When the value of the switch and the case statement matches, the statement block of that particular case is executed.
Did you notice the keyword default in the syntax of the switch case statement? Default is the case that is executed when the value of the variable does not match with any of the values of the case statements. That is, default case is executed when no match is found between the values of switch and case statements and thus there are no statements to be executed. Although the default case is optional, it is always recommended to include it as it handles any unexpected case.
In the syntax of the switch–case statement, we have used another keyword break. The break statement must be used at the end of each case because if it is not used, then the case that matched and all the following cases will be executed. For example, if the value of switch statement matched with that of case 2, then all the statements in case 2 as well as the rest of the cases including default will be executed. The break statement tells the compiler to jump out of the switch case statement and execute the statement following the switch–case construct. Thus, the keyword break is used 
to break out of the case statements.
Advantages of Using a switch–case Statement
Switch–case statement is preferred by programmers due to the following reasons:
* Easy to debug
* Easy to read and understand
* Ease of maintenance as compared to its equivalent if–else statements
* Like if–else statements, switch statements can also be nested
* Executes faster than its equivalent if–else construct
Programming Example
Write a program to determine whether the entered character is a vowel or not.
#include <stdio.h>
int main()
{
char ch;
printf("\n Enter any character : ");
scanf("%c", &ch);
switch(ch)
{
 case ‘A’:
 case ‘a’:
 printf("\n %c is VOWEL", ch);
 break;
 case ‘E’:
 case ‘e’:
 printf("\n %c is VOWEL", ch);
 break;
 case ‘I’:
 case ‘i’:
 printf("\n %c is VOWEL", ch);
 break;
 case ‘O’:
 case ‘o’:
 printf("\n %c is VOWEL", ch);
 break;
 case ‘U’:
 case ‘u’:
 printf("\n %c is VOWEL", ch);
 break;
 default: printf("\n %c is not a vowel", ch);
}
return 0;
}
Output
Enter any character : j
j is not a vowel
Note that there is no break statement after case A, so if the character A is entered then control will execute the statements given in case a.

Popular posts from this blog

Organic Farming: A Pathway to Sustainable Agricultural Production

Introduction : In recent years, organic farming has gained considerable attention as a sustainable alternative to conventional agriculture. As concerns over environmental degradation, food security, and public health rise, organic farming offers a holistic approach to agricultural production that aligns with nature’s own processes. This blog post explores the significance of organic farming in promoting sustainable agriculture, its key principles, and the benefits it offers for farmers, consumers, and the environment. Understanding Organic Farming Organic farming is an agricultural practice that emphasizes the use of natural inputs and processes to cultivate crops and raise livestock. Unlike conventional farming, which often relies on synthetic chemicals, genetically modified organisms (GMOs), and monoculture practices, organic farming seeks to work in harmony with the environment. It avoids synthetic pesticides and fertilizers, instead focusing on building healthy soil, fostering biod...

MEMORY MAPPED FILES

Memory-mapped files           Rather than retriving data files directly via the file system with every file access, data files can be paged into memory the same as process files, resulting in much faster retrieves ( except of course when page-faults occur. ) This is called as memory-mapping a file. Basic Mechanism * Basically a file is mapped to an address range within a process's virtual address space, and then paged in as required using the ordinary demand paging system. * Note that file matches are made to the memory page frames, and are not immediately written out to disk. ( This is the purpose of the "flush( )" system call, which may also be needed for stdout in some cases. See the time killer program for an example of this) * This is also why it is important to "close()" a file when one is done writing to it - So that the data can be safely flushed out to disk and so that the memory frames can be release for other purposes. * Some systems issue special sys...

MAGNETISM

Magnetism: * The word magnetism is derived from the iron ore magnetite (Fe3O4). which was found in the island of magnesia in Greece. Gilbert who laid the foundation for  magnetism and had proposed that Earth itself behaves as a giant bar magnet. The field at the surface of the Earth is  roughly to 10^-4 T and the field extends upto a height of nearly five times the radius of the Earth.  Causes of the Earth’s magnetism: * The exact cause of the Earth’s magnetism is not known even today. Some important factors which may be the cause of Earth’s magnetism are: 1. Magnetic masses in the Earth.  2. Electric currents in the Earth.  3. Electric currents in the upper regions of the atmosphere.  4. Radiations from the Sun.  5. Action of moon etc.  *It is believed that the Earth’s magnetic field is due to the molten charged metallic fluid inside the Earth surface with a core of radius about 3500 km compared to the Earth’s radius of 6400 km.  Basic prope...