Posts

Write a Python program that takes a list of numbers as input and returns the sum of all even numbers in the list

Image
  Program Code: Program Explanation: The function sum_even_numbers takes a single argument numbers, which is a list of integers. The function uses a list comprehension to create a new list of even_numbers containing only the even numbers from the input list. This is done using the modulo operator %, which returns the remainder of dividing a number by 2. If the remainder is 0, then the number is even, and it is added to the even_numbers list. The sum function is then called on the even_numbers list to compute the sum of all the even numbers in the list. The sum of the even numbers is returned as the output of the function. Overall, this function is a simple and efficient way to compute the sum of even numbers in a list of integers.

Python Program to Check Whether an Integer is Armstrong Number or Not.

Image
  An Armstrong number is a number that is equal to the sum of its own digits each raised to the power of the number of digits in the number. For example, 153 is an Armstrong number because 1^3 + 5^3 + 3^3 = 153. Program Code: Program Explanation: We first take an input integer from the user using the input() function and convert it to an integer using the int() function. We determine the number of digits in the input number by converting it to a string using the str() function, getting its length using the len() function, and storing the result in the variable num_digits. We initialize a variable called sum_of_cubes to 0, which will hold the sum of the cubes of each digit in the input number. We use a for loop to iterate over each digit in the input number. Since the input number is an integer, we first convert it to a string using the str() function so that we can iterate over each of its digits. For each digit, we convert it back to an integer using the int() function, cube it us...

Fibonacci Series Program in Python using Iteration

Image
  1. Program Code: 2. Program Explanation: We define a function called Fibonacci that takes an integer n as input. We initialize the first two terms of the Fibonacci series to 0 and 1, respectively, using tuple unpacking: a, b = 0, 1. These values will be updated as we generate the series. We check if n is equal to 0 or 1. If n is 0, then we return an empty list because there are no terms in the series. If n is 1, then we return a list with the first term of the series, which is 0. If n is greater than 1, then we initialize a list called fib_series with the first two terms of the series, which are 0 and 1. We use a for loop to iterate over the range from 2 to n - 1, since we've already accounted for the first two terms of the series. Inside the loop, we compute the next term of the series by adding the previous two terms: c = a + b. We then update the values of a and b to prepare for the next iteration: a, b = b, c. Finally, we append the new term c to the list of series terms: f...

Fibonacci Series in Python Using While Loop

Image
So, today we'll be discussing how we can make the Fibonacci series using python. What is the Fibonacci series? In the Fibonacci sequence, the sum of the two preceding numbers. it is commonly started with 0 and 1. You can read more about the history of the Fibonacci series on Wikipedia . Now, let's see how we can calculate it in python. In this python program:  We're first taking input from the user that how many terms he wants to print. (User input) Then, we have made two conditions to check if the user enters a negative number or first number so we print that accordingly. If the above of the two conditions are false then the while loop will run to print the fibonacci numbers.

How to Connect Microsoft SQL Server with Python

Image
Today we'll be discussing how you can connect Microsoft SQL Server Database(2019) with Python. So, you have been here then I'm assuming you know pretty much about Python programming. First, you need to install pyodbc using pip - the python package manager. Now, you'll be thinking what is pyodbc? It is an open-source Python module that makes it super easy for us to access ODBC datasbases. Enter this command in your terminal: pip install pyodbc Now you need two more things to move forward: 1. Your SQL Server Instance Name 2. And your database name which you want to connect. Here's the code to connect your SQL database successfully with Python. Note: My instance is blank because I have used the default instance when installing SQL Server.

Swapping Using Two Variables in Python

Image
So, today we'll learn how we can swap using two variables only. using three variables is popular among programmers and they think it can't be done using two variables.  But it's not the case it can be done, of course in certain conditions, such as only in numbers. We can use some maths and sort the values of variables easily. Let's how to do swapping in python using two variables only. EASY CHEESY So, here's the logic which you need to understand, instead of memorizing the code. Let's consider: a = 1 b = 2 So we'll do some maths in it to swap it. a = 1 + 2, a is now equal to 3  b = 3 - 2, b is now equal to 1  and finally, a = 3 - 1, a is now equal to 2. swapping done using some simple maths. Here's how you can do it in python.  

