Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create Celsius_to_Fahrenheit.c #111

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions Celsius_to_Fahrenheit.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
C Program to Convert Celsius to Fahrenheit
How to write a C program to convert Celsius to Fahrenheit with an example. The formula behind the temperature conversion of Celsius to Fahrenheit in C is: Fahrenheit = (9/5) * Celsius) + 32

C program to convert Celsius to Fahrenheit
This C program to change Celsius to Fahrenheit lets the user enter the temperature value in Celsius. Next, we are going to convert the user-specified temperature in Celsius to Fahrenheit in C.


//C program to convert Celsius to Fahrenheit
#include <stdio.h>

int main()
{
float celsius, fahrenheit;

printf("Please Enter temperature in Celsius: \n");
scanf("%f", &celsius);

// Convert the temperature from celsius to fahrenheit
fahrenheit = ((celsius * 9)/5) + 32;
// fahrenheit = ((9/5) * celsius) + 32;
// fahrenheit = ((1.8 * celsius) + 32;

printf("\n %.2f Celsius = %.2f Fahrenheit", celsius, fahrenheit);

return 0;
}
C program to convert Celsius to Fahrenheit
Within this C program to change Celsius to Fahrenheit example, the following statements will ask the user to enter the temperature value in Celsius. And the scanf statement in this C program will assign the user entered values to declare variable already Celsius.

printf("Please Enter temperature in Celsius: \n");
scanf("%f", &celsius);
We can use any of the below-specified formulas to convert the temperature in Celsius to Fahrenheit

fahrenheit = ((celsius * 9)/5) + 32
fahrenheit = ((9/5) * celsius) + 32 => ((1.8 * celsius) + 32;


Last C programming printf statement will print the output

printf("\n %.2f Celsius = %.2f Fahrenheit", celsius, fahrenheit);
Let me show you the Fahrenheit value of Zero Celsius

Please Enter temperature in Celsius:
0

0.00 Celsius = 32.00 Fahrenheit
31 changes: 31 additions & 0 deletions Converter.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
C Program to Convert Kilometer to Meter Centimeter and Millimeter

C Program to Convert Kilometer to Meter Centimeter and Millimeter
This program allows the user to enter the length in Kilometers, and then convert the length into Meters, Centimeters, and Millimeters


1 Kilometer = 1000 Meters
1 Kilometer = 100000 Centimeters
and, 1 Kilometer = 1000000 Millimeters

/* C Program to Convert Kilometer to Meter Centimeter and Millimeter */

#include <stdio.h>

int main()
{
float Millimeter, Centimeter, Meter, Kilometer;

printf("\n Please Enter the Length in Kilometers (km) : ");
scanf("%f", &Kilometer);

Meter = Kilometer * 1000.0;
Centimeter = Kilometer * 100000.0;
Millimeter = Kilometer * 1000000.0;

printf("\n %.2f Kilometers = %.2f Meters", Kilometer, Meter);
printf("\n %.2f Kilometers = %.2f Centimeters", Kilometer, Centimeter);
printf("\n %.2f Kilometers = %.2f Millimeters", Kilometer, Millimeter);

return 0;
}
106 changes: 106 additions & 0 deletions Symmetric_Matrix.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
C Program to check Matrix is a Symmetric Matrix
How to write a C Program to check Matrix is a Symmetric Matrix or Not with example. Any square matrix called a Symmetric Matrix if a matrix is equal to its Transposed Matrix.

C Program to check Matrix is a Symmetric Matrix or Not 1
C Program to check Matrix is a Symmetric Matrix Example
This program allows the user to enter the number of rows and columns of a Matrix. Next, we are going to check whether the given matrix is a symmetric matrix or not using For Loop.


/* C Program to check Matrix is a Symmetric Matrix or Not */

#include<stdio.h>

int main()
{
int i, j, rows, columns, a[10][10], b[10][10], Count = 1;

printf("\n Please Enter Number of rows and columns : ");
scanf("%d %d", &i, &j);

printf("\n Please Enter the Matrix Elements \n");
for(rows = 0; rows < i; rows++)
{
for(columns = 0;columns < j;columns++)
{
scanf("%d", &a[rows][columns]);
}
}
//Transpose of matrix
for(rows = 0; rows < i; rows++)
{
for(columns = 0;columns < j; columns++)
{
b[columns][rows] = a[rows][columns];
}
}

for(rows = 0; rows < i; rows++)
{
for(columns = 0; columns < j; columns++)
{
if(a[rows][columns] != b[rows][columns])
{
Count++;
break;
}
}
}
if(Count == 1)
{
printf("\n The Matrix that you entered is a Symmetric Matrix ");
}
else
{
printf("\n The Matrix that you entered is Not a Symmetric Matrix ");
}

return 0;
}
C Program to check Matrix is a Symmetric Matrix or Not 2
In this Program to check Matrix is a Symmetric Matrix, We declared single Two dimensional arrays Multiplication of size of 10 * 10.

Below statements in this program asks the User to enter the Matrix size (Number of rows and columns. For instance 2 Rows, 2 Columns = a[2][2] )

printf("\n Please Enter Number of rows and columns : ");
scanf("%d %d", &i, &j);
Next, we used for loop to iterate every item present in a[2][2] matrix. Conditions inside the for loops ((rows < i) and (columns < j)) ensures the compiler, not to pass the matrix limit. Otherwise, the matrix will overflow. The scanf statement inside the C Programming for loop will store the user entered values in every individual array element such as a[0][0], a[0][1], …..

for(rows = 0; rows < i; rows++).
{
for(columns = 0; columns < j; columns++)
{
scanf("%d", &a[rows][columns]);
}
}
In the next line, We used For Loop to transpose this Matrix. I suggest you to refer Transpose a Matrix article to understand the same

for(rows = 0; rows < i; rows++)
{
for(columns = 0;columns < j; columns++)
{
b[columns][rows] = a[rows][columns];
}
}
Next, we are trying to check whether each element in a matrix is equal to the transposed matrix or not.

for(rows = 0; rows < i; rows++)
{
for(columns = 0; columns < j; columns++)
{
if(a[rows][columns] != 1 && a[columns][rows] != 0)
{
Flag = 0;
break;
}
}
}
Let me try the program with other values

Please Enter Number of rows and columns : 3 3

Please Enter the Matrix Elements
10 20 30
40 50 60
70 80 90

The Matrix that you entered is Not a Symmetric Matrix
130 changes: 130 additions & 0 deletions array.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
C Program to find Second largest Number in an Array
How to write a C Program to find the Second largest Number in an Array with example.? Before going into this second largest number in c example.

C Program to find Second largest Number in an Array
This program for finding the second largest number in c array asks the user to enter the Array size, Array elements, and the Search item value. Next, this C program will find the Second largest Number in this Array using For Loop.


/* C Program to find Second largest Number in an Array */

#include <stdio.h>
#include <limits.h>

int main()
{
int arr[50], i, Size;
int first, second;

printf("\n Please Enter the Number of elements in an array : ");
scanf("%d", &Size);

printf("\n Please Enter %d elements of an Array \n", Size);
for (i = 0; i < Size; i++)
{
scanf("%d", &arr[i]);
}

first = second = INT_MIN;

for (i = 0; i < Size; i++)
{
if(arr[i] > first)
{
second = first;
first = arr[i];
}
else if(arr[i] > second && arr[i] < first)
{
second = arr[i];
}
}
printf("\n The Largest Number in this Array = %d", first);
printf("\n The Second Largest Number in this Array = %d", second);

return 0;
}
C Program to find Second largest Number in an Array 1
In this C Program to find second largest number in an array, We declared 1 One Dimensional Arrays arr[] of size 10 and also declared i to iterate the Array elements. Please refer to Array in C article.

Below statements will ask the user to enter the array arr[] size (Number of elements an Array can hold), and assign the user entered values to Size variable.

printf("\n Please Enter the size of an array \n");
scanf("%d",&Size);
Below For loop will help to iterate each cell present in a[5] array. Condition inside the for loops (i < Size) will ensure the compiler, not to exceed the array limit.


The C Programming scanf statement inside the for loop store the user entered values into individual array element such as arr[0], arr[1], arr[2], arr[3], arr[4]

for(i = 0; i < Size; i++)
{
scanf("%d",&arr[i]);
}
In the next line, We have one more for loop, used to iterate each element in an array. If Statement inside the For loop will check whether arr[i] is equal to search item or not. If it is true, then Flag will become 1 and exit from the Loop (using Break Statement)

for (i = 0; i < Size; i++)
{
if(arr[i] > first)
{
second = first;
first = arr[i];
}
else if(arr[i] > second && arr[i] < first)
{
second = arr[i];
}
}
From the above screenshot, you can observe that the user inserted values for C second largest number are
a[5] = {10, 90, 80, 90, 80}


First Iteration: for (i = 0; 0 < 5; 0++)

The value of i will be 0, and the condition (i < 5) is True. So, program will start executing the statements inside the loop until the condition fails.

If (arr[i] > Search) => if(10 > Int_Min) – Condition is True
second = Int_Min
first = 10

Second Iteration: for (i = 1; 1 < 5; 1++)
The condition (1 < 5) is True.
If (arr[i] > Search) => if(90 > 10) – Condition is True
second = 10
first = 90

Third Iteration: for (i = 2; 2 < 5; 2++) – The condition (2 < 5) is True.

If (arr[i] > Search) => if(80 > 90) – Condition is false. So, it will enter into Else If block


else if(arr[i] > second && arr[i] < first)

=> else if(80 > 10 && 80 < 90) – Condition is True
second = arr[i] = 80

Fourth Iteration: for (i = 3; 3 < 5; 3++) – The condition (3 < 5) is True.


If (arr[i] > Search) => if(90 > 90) – Condition is false. So, it will enter into Else If block

else if(arr[i] > second && arr[i] < first) => else if(90 > 80 && 90 < 90)
Condition is False

Fifth Iteration: for (i = 4; 4 < 5; 4++) – The condition (4 < 5) is True.


If (arr[i] > Search) => if(80 > 90) – Condition is false. So, it will enter into Else If block

else if(arr[i] > second && arr[i] < first) => else if(80 > 80 && 80 < 90) – Condition is False

Sixth Iteration: for (i = 5; 5 < 5; 5++)
The condition (4 < 5) is False. So, it will exit from the For Loop

Let me try different array elements for C Program to find Second largest Number in an Array

Please Enter the Number of elements in an array : 10

Please Enter 10 elements of an Array
10 10 10 10 10 -5 -5 -2 10 10

The Largest Number in this Array = 10
The Second Largest Number in this Array = -2
Loading