#include <iostream.h>
// Fundamental idea of Euclid's algorithm (one of the oldest known algorithms)
// gcd(a,0) = a
// gcd(a,b) = gcd(b,a%b)
int gcd (int a, int b)
{
int temp;
while (b != 0)
{
temp = a % b;
a = b;
b = temp;
}
return(a);
}
int main ()
{
int x, y;
cout << "Enter two natural numbers: ";
cin >> x >> y;
cout << "gcd(" << x << ", " << y << ") = " << gcd(x,y) << endl;
return(0);
}
# include <iostream.h>
# include <conio.h>
# include <math.h>
void main ()
{
clrscr();
int a,b=0,sum=0;
long int n;
cout<<"Enter the NO. : ";
cin>>n;
for(;n>0;)
//counts the digits
{
a=n%10;
n=n/10;
b++;
}
for(;n>0;)
{
a=n%10;
sum=sum+pow(a,b);
n=n/10;
}
if(sum==n)
{
cout<<"IT IS AN ARMSTRONG NUMBER...";
getch();
}
else
{
cout<<"IT IS NOT AN ARMSTRONG NUMBER...";
getch();
}
}
#include <iostream.h>
#include <conio.h>
void main()
{
clrscr();
int choice;
float ctemp,ftemp;
cout << "1.Celsius to Fahrenheit" << endl;
cout << "2.Fahrenheit to Celsius" << endl;
cout << "Choose between 1 & 2 : " << endl;
cin>>choice;
if (choice==1)
{
cout << "Enter the temperature in Celsius : " << endl;
cin>>ctemp;
ftemp=(1.8*ctemp)+32;
cout << "Temperature in Fahrenheit = " << ftemp << endl;
}
else
{
cout << "Enter the temperature in Fahrenheit : " << endl;
cin>>ftemp;
ctemp=(ftemp-32)/1.8;
cout << "Temperature in Celsius = " << ctemp << endl;
}
getch();
}
Scaricare iostream.h e conio.h per usare codice
#include<iostream.h>
#include<conio.h>
class complex
{
private:
float real,img;
public:
void assign(float x,float y)
{
real=x;
img=y;
}
void print()
{
if(img>=0)
cout<< real<<"+"<< img<<"i";
else
cout<< real<< img<<"i";
getch();
}
};
void add( float a,float b,float c, float d)
{
float e,f;complex g;
e=a+c;
f=b+d;
g.assign(e,f);
g.print();
}
void sub( float a,float b,float c, float d)
{
float e,f;complex g;
e=a-c;
f=b-d;
g.assign(e,f);
g.print();
}
void mul( float a,float b,float c, float d)
{
float e,f; complex g;
e=a*c-b*d;
f=b*c+a*d;
g.assign(e,f);
g.print();
}
void main()
{
float a,b,c,d;
complex x,y,z;
clrscr();
cout<<" for complex 1:";
cout<<"real part:";
cin>>a;
cout<<"imaginary part:";
cin>>b;
cout<<" for complex 2:";
cout<<"real part:";
cin>>c;
cout<<"imaginary part:";
cin>>d;
x.assign(a,b);
y.assign(c,d);
cout<<"***original data:***\n";
cout<<"Complex 1:\n";x.print();
cout<<"\n Complex 2:\n";y.print();
cout<<"\n***\n";
cout<<"\n Addition:\n";add(a,b,c,d);
cout<<"\n Subtraction:\n";sub(a,b,c,d);
cout<<"\n Multipication:\n";mul(a,b,c,d);
}
Aggiungeremo a breve semplici codici per sviluppare piccole app
Uscita nuovo gs4
Sarà nuovo o un evoluzione dell s3 ?
benvenuti nel nuovo sito di "sviluppando" .
vi auguro una buona permanenza !!!!