Skip to main content

Posts

Showing posts with the label C program

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

C program to find sum of digits of a number using recursion.

 C  program to find sum of digits of a number using recursion. #include <stdio.h> int sumOfDigits(int num); int main() {     int num, sum;     printf("Enter a number: ");     scanf("%d", &num);     sum = sumOfDigits(num);     printf("The sum of digits of %d is %d.\n", num, sum);     return 0; } int sumOfDigits(int num) {     if (num == 0) {         return 0;     } else {         return (num % 10) + sumOfDigits(num / 10);     } } Explanation :  The program starts by including the standard input-output library stdio.h. The program defines a function sumOfDigits that takes an integer argument num and returns the sum of its digits. The function is defined using recursion. Inside the sumOfDigits function, there is an if statement that checks if the number num is equal to 0. If it is, the function returns 0 as the sum of digits. If num is n...

C program to check if a number is binary or not

C program to check if a number is binary or not  #include <stdio.h> int isBinary(int num) {     while (num != 0) {         if (num % 10 > 1) {             return 0;         }         num /= 10;     }     return 1; } int main() {     int num;     printf("Enter a number: ");     scanf("%d", &num);     if (isBinary(num)) {         printf("%d is a binary number.\n", num);     } else {         printf("%d is not a binary number.\n", num);     }     return 0; } Explanation :  This program defines a function isBinary that takes an integer num as input and returns 1 if num is a binary number, and 0 otherwise. The function checks each digit of the number by dividing it by 10 and checking if the remainder is greater than 1. If any digit is greater ...

C program to find greatest among three integers

C program to find the greatest among three integers: #include <stdio.h> int main() {      int num1, num2, num3;  printf("Enter three integers: ");     scanf("%d %d %d", &num1, &num2, &num3);    if(num1 > num2 && num1 > num3) {         printf("%d is the greatest.", num1);     }     else if(num2 > num1 && num2 > num3) {         printf("%d is the greatest.", num2);     }     else {         printf("%d is the greatest.", num3);     }     return 0; } In this program, we first declare three integer variables num1, num2, and num3. We then prompt the user to enter three integers using printf() and read those integers using scanf(). Next, we use a series of if and else if statements to compare the three numbers and determine which is the greatest. We use the logical operators && and || ...

C program to check whether a number is palindrome or not

C to check whether a number is a palindrome or not using iteration: include <stdio.h> int main () { int num, reversedNum = 0 , remainder, originalNum;   printf ( "Enter an integer: " ); scanf ( "%d" , &num);  originalNum = num; // reverse the number   while (num != 0 )  {  remainder = num % 10 ; reversedNum = reversedNum * 10 + remainder;  num /= 10 ;  }   // check if the number is palindrome or not   if (originalNum == reversedNum) {   printf ( "%d is a palindrome number.\n" , originalNum);   }  else {   printf ( "%d is not a palindrome number.\n" , originalNum);  }   return 0; } Explanation : We first take an integer as input from the user using scanf . We then store the original number in a separate variable called originalNum . We use a while loop to reverse the input number. In each iteration, we get the remainder of the number when divided by 10 using the modulus operator (%). We then add ...

C program for Fibonacci series

C program to print fibonacci series using iteration  #include <stdio.h> int main() {     int n, i, fib0 = 0, fib1 = 1, fib;  printf("Enter the number of terms: ");     scanf("%d", &n);   printf("Fibonacci Series: ");   for (i = 1; i <= n; i++) {         printf("%d ", fib0);         fib = fib0 + fib1;         fib0 = fib1;         fib1 = fib;     }     return 0; } Explanation : *  The program first prompts the user to enter the number of terms in the Fibonacci series. * It initializes variables fib0 and fib1 to the first two terms of the series. * The for loop is used to iterate from 1 to n, and in each iteration, it prints the value of fib0, which is the current term of the series. * The fib variable is used to calculate the next term of the series by adding fib0 and fib1. * Then fib0 is updated to the value of fib1, and fib1 is upd...

Important C programs

1) Hello World Program: #include<stdio.h> int main() {     printf("Hello, World!");     return 0; } 2) Program to Add Two Numbers: #include<stdio.h> int main() {     int num1, num2, sum;     printf("Enter two numbers: ");     scanf("%d %d", &num1, &num2);     sum = num1 + num2;     printf("Sum = %d", sum);     return 0; } 3) Program to Find Factorial of a Number: #include<stdio.h> int main() {     int num, i, fact=1;     printf("Enter a number: ");     scanf("%d", &num);     for(i=1; i<=num; i++)     {         fact *= i;     }     printf("Factorial of %d = %d", num, fact);     return 0; } 4) Program to Check Whether a Number is Prime or Not: #include<stdio.h> int main() {     int num, i, flag=0;     printf("Enter a number: ");     scanf("%d",...