How Badly Website Loading Time Affects Your Business

Image
The world is moving fast, everyone wants more work in less time. This is the biggest reason why users have no patience for website with poor loading time. In this internet world it is must to have a lightning-fast website. While page load time matters more on mobile or tablets, in which AMP has played a significant role. Additionally, website speed also matters in search engine rankings. Facts and Studies These are certain facts and studies about website speed. Users Wants Speedy Website In the survey and feedback, of 1,048 online shoppers, Forrester Consulting concluded that: 47% users expects that a webpage would load in or under two seconds. 40% leaves the website if web takes more than three seconds to load. 52% stated fast loading page is important for devotion to site. Lost in Conversions A 1 second delay in page response can result in a 7% reduction in conversions. Lost in Business If users distracted from loading time then 14 will shop from another websit...

Sorting Using 3 Variables in C Language

Image
Learn, how you can sort values using three variables easily. However, there are many methods you can do it from here is the one. After including the library and creating the main method. 1. First, we'll declared three variables 'n1', 'n2' , 'n3' and temporary variable 'temp' 2. Then, we'll be taking input from users in these three variables, 'n1', 'n2', 'n3' 3. After that we're using the if-else condition to swap variables: if n1 is greater than n2, then we're swapping the value using the temporary variable if n2 is greater than n3, then we're swapping the value using the temporary variable if n1 is greater than n3, then we're swapping the value using the temporary variable 4. After all the swapping we're printing the value after swapping.

Java Programming Task 1 With Solution

Image
Task 1 : Design a class named StopWatch. The class contains: Private data fields are startTime and endTime with getter methods.  A no-arg constructor that initializes startTime with the current time. A method named start() that resets the startTime to the current time. A method named stop() that sets the endTime to the current time. A method named getElapsedTime() that returns the elapsed time for the stopwatch in milliseconds. Write a test program and create a stopwatch and call all methods. Solution : The task is explanatory itself, if you focus however here's an explanation for you: First of all, declare two private data fields 'startTime' & 'endTime' as said in the task, as we know the time can set in seconds means values in points, therefore, we have to use data type float. Then, we have asked to create a no argument constructor which will be used to initialize the current time.  Then we have to create methods of s...

C Program to Check the Quadrant of X and Y Coordinates

Image
How This Program Works? First, we'll write a function in which we'll create 4 conditions to check whether number lies in the first, second, third or fourth quadrant. For first quadrant value of x and y should be greater than 0. For the second quadrant value of x should be less than 0 and the value of y should be greater than 0. For the third quadrant value of x should be less than 0 and the value of y should be greater than 0. For the fourth quadrant value of x should be greater than 0 and the value of y should be less than 0. Then in the main method, we'll take the value of x and y from the user and pass the value to the function to check in which quadrant value lies. C Program to Check the Quadrant of X and Y Coordinates You May Also Like: Return Multiple Values from a Function . Calculator in C . C Program to Convert Fahrenheit into Celsius.

Quadratic Formula in C language

Image
Remember the famous quadratic formula? Let's learn today, how we can implement it in c language. First, we'll take variables a, b and c for the quadratic formula values. Pos and Neg variable for negative and postive value of quadratic formula. Then, we'll take the values of a,b, and c as input from the user. After that, we'll calculate '4' into 'a' into 'c' i.e (4 * a * c) and save the answer in d variable and apply the condition value of d is greater than 0 than continue, else show complex roots. In if condition we'll apply the formula to calculate the value of quadratic value. and save the answer in their respective variable.  After that, we'll print the answers. Related: Marksheet in C. How to Return Multiple Values from a function . Calculator in C Using If-Else .

Clear Screen in C

Image
Learn how you can clear screen in command prompt or cmd in C language. Clearing screen is important for big projects, let's seen how you can do this in your c program too. First, we'll add a new library file, which will help us to clear the screen without calling this library, clearing screen task can't be done. Then, we'll write a code which will clear the screen in cmd. How to Clear Screen in C You Might Like: Marksheet in C . Convert Miles into Meters in C.

How to Create Marksheet in C

