Q. C Program - Accept temperatures in Fahrenheit (F) and print it in Celsius (C) and Kelvin (K)
Program
#include<stdio.h>
#include<conio.h>
int main()
{
float cel,fer,kel;
printf("Enter Temperature in Fahrenheit :");
scanf("%f",&fer);
cel= (fer-32)/1.8 ;
printf("Celsius = %f \n",cel);
kel = (fer-32)/1.8 + 273.15 ;
printf("Kelvin = %f \n",kel);
return (0) ;
}
Output:
Enter Temperature in Fahrenheit :56
Celsius = 13.333333
Kelvin = 286.483337


5 Comments
# 6 : Remove Punctuation
ReplyDeleteimport string
text = input("Enter a text: ")
clean_text = ""
for ch in text:
if ch not in string.punctuation:
clean_text += ch
print("\nOriginal Text:", text)
print("Text without punctuation:", clean_text)
# 7 : Remove Extra Spaces
ReplyDeletetext = input("Enter a sentence with extra spaces: ")
clean_text = " ".join(text.split())
print("\nBefore: [" + text + "]")
print("After : [" + clean_text + "]")
# 8 : Search for a Word
ReplyDeletesentence = input("Enter a sentence: ")
word = input("Enter the word to search: ")
words = sentence.lower().split()
if word.lower() in words:
print("\nThe word '" + word + "' is FOUND in the sentence.")
print("Number of times it appears:", words.count(word.lower()))
else:
print("\nThe word '" + word + "' is NOT FOUND in the sentence.")
# 9 : Count Sentences
ReplyDeleteimport re
paragraph = input("Enter a paragraph: ")
parts = re.split(r"[.!?]+", paragraph)
sentences = []
for part in parts:
if part.strip() != "":
sentences.append(part.strip())
print("\nNumber of sentences:", len(sentences))
for i, sentence in enumerate(sentences, 1):
print(str(i) + ". " + sentence)
# 10: Replace a Word
ReplyDeletesentence = input("Enter a sentence: ")
old_word = input("Enter the word to replace: ")
new_word = input("Enter the new word: ")
new_sentence = sentence.replace(old_word, new_word)
print("\nOriginal Sentence:", sentence)
print("Updated Sentence :", new_sentence)