C++ Program to print given series:1 2 4 8 16 32 64 128
#include<iostream.h>#include<conio.h> void main(){ clrscr(); int i; for(i=1;i<=128;i*=2) cout<<i<<” “; getch();}
#include<iostream.h>#include<conio.h> void main(){ clrscr(); int i; for(i=1;i<=128;i*=2) cout<<i<<” “; getch();}
Here you learn how to check prime number in C++. Prime number is a number which is only divided by 1 or itself. Below is the C++ program to check whether a number is prime of not. Prime Number in C++ #include<iostream> using namespace std; int main() { int n,i,flag=1; cout<<“Enter any number:”; cin>>n; …
Here you will get simple C++ program to find roots of quadratic equation ax2+bx+c=0. #include<iostream> #include<math.h> //to calculate square root using namespace std; int main() { float root1,root2,a,b,c,d,imaginaryPart,realPart; cout<<“Quadratic Equation is ax^2+bx+c=0”; cout<<“\nEnter values of a,b and c:”; cin>>a>>b>>c; d=(b*b)-(4*a*c); if(d>0) { cout<<“\nTwo real and distinct roots”; root1=(-b+sqrt(d))/(2*a); root2=(-b-sqrt(d))/(2*a); cout<<“\nRoots are “<<root1<<” and “<<root2; } …
#include<iostream.h>#include<conio.h> void main(){ clrscr(); //to clear the screen float temp,res; int choice; cout<<“Temperature Conversion”<<“nn 1.Fahrenheit to Celcius”; cout<<“n 2.Celcius to FahrenheitnnEnter your choice:”; cin>>choice; switch(choice){ case 1: { cout<<“nEnter temperature in Fahrenheit:”; cin>>temp; res=(temp-32)/1.8;} break; case 2: { cout<<“nEnter temperature in Celcius:”; cin>>temp; res=(temp*1.8)+32;} break; } cout<<“nConverted Temperature=”<<res; getch(); …
#include<iostream.h>#include<conio.h>#include<math.h> //for pow() function void main(){ clrscr(); int x,n,res; cout<<“Enter value of x and n:”; cin>>x>>n; res=pow(x,n); cout<<“nResult=”<<res; getch();}
#include<iostream.h>#include<conio.h> void main(){ clrscr(); int a,b,q,r; cout<<“Enter two numbers:”; cin>>a>>b; if(a>b) { q=a/b; r=a%b; cout<<“nQuotient=”<<q; cout<<“nRemainder=”<<r; } else cout<<“nFirst no. should be greater than second no….!!!”; getch();}
#include<iostream.h>#include<conio.h> void main(){ clrscr(); int y,f,i; cout<<“Enter inches:”; cin>>i; y=i/432; i=i%432; f=i/12; i=i%12; cout<<“Yard=”<<y<<“nFeet=”<<f<<“nInches=”<<i; getch();}
#include<iostream.h> #include<conio.h> void main() { clrscr(); //to clear screen float cube(float); //function prototype float a,cu; cout<<“Enter any …
C++ Program to find cube of a number using function Read More »