bai toan c++

414 0 1
                                        

Đề1: Tinh số pi với độ sai số epxilon từ bàn phím.

Chương trình.

COLOR=darkblue]#include<stdio.h>

#include<conio.h>

#include<graphics.h>

#include<alloc.h>

void main()

{ float pi=1,x,i=1;

int j=0;clrscr(); textmode(C80);

printf("

Cho so epxilon=");

scanf("%f",&x);

do

{

if(j%2==0)

pi-=1/(2*i + 1);

else

pi+=1/(2*i + 1);

i++;

j++;

}

while ( 1/(2*i+1)>x);

pi*=4;

printf("

Pi=%f",pi);

getch();

}

----------------------------------------------------------------------------------------

Đề 2: Viết hàm tính trung bình tổng 3 số bất kỳ.

Chương trình.

#include<conio.h>

#include<stdio.h>

float tb(float a,float b,float c)

{ float t ;

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

return(t);

}

void main(void)

{float x,y,z;

clrscr();

printf("

Nhap vao ba so bat ky tu ban phim: ");

scanf("%3f%3f%3f",&x,&y,&z);

printf("

Trung binh cong ba so la:TBC = %f",tb(x,y,z));

getch();

}

-------------------------------------------------------------------------------------------

Đề3: Dùng for, do while,while tính giai thừa.

Chương trình.

// Tinh gia thua bang while

#include<stdio.h>

#include<conio.h>

#include<graphics.h>

void main()

{float n,gt=1;

int j,i=0;

clrscr(); textmode(C80);

printf("

Dung While tinh n giai thua");

printf("

Nhap vao mot so nguyen duong n:");

scanf("%f",&n);

while(i<n)

You've reached the end of published parts.

⏰ Last updated: Aug 27, 2009 ⏰

Add this story to your Library to get notified about new parts!

bai toan c++Where stories live. Discover now