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

added palindrome in java and python #23

Open
wants to merge 3 commits into
base: main
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
15 changes: 15 additions & 0 deletions Mathematics/Celsius_to_Fahrenheit.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//Function for conversion
float convertCelFahrenheit(float c)
{
return ((c * 9.0 / 5.0) + 32.0);
}
int main()
{
float celsius, fahrenheit;
printf("Enter temperature in Celsius: ");
scanf("%f", &celsius);
//called function to convert celsius to fahrenheit
fahrenheit = convertCelFahrenheit(celsius);
printf("%.2f Celsius = %.2f Fahrenheit", celsius, fahrenheit);
return 0;
}
18 changes: 18 additions & 0 deletions Mathematics/Palindrome.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import java.util.*;
class Palindrome
{
public static void main(String args[])
{
String original, reverse = ""; // Objects of String class
Scanner in = new Scanner(System.in);
System.out.println("Enter a string/number to check if it is a palindrome");
original = in.nextLine();
int length = original.length();
for ( int i = length - 1; i >= 0; i-- )
reverse = reverse + original.charAt(i);
if (original.equals(reverse))
System.out.println("Entered number is a palindrome.");
else
System.out.println("Entered number isn't a palindrome.");
}
}
11 changes: 11 additions & 0 deletions Mathematics/palindrome.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
num=int(input("Enter a number:"))
temp=num
rev=0
while(num>0):
dig=num%10
rev=rev*10+dig
num=num//10
if(temp==rev):
print("The number is palindrome!")
else:
print("Not a palindrome!")