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...

Iterative statement

Iterative Statements
Iterative statements are used to repeat the implementation of a series of statements until the specified expression becomes false. C supports three types of repetitive statements also known as looping 
statements. They are
* while loop
* do–while loop
* for loop
In this part, we will discuss all these statements.

while loop
The while loop supports a mechanism to repeat one or more statements while a specific condition is true. Figure below shows the syntax and general form of a while loop.
Note that in the while loop, the condition is verified before any of the statements in the statement block is implemented. If the condition is true, only then the statements will be implemented, otherwise if the condition is false, the control will jump to statement y, that is the next statement outside the while loop block.
In the flow diagram it is clear that we require to constantly update the condition of the while loop. It is this condition which defines when the loop will end. The while loop will implement as long as the condition is true. Note that if the condition is not at all updated and the condition not at all becomes false, then the computer will run into an infinite loop which is not at allSensible. For example, the following code prints the first 10 numbers using a while loop.
#include <stdio.h>
int main()
{
int i = 1;
while(i<=10)
{
 printf("\n %d", i);
 i = i + 1; // condition updated
}
return 0;
}
Note that initially i = 1 and is less than 10, i.e., the condition is true, so in the while loop the value of i is printed and its value is incremented by 1. When i=11, the condition becomes false and the loop ends.
Write a program to calculate the sum of numbers from m to n.
#include <stdio.h>
int main()
{
int n, m, i, sum =0;
printf("\n Enter the value of m : ");
scanf("%d", &m);
i=m;
printf("\n Enter the value of n : ");
scanf("%d", &n);
while(i<=n)
{
 sum = sum + i;
 i = i + 1;
}
printf("\n The sum of numbers from %d to %d = %d", m, n, sum);
return 0;
}
Output
Enter the value of m : 2
Enter the value of n : 10
The sum of numbers from 2 to 10 = 54

do–while Loop
The do–while loop is same as the while loop. The only difference is that in a do–while loop, at the end of the loop condition is tested. As the test condition is calculated at the end, this means that the body of the loop gets implemented at least one time (even if the condition is false). Below figure shows the syntax and the general form of a do–while loop.
Fig: do while construct
Note that the test condition is encompass in parentheses and followed by a semi-colon. The statements in the statement block are enclosed within curly brackets. The curly brackets are voluntery if there is only one statement in the body of the do–while loop.
The do–while loop continues to implement while the condition is true and when the condition becomes false, the control moves to the statement following the do–while loop.
The main disadvantage of using a do–while loop is that it always implements at least once, so even if the user gives some invalid data, the loop will implement. However, do–while loops are broadly used to print a list of options for menu-driven programs. For example, consider the following code.
#include <stdio.h>
int main()
{
int i = 1;
do
{
 printf("\n %d", i);
 i = i + 1;
} while(i<=10);
return 0;
}
What do you think will be the output? Yes, the code will print numbers from 1 to 10.
Write a program to calculate the average of first n numbers.
#include <stdio.h>
int main()
{
int n, i = 0, sum =0;
float avg = 0.0;
printf("\n Enter the value of n : ");
scanf("%d", &n);
do
{
 sum = sum + i;
 i = i + 1;
} while(i<=n);
avg = (float)sum/n;
printf("\n The sum of first %d numbers = %d",n, sum);
printf("\n The average of first %d numbers = %.2f", n, avg);
return 0;
}
Output
Enter the value of n : 20
The sum of first 20 numbers = 210
The average of first 20 numbers = 10.05

for Loop
Like the while and do–while loops, the for loop gives a method to repeat a task till a specific condition is true. The synax and general form of a for loop is given in Fig. below.
Fig: for loop construct
When a for loop is used, the loop variable is initialized only once. With every repetitive, the value of the loop variable is updated and the condition is verified. If the condition is true, the statement block of the loop is implemented, else the statements comprising the statement block of the for loop are skipped and the control moves to the statement following the for loop body.
In the syntax of the for loop, initialization of the loop variable permits the programmer to give it a value. Second, the condition defines that while the conditional expression is true, the loop
should continue to repeat itself. Every repetition of the loop must make the condition to exit the loop approachable. So, with every iteration, the loop variable must be updated. Updating the loop 
variable may include incrementing the loop variable, decrementing the loop variable or setting it to some other value like, i +=2, where i is the loop variable.
Note that every section of the for loop is divided from the other with a semi-colon. It is possible that one of the divisions may be empty, though the semi-colons still have to be there. However, 
if the condition is empty, it is calculated as true and the loop will repeat until something else stops it.
The for loop is mostly used to implement a single or a group of statements for a limited number of times. The following code shows how to print the first n numbers using a for loop.
#include <stdio.h>
int main()
{
int i, n;
printf("\n Enter the value of n :");
scanf("%d", &n);
for(i=1;i<=n;i++)
 printf("\n %d", i);
return 0;
}
In the code, i is the loop variable. Initially, it is initialized with 1. Suppose the user enters 10 as the value of n. Then the condition is checked, since the condition is true as i is less than n, the statement in the for loop is executed and the value of i is printed. After every iteration, the value 
of i is incremented. When i exceeds the value of n, the control jumps to the return 0 statement.
Programming Example
Write a program to determine whether a given number is a prime or a composite number.
#include <stdio.h>
#include <conio.h>
int main()
{
int flag = 0, i, num;
clrscr();
printf("\n Enter any number : ");
scanf("%d", &num);
for(i=2; i<num/2;i++)
{
if(num%i == 0)
 {
flag =1;
 break;
 }
}
if(flag == 1)
printf("\n %d is a composite number", num);
else
printf("\n %d is a prime number", num);
return 0;
}
Output
Enter any number : 37
37 is a prime number

Popular posts from this blog

Program threads

Program Threats * There are many familiar threats to modern systems. Only a few are discussed here. Trojan Horse * A Trojan Horse is a program that secretly performs some maliciousness in extra to its visible actions. * Some Trojan horses are deliberately written as such, and others are the result of legitimate programs that have become infected with viruses, (see below.) * One dangerous opening for Trojan horses is long search paths, and in specific paths which include the current directory (“.”) as part of the path. If a dangerous program having the same name as a authorized program (or a common mis-spelling, such as "sl" instead of "ls”) is placed anywhere on the path, then an unsuspecting user may be fooled  into running the wrong program by mistake. * Another classic Trojan Horse is a login imitator, which records a users account name and password, problems a "password incorrect" message, and then logs off the system. The user then tries again (with a prop...

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...

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...