Image
Here's an example, how you can create a mark sheet in C language. First, we'll take the marks of five subjects from the user to generate the mark sheet. These marks will be stored in a variable of the float data type. After that, we'll apply the formula to calculate the percentage and design a template for mark sheet. Marksheet in C Related: C Program for fibonacci serires. Calculator in C using functions (subroutines).

C Program to Convert Miles into Meter

Image
Here's the complete c program to convert miles into meters. First, we're taking two variables named mile and meter in float data types. Then, we'll get the value from the user in miles. After getting the value we'll apply the formula to convert miles into meters. How to Convert Miles into Meter in C? Related: Convert Fahrenheit into Celsius  in C. C Program to check number is Positive or Negative. Calculator in C .

Pseudocode To Check Which Number is Greater

Image
Pseudocode To Check Which Number is Greater 0.  Start 1.  Print "Please Enter the value of the First number" 2.  input ← num1 3.  Print "Please Enter the value of the Second number" 4.  input ← num2 5.  If num1 == to num2 6. Print "Both numbers are equal" 7.  Else If num1 > num 2 8. Print "The first number is greater" 9.  Else 10. Print "The second number is greater" 11. End

Calculate Reduced Mass in C language

Image
First, we'll take input the values of masses of the first & second body, and then store them in the variables m1 and m2 respectively. Then, we'll apply a condition, since mass can't be negative or less than zero. After that, we'll apply the formula to calculate reduced mass. Calculate Reduced Mass in C language  Related: Second Equation of Motion in C . C Program to check the number is positive negative or zero. How to Get Multiple Value from a Function in C . Calculator in C . 

Second equation of motion in C language

Image
Before going into this, we'll use a library of math.h, for mathematic operations. First, we'll take input the values of initial velocity, time and acceleration, and then store the inputs in the variables. Then, we will apply a condition, because time can't be negative. After that, we'll apply the formula to calculate distance. Second equation of motion in the C language  Related : C Program to check even or odd . How to Calculate K.E in C . C Program to Calculate Acceleration .

How to Calculate Kinetic Energy in C

Image
How this Program Work? Before starting we will be using a library of math.h, for mathematic operations. First, we'll take input the values of mass and velocity and store the input in the variables. Then, we will apply a condition, because mass can't be negative. After that, we'll apply the formula to calculate kinetic energy. Calculate Kinetic Energy in C Related: C Program to Calcualte Acceleration Calculate Speed in C C Program to Calculate Final Velocti y

How to Return Multiple Values From a Function in C Using Pointers

Image
In this example, we will learn how you can get two values from a function in C using pointers. For this example, we're making a function of quadratic formula to return multiple values because the quadratic formula has two significant one positive and one negative. In function, we can only get one value in the main method with the return, so for the second value we will use a pointer How to Get Multiple Values From a Function Using Pointers

Pseudocode to Check, Number is Odd or Even

Image
Here's the complete Pseudocode to check number is even or odd. You can check from two methods whether the number is odd or even. Pseudocode to Check Whether Number is Odd or Even 1st Method: 0. Start 1. Print "Enter Any Number to Check, Even or Odd" 2. Read input of a number 3. If number mod = 0 4. Print "Number is Even" 5. Else 6. Print "Number is Odd" 7. End 2nd Method: 0. Start 1. Print "Enter Any Number to Check, Even or Odd" 2. Read input of a number 3. If number mod = 1 4.  Print "Number is Odd" 5. Else 6.  Print "Number is Even" 7. End Learn How to check even or odd in C language .

C Program to Convert Fahrenheit to Celsius

Image
Here's the C Program to convert temperature from Fahrenheit to Celsius (degree centigrade). How this Program Work? First, We will take the value from the user in Fahrenheit and convert it into Celsius. Then, we'll apply the formula to convert Fahrenheit into Celsius. Then, we'll print the value in Celsius. C Program to Convert Fahrenheit Into Celsius #include<stdio.h> void main() { //declaration of variable float f, c; /* f variable is used for farenheit c variable is used to store value in Celsius */ // getting the value from user in farenheit printf("Enter the temperature in Farenheit"); scanf("%f",&f); // formula to convert farenheit into celsius c = ( ( (f-32) * 5 ) / 9); // printing the value in celsius printf("The temperature in Celsius is %.1f Celsius",c); } You May Also Like: Fibonacci Series in C Calculator in C using Switch

C Program to Calculate Acceleration

Image
Learn how to find the value of acceleration in C language. How this Program Work? First, we're taking the value of initial velocity, final velocity and time from the user as input. After that, we'll apply condition if time is positive then calculate the acceleration using formula we defined and print the value of acceleration. And if time is negative then terminate the program because time can't be negative. C Program to Calculate Acceleration #include<stdio.h> void main() { //declaration of variable float v, u, t, acc; /* we're taking v variable for initial velocity, u variable for final velocity t variable for time */ //getting the value of initial velocity from user printf("Enter the Value Of Initial Velocity"); scanf("%f",&v); //getting the value of final velocity from user printf("Enter the Value Of final Velocity"); scanf("%f",&u); //getting the value of tim...

C Program to Calculate Final Velocity

Image
Here's the complete program to calculate final velocity in C language. How this Program Works? First, we'll take the value of initial velocity, time and acceleration from the user as input. Then, we'll apply condition if time is positive then put the values of acceleration, time and initial velocity in the formula to calculate the value of final velocity. If the condition is false means time is negative then the program will end, because time can't be negative. C Program To Calculate Final Velocity #include<stdio.h> void main(){ //declaration of variable float v,t, acc, fv; //getting the value of initial velocity from user printf("Enter the Value Of Initial Velocity 'V' "); scanf("%f",&v); //getting the value of time from user printf("Enter the Value Of Time 'T' "); scanf("%f",&t); //getting the value of acceleration from user printf("Enter the Value Of ac...

C Program to Make a Simple Calculator Using Switch Case

Image
Example to create a basic calculator to add, subtract, multiply, divide and find a percentage. How this program work? First, this program will take two operands from user i.e. first-number and the second-number, after that it will ask the user to choose the operator for addition, subtraction, multiply, divide. Then, the program will print the answer of two operands depending upon the operator chosen by the user. C Program to Make a Calculator Using Switch Case #include <stdio.h> int main() {     int num1,num2;     float result;     char ope;     printf("Enter first number: \n");     scanf("%i",&num1);     printf("Enter second number: \n");     scanf("%i",&num2);     printf("Choose any of these operator : + | - | * | / | % %  ");     scanf(" %c",&ope);     //starting of switch     switch(ope)     {   ...

C Practice Program on TCS

Consider a scenario that TCS find their salary using these conditions: Number of Packages Transferred: TCS pays 5000 per package delivery to Permanent Employees and 3000 per package delivery to Temporary Employees. Travel Allowance: TCS provide 500 per travel as allowance and 300 per travel as an allowance to Temporary Employees. Shift: TCS pays 10% increment, who did night shifts. So write a program in C to calculate employees basic pay. Also, TCS use Grading System for its employee to calculate net pay (consider grade is entered by a user) A1 5% A2 10% A3 15%

C Program for Calculator Using Function (SubRoutine)

Image
Here is the code to create a calculator using C language. How Program Work? First, we'll be creating a function for calculations and apply all the condition in function to perform calculations. Next, in the main method, we'll be taking two operands from the user and an operator from user to perform an operation (calculation) i.e. addition, subtraction, multiplication, division. Then, In main we will call a function to pass the value which user entered to function to perform the calculation. After taking three value from the user i.e. two operands and one operator. As the function is called it will check the operator and perform the calculation and give the answer accordingly. Calculator in C Using Function #include <stdio.h> //function start double cal(double val1, double val2, char ope) { if(ope == '+') { printf("Addition of two numbers is %lf ", val1 + val2); } else if(ope == '-') { printf("Subtraction o...

C Programs for Fibonacci Series

