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

Paste

Pasted as C++ by registered user xujiayu ( 5 years ago )
#include <stdio.h>
#include <conio.h>
#include <math.h>
int main()
{
	//nhap vao 2 so nguyen
	//tinh MIN va MAX cua 2 so do 
	/*int a,b;
	printf("\nnhap vao so nguyen a : ");
	scanf("%d",&a);
	printf("\nnhap vao so nguyen b : ");
	scanf("%d",&b);
    int max = a > b ? a : b;
	int min = a < b ? a : b;

	printf("\nmax = %d",max);
	printf("\nmin = %d",min);*/

	//nhap VAO SO XE BAO GOM 5 CHU SO TINH SO NUT 
	
	int soxe;

	printf("\nhay nhap vao so xe : ");
	scanf("%d",&soxe);
    
	int sochuso;
	sochuso = log10 ((float)soxe) + 1;
	//printf("\nso %d co %d chu so !",soxe,sochuso);

	/*
	12345=>1 + 2 + 3 + 4 + 5 = 15 => 5 nut 
	12345 % 10 = 5
	12345 / 10 = 1234
	*/
	int sonut = 0;

	sonut += soxe % 10;// lan 1 
	soxe /= 10; // bo so cuoi

	sonut += soxe % 10;// lan 2
	soxe /= 10; // bo so cuoi

	sonut += soxe % 10;// lan 3
	soxe /= 10; // bo so cuoi

	sonut += soxe % 10;// lan 4 
	soxe /= 10; // bo so cuoi

	sonut += soxe % 10;// lan 5
	soxe /= 10; // bo so cuoi

	sonut += soxe;

	sonut %= 10; // lay hang don vi 

	sochuso == 5 ? printf("\nso nut = %d",sonut) : printf("xin hay nhap dung 5 chu so cam on");


   getch();
   return 0;


}

 

Revise this Paste

Parent: 116845
Children: 116850
Your Name: Code Language: