Posts

Showing posts with the label C Language

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.

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 .

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

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)     {         case '+':             result=num1+num2;             break;

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!"); } }