برنامج لعزل جزء الصحيح من عدد عن كسري
#include "stdafx.h"
#include<iostream>
#include<conio.h>
using namespace std;
void intfrac(float, float&, float&);
void main()
{
float number, intpart, fracpart;
cout << "enter number to sparates :" << endl;
cin >> number;
intfrac(number, intpart, fracpart);
cout << "the interger part is " << intpart << endl;
cout << "the fraction part is " << fracpart << endl;
_getch();
}
void intfrac(float x, float &y, float &z)
{
y = int(x);
z = x - y;
}
-----------------------------------------------------------------
تحويل من inche الى centimeter
#include "stdafx.h"
#include<iostream>
#include<conio.h>
using namespace std;
void main()
{
void centimeter(double &);
double var;
cout << "enter number : " << endl;
cin >> var;
cout << "var= " << var << " inches\n";
centimeter(var);
cout << "var= " << var << " centimeter\n";
_getch();
}
void centimeter(double &x)
{
x *= 2.54;
}
----------------------------------------------------------------
نفس مثال السابق و لكن by pointer
#include "stdafx.h"
#include<iostream>
#include<conio.h>
using namespace std;
void centimeter(double *);
void main()
{
double var;
cout << "enter number : " << endl;
cin >> var;
cout << "var= " << var << " inches\n";
centimeter(&var);
cout << "var= " << var << " centimeter\n";
_getch();
}
void centimeter(double *ptr)
{
*ptr*= 2.54;
}
#include "stdafx.h"
#include<iostream>
#include<conio.h>
using namespace std;
void intfrac(float, float&, float&);
void main()
{
float number, intpart, fracpart;
cout << "enter number to sparates :" << endl;
cin >> number;
intfrac(number, intpart, fracpart);
cout << "the interger part is " << intpart << endl;
cout << "the fraction part is " << fracpart << endl;
_getch();
}
void intfrac(float x, float &y, float &z)
{
y = int(x);
z = x - y;
}
-----------------------------------------------------------------
تحويل من inche الى centimeter
#include "stdafx.h"
#include<iostream>
#include<conio.h>
using namespace std;
void main()
{
void centimeter(double &);
double var;
cout << "enter number : " << endl;
cin >> var;
cout << "var= " << var << " inches\n";
centimeter(var);
cout << "var= " << var << " centimeter\n";
_getch();
}
void centimeter(double &x)
{
x *= 2.54;
}
----------------------------------------------------------------
نفس مثال السابق و لكن by pointer
#include "stdafx.h"
#include<iostream>
#include<conio.h>
using namespace std;
void centimeter(double *);
void main()
{
double var;
cout << "enter number : " << endl;
cin >> var;
cout << "var= " << var << " inches\n";
centimeter(&var);
cout << "var= " << var << " centimeter\n";
_getch();
}
void centimeter(double *ptr)
{
*ptr*= 2.54;
}
0 التعليقات:
إرسال تعليق