Here's the C Program to print the complete Fibonacci series of n number (n = number entered by the user at runtime). Also, in a different example, you can generate Fibonacci series up to a certain number, like 100 or 50 whatever you want. In Fibonacci series, the next number is the sum of previous two numbers, For Example : 0, 1 , 1, 2, 3, 5, 8, 13, 21 and so on.. C Programs for Fibonacci Series 1. Fibonacci Series Using For Loop 2. Fibonacci Series Using While Loop Related: Marksheet in C . Calculator Using If-else in C . Fahrenheit into Celsius in C . C program for Even or Odd .

C Program to Calculate the Speed

Image
Example of how you can calculate the speed in C language, using the value of distance and time with the specific conditions. How this Program Work? First, we'll take input the value of distance and time from the user. After that, we will be applying condition if time and distance are positive then calculate the value of speed. And, if time or distance is negative then terminate the program. C Program to Calculate the Speed #include<stdio.h> void main(){ //declaration of variable float d,t, speed; /* we're taking d variable for distance t variable for time */ //getting the value of d from user printf("Enter the Value Of Distance"); scanf("%f",&d); //getting the value of t from user printf("Enter the Value Of Time 'T' "); scanf("%f",&t); if(t>0 && d>0) //applying condition since time and distance can't be negative { // formula to find speed sp...

C Program to Check the Number is Positive or Negative

Image
Here's the program to check whether the number is positive or negative. In this program, we are taking the value at runtime by the user to check whether it is negative or positive using if else condition. Code to Check Number is Positive or Negative #include<stdio.h> void main() { int num; printf("Enter Any Number"); scanf("%i", &num); if(num > 1) { printf("The number is positive"); } else if(num < 0) { printf("The number is negative"); } else { printf("Invalid Input!"); } }

C Program to Check the Number is Positive, Negative or Zero

Image
#include<stdio.h> void main(){ int num; printf("Enter Any Number"); scanf("%i", &num); if(num > 1) { printf("The number is positive"); } else if(num < 0) { printf("The number is negative"); } else if(num == 0) { printf("The number is Zero"); } else { printf("Invalid Input!"); } }

Age and Gender Checking Program in C-language

Image
#include<stdio.h> void main() { char gen; //decleration of variable int age; //decleration of variable printf("Enter Your Gender, M for Male and F for Female"); scanf("%c",& gen); printf("Enter Your Age"); scanf("%i",& age); if(age > 16 && gen == 'F' || age > 16 && gen == 'f' ) { printf("Female is genius"); } else if(age > 16 && gen == 'M' || age > 16 && gen == 'm' ) { printf("Male have to do more effort"); } }

How to Check Even or Odd Number in C language

Image
#include<stdio.h> void main() { int num; //declaration of variables printf("Enter Any Number"); scanf("%i", &num); // getting the first value from user // if-else condition to check even or odd          if(num% 2 == 0) { printf("You have entered even number"); }         if(num% 2 == 1) { printf("You have entered odd number"); } }

C Program to Check Two Numbers If Even or Odd

Image
#include<stdio.h> void main() { int num1, num2; //declaration of variables printf("Enter First Number"); scanf("%i", &num1); // getting the first value from user printf("Enter Second Number"); scanf("%i", &num2); // getting the second value from user if(num1% 2 == 0 && num2% 2 == 0) { printf("You have entered two even numbers"); } if(num1% 2 == 1 && num2% 2 == 1) { printf("You have entered two odd numbers"); }         else { printf("You have entered one even number and one odd number"); } }

Calculator in C: Add, Sub, Mul and Div Using If-Else in C

Image
Related: Calculator in C language using a switch case. Calculator in C using the function.

C Basic data types Syntax: Int, Float, Character and Double

Image
In this post, I'll be discussing C language basic data types that are int, float, double and char. What are these? int - integer: used for a  whole number input. float - floating point: a number with a fractional part. double - a double-precision floating point value. char - a single character. C Basic Datatype Syntax Method 1 (int method): #include<stdio.h> int main() // the int needs to add return { //decleration of variable char c; // char data type variable decleration int i; // int data type variable decleration float f; // float data type variable decleration double d; // double data type variable decleration printf("Enter Any Character "); scanf("%c", &c); // %c is used to get character value printf("Enter Any Integer "); scanf("%i", &i); // %i or %d is used to get integer value printf("Enter Any Float "); scanf("%f", &f); // %f is used to get float va...