Fahrenheit and Celsius are two unit for measure temperature. We have standard formula to Convert Fahrenheit to Celsius, using this formula we can change temperature.
Formula
c =(f -32)*5/9;
Convert Fahrenheit to Celsius in C++
#include<iostream.h>#include<conio.h>void main(){float cel, far;
clrscr();
cout<<"Enter temp. in Fahrenheit: ";
cin>>far;
cel =(far -32)*5/9;
cout<<"Temp. in Celsius: "<<cel;
getch();}
Output
Enter temp. in Fahrenheit: 98
Temp. in Celsius: 36.666668
Fahrenheit and Celsius are two unit for measure temperature. We have standard formula to Convert Celsius to Fahrenheit using this formula you can change temperature Fahrenheit to Celsius.
Formula
f = c *9/5+32;
Convert Celsius to Fahrenheit in C++
#include<iostream.h>#include<conio.h>void main(){float cel, far;
clrscr();
cout<<"Enter temp. in Celsius: ";
cin>>cel;
far = cel *9/5+32;
cout<<"Temp. in Fahrenheit: "<<far;
getch();}
Output
Enter temp. in Celsius: 36
Temp. in Fahrenheit: 96.000
A Leap Year is a year containing one additional day that means in that year 366 day. and these year are divisible by 4 so if you write this program must be check year divisible by 4.
C++ Program to Check Leap Year
#include<iostream.h>#include<conio.h>void main(){int y;
cout<<"Enter a year: ";
cin>>y;if(y%4==0){
cout<<"Leap Year";}else{
cout<<"Not a Leap Year";}
getch();}
Sum of digits means add all the digits of any number, for example we take any number like 358. Its sum of all digit is 3+5+8=16. Using given code we can easily write c++ program.
C++ program to find sum of digits of a number
#include<iostream.h>#include<conio.h>void main(){int a,no,sum=0;
clrscr();
cout<<"Enter any num : ";
cin>>no;while(no>0){
a=no%10;no=no/10;
sum=sum+a;}
cout<<"\nSum of digits: "<<sum;
getch();}
Output
Enter any number : 584
Sum of digits : 17
Explanation of code
a=no%10;
Here we find remainder of given number, using Modulo Operator we find remainder of any number, Using this step we get only last digits.
a=no/10;
Here After dividing any number by 10 we get all digits except last digits.
Sum=Sum+a;
Using this statement we find sum of all digits. In first iteration it add 0 and last digits and store in Sum variable, in second iteration it add Previous sum values and last digits of new number and again store in Sum variable, and so on upto while condition is not false.
Full form of Ascii is American Standard Code for Information Interchange. Ascii is a character-encoding scheme. Originally based on the English alphabet, every character or number have its own Ascii value for example Ascii value of a is 97.
Find Ascii Value of Number Using Library Function
#include<iostream.h>#include<ctype.h>#include<conio.h>int main(void){int number, result;
clrscr();
cout<<"Enter any Character/Symbol/Digits: ";
number = getch();
result = toascii(number);
cout<<"Ascii value: "<<result;
getch();}
Output
Enter any Character/Symbol/Digits:a
Ascii value: 97
Code Explanation
Here toascii() is a predefined function in "ctype.h" header file which gives or return Ascii value of any given value.
getch() is a predefined function in "conio.h" header file which take or receive one value from keyboard.
Find Ascii Value of Number without using Library Function
To find cube root of any number we need to find 0.3 power of any number. For example if you need to find cube root of 27 then calculate 0.3 power of 27, result is 3. And one another method for this program is use cbrt() function it is pre-defined in math.h header file.
Cube Root program in C++
#include<iostream.h>#include<conio.h>#include<math.h>void main(){int num, ans;
clrscr();
cout<<"Enter any number";
cin>>num;
ans=pow(num,1.0/3.0);
ans++;
cout<<"\n\Cube of "<<num<<" is: "<<ans;
getch();}
Output
Enter any Number: 27
Cube of 27 is: 3
Explanation of Program
Here we receive any number from keyboard and after that we find 1.0/3.0 power of number because square root of any number means power of 1/3.
pow() is a predefined function in math.h header file, it is used for calculate power of any number.
C++ program to find Cube Root
#include<iostream.h>#include<conio.h>#include<math.h>void main(){int num,ans;
clrscr();
cout<<"Enter any Number: ";
cin>>num;
ans=cbrt(num);;
cout<<"\n Cube Root of "<<num<<" is: "<<ans;
getch();}
Output
Enter any Number: 27
Cube Root of 27 is: 3
Explanation of Code
cbrt() is a predefined function in math.h header file, it is used for calculate cube root of any number.
Cube Root of number using user defined function
Cube Root program in C++
#include<iostream.h>#include<conio.h>int cube(int);void main(){int num;
clrscr();
cout<<"Enter any number";
cin>>num;
cout<<"\n\Cube of "<<num<<" is: "<<cube(num);
getch();}int cube(int num){int ans;
ans=pow(num,0.3);
ans++;return(ans);
getch();}
Output
Enter any Number: 64
Cube of 64 is: 4
Explanation of Program
Here we receive any number from keyboard and after that we multiply number by 0.33333 because square root of any number means power of 1/3 and 1/3=0.33333.
pow() is a predefined function in math.h header file, it is used for calculate power of any number.
For calculate Square Root of a number we multiply number by 0.5 because square root of any number means power of 1/2 and 1/2=0.5. And one another method for this program is use sqrt() function it is pre-defined in math.h header file.
C++ program to find Square Root
#include<iostream.h>#include<conio.h>#include<math.h>void main(){int num,ans;
clrscr();
cout<<"Enter any Num: ";
cin>>num;
ans=pow(num,0.5);
cout<<"\n Squre of "<<num<<" is: "<<ans;
getch();}
Output
Enter any Num: 9
Squre of 9 is: 3
Explanation of Code
pow() is a predefined function in math.h header file, it is used for calculate power of any number.
C++ program to find Square Root
#include<iostream.h>#include<conio.h>#include<math.h>void main(){int num,ans;
clrscr();
cout<<"Enter any Number: ";
cin>>num;
ans=sqrt(num);;
cout<<"\n Squre of "<<num<<" is: "<<ans;
getch();}
Output
Enter any Number: 9
Squre of 9 is: 3
Explanation of Code
sqrt() is a predefined function in math.h header file, it is used for calculate square root of any number.
Find Square Root By passing values in Function
Example
#include<iostream.h>#include<conio.h>#include<math.h>int square(int);void main(){int num;
clrscr();
cout<<"Enter any Num: ";
cin>>num;
cout<<"\n Square of "<<num<<" is: "<<square(num));
getch();}int square(int num){int ans;
ans=pow(num,0.5);return(ans);
getch();}
To find the LCM (Least Common Multiple) of two or more numbers, make multiple of numbers and choose common multiple. Then take lowest common multiple, this lowest common multiple is LCM of numbers. For example;
LCM
Suppose find LCM of 3 and 4
Multiple of 3 : 3, 6, 9, 12, 15, 18, 21, 24,.......
Multiple of 4 : 4, 8, 12, 16, 20, 24, 28,.....
So, common multiple of 3 and 4 is 12, 24
and Least Common Multiple is 12
LCM of 3 and 4 is: 12
C++ program to find LCM of two numbers
#include<iostream.h>#include<conio.h>void lcm(int,int);void main(){int a,b;
clrscr();
cout<<"Enter two numbers: ";
cin>>a;
cin>>b;
lcm(a,b);
getch();// return 0;}//function to calculate l.c.mvoid lcm(int a,int b){int m,n;
m=a;
n=b;while(m!=n){if(m < n){
m=m+a;}else{
n=n+b;}}
cout<<"\nL.C.M of "<<a<<" and "<<b<<" is "<<m;}
Link list 2
Link list 1
Link list 3