تبلیغات
دنیای دیجیتال - پاسخ تمرینهای فصل سوم کتاب C++ جعفرنژاد
 نتیجه تصویری برای ‪c++جعفرنژاد‬‏
پاسخ تمرینها را در ادامه مطلب مشاهده کنید

//سوال1
#include >

#include >

int m(int x){

 while (x!=0){

             cout<< x<<'\t';

                         return m(x-1);

             }

  }

// ------------- main -------------------

int main(){

int a;

cout<< " please tupe 1 number : ";

cin >> a;

m(a);

getch();

return 0;

 

}
*****************************************************
//سوال2
#include >

#include >

long int fibo(long int x)

{

             if (x<=0)

 

                         return 0;

 

             if (x==1||x==2)

 

                         return 1;

 

             return fibo(x-1)+fibo(x-2);

}

//---------- main ----------------

int main(){

long int a;

int n;

cout<< " type n number for fibonschi : ";

cin>>n;

for (a=1 ; a<=n;a++){

cout<< fibo(a)<<'\t';

}

getch();

return 0;

}
********************************************************
//سوال 3
# include >

# include >

void input1(float fot,float inch);

void hsb(float fot,float inch);

void output1 (float metr,int sw);

float fot,inch,metr;

int main(){

             input1(fot,inch);

             getch();

             return 0;

}

void input1(float fot,float inch){

             cout << "Enter for foot ";

             cin >> fot;

             cout << "Enter for INCH ";

             cin >> inch;

             hsb(fot,inch);

}

void hsb(float fot,float inch){

              metr = fot * 0.3048;

              output1 (metr,1);

              metr = (inch * (0.3048 / 12))*100;

              output1 (metr,2);

}

void output1(float metr,int sw){

              if (sw == 1){

                          cout << " \n FOT = " << metr;

              }

              if (sw == 2){

                          cout << "\n  INCH = " << metr;

              }

}
********************************************************
//سوال4
#include >

#include >

float k (float a,float b,float c){

 float s ;

 s= (a+b+c)/3;

return s;

}

 

//----------main----------

int main(){

 float x,y,z;

 clrscr();

 cout <<" please 3 number : ";

 cin>>x>>y>>z;

 cout<<"average is a : " << k(x,y,z);

getch();

return 0;

}
*********************************************
//سوال5
#include >

#include >

float dama(float a){

return(a-273);

}

 

int main(){

float x;

clrscr();

cout<<"enter a temprecher farenhait : ";

cin>>x;

cout<<"silicius temperacher is : "<);

getch();

return 0;

}
************************************************
//سوال6
#include >

#include >

#include >

void m(int a, int b , int c){

            int d;

            double r1,r2;

            d= (b*b) - (4*a*c);

            if (d>0){

                        r1=-b-sqrt(d)/(2*a);

                        r2= -b+sqrt(d)/(2*a);

                        cout << "r1 : " << r1 <<'\t'<< "r2 : " ;

            }

            else if (d==0){

                        r1 = -b /(2*a);

                        cout << " r1,r2 : " << r1;

            }

            else if (d<0)

                        cout << "rishe nadarim " ;

            }

//----------------------------------

int main() {

            int x , y , z ;

            clrscr();

            cout << "enter 3 number (a,b,c) for ax^2+bx+c : " ;

            cin >> x >> y >> z;

            m(x,y,z);

getch();

return 0 ;

}
**************************************************
//سوال7
#include >

#include >

void m(float x,float y) {

            float f,k,i;

            f=x*y;

            k = x/y;

            i=x-y;

            cout<<"hasel x-y : " << i<<'\n';

            cout<<"hasel x*y : " << f <<'\n';

            cout<<"hasel x/y : " << k <<'\n';

}

//------------------------------

int main(){

            float a,b;

            clrscr();

            cout<<"enter 2 number : ";

            cin>>a>>b;

            m(a,b);

getch();

return 0 ;

}
*********************************************
//سوال8


#include >

#include >

void print(char c , int i , int j){

            int n ,k;

            for (n=1 ; n<=i;n++){

                        cout << " ";

            }

            for (k=1 ; k<=(j-i) ; k++){

                        cout << c;

            }

}

//-----------------------

int main(){

            int a , b ;

            char ch ;

            cout << " enter a character : " ;

            cin >> ch;

            cout << " enter 2 number (a) : " ;

            cin >> a >> b;

            print (ch,a,b);

            getch();

            return 0;
}
**********************************************
//سوال9
#include >

#include >

void print(char c , int i, int j){

int n,k ;

for (n = 1 ; n <= i ; n++){

            for (k = 1 ; k <= j ; k++){

                        cout << c;

            }

            cout << '\n';

}

}

 

// ---------------------------------

int main(){

             int a,b;

            char ch ;

            clrscr();

             cout << "enter 2 number : ";

             cin >> a >> b ;

             cout << "please enter a character : " ;

            cin >> ch ;

            print (ch,a,b);

getch();

return 0;

}
***********************************************
//سوال10
#include >

#include >

#include >

void tav(){

            double a,r=1,r1;

            int b,i;

            cout << "please 2 number for a^b : ";

            cin >> a >> b ;

            if (b>1){

                        for (i=1 ; i<=b ; i++){

                                    r = (double)r*a;

                        }

                        cout << "result : " << r ;

            }

            else if (b==1){cout << "result : " << a ;}

            else if (b<1) {

                        for (i=1 ; i<=abs(b) ; i++){

                                    r = (double)r*a;

                        }

                        r1 = (double)1/r;

                        cout << "result : " << r1 ;

            }

}

 

// ---------------

int main(){

            tav();

            getch();

            return 0;

}


تاریخ : شنبه 22 آبان 1395 | 12:28 ب.ظ | نویسنده : محمد حبیبی | نظرات
.: Weblog Themes By M a h S k i n:.