Welcome, guest! Login / Register - Why register?
Psst.. new poll here.
Psst.. new forums here.

Paste

Pasted as C++ by registered user xujiayu ( 4 years ago )
#include <stdio.h>
#include <conio.h>
#include <math.h>

float xulytinhtoan (int a , int b , char pheptoan)
{
	if(pheptoan == '+')
	{
	   return a + b;
	}
	if(pheptoan == '-')
	{
	   return a - b;
	}
	if (pheptoan == '*')
	{
	   return a*b;
	}
		
		return b == 0 ? 0 : (float) a / b;
	
	
}
int timmax ( int a , int b)
	{//cach 1 
	  // return a > b ? a : b;
		if (a > b)
		{
		   return a;
		}
		return b;
	}
	int timmin ( int a , int b )
	{
	    return a < b ? a : b;
	}
	int demsochuso ( int n)
	{ 
	    return log10((double)n) +1;
	}

int main()
	// cach goi ham dang 2 
{     
	int a = 1;
	 int b = 2;

	  int tong = xulytinhtoan (a, b , '+');
	  int hieu  = xulytinhtoan (a, b , '-');
	  int tich = xulytinhtoan (a, b , '*');
	  float thuong = xulytinhtoan (a, b , '/');
	  printf("\n%d",tong);
	  printf("\n%d",hieu);
	  printf("\n%d",tich);
	  printf("\n%f",thuong);

	  int max = timmax (a,b);
	  int min = timmin (a , b);
	int n = 123456; int sochuso = demsochuso (n);
	printf("\nmax = %d ",max);
	printf("\nmin = %d",min);
	printf("\nN co = %d chu so ",sochuso);
	
	getch();
	return 0;



}

 

Revise this Paste

Your Name: Code Language: