Convert celsius to farenheit in C++

#include <iostream> using namespace std;   int main() { double ctemp; // Celsius temperature double ftemp; // Fahrenheit temperature cout << "Input a Celsius temp and press ENTER: "; cin >> ctemp; ftemp = (ctemp * 1.8) + 32; cout << "Fahrenheit temp is: " << ftemp << endl;   return 0; }
Continue reading…

Enjoyed this post? Share it!

 
 

A recursive solution to the towers of Hanoi problem in C

#include <stdio.h>   void Hanoi(int, char, char, char)   int main() { char src,aux,dest; int n;   src=’A’; aux=’B’; dest=’C’;   printf("Enter the number of discs in the game : "); scanf("%d",&n); if(n == 0) printf("nNothing has to be moved.n"); else Hanoi(n,src,aux,dest); return 0; } void Hanoi(int n,char src,char aux,char dest) { if(n == 1) […]
Continue reading…

Enjoyed this post? Share it!

 
 

Program to compute a specified Fibonacci number using recursion – modified

#include <stdio.h> long ncalls=0;   long fib(int);   int main() { int n;   printf("Enter the value : "); scanf("%d",&n); printf("nFib(%d) = %ld.",n,fib(n)); printf("nNo of calls to the function : %dn",ncalls); return 0; }   long fib(int n) { ncalls++; if(n > 2) return (fib(n-1) + fib(n-2)); else return 1; }
Continue reading…

Enjoyed this post? Share it!