Untitled

mail@pastecode.io avatar
unknown
plain_text
2 years ago
900 B
3
Indexable
Never
#include<stdio.h>
#include<conio.h>
#include<Windows.h>

void nhapso(int& n);
int tinhgiaithua(int n);

int main()
{
	int tong = 0;
	int a;
	while (true)
	{
		nhapso(a);
		tong += tinhgiaithua(a);	

	kquin:

		printf("\nban co muon nhap tiep khong? (nhan phim 'y' de tiep tuc) ");

		char luachon = _getch();
		fflush(stdin);
		scanf_s("%c", &luachon);

		if (luachon == 'y' || luachon == 'Y')
		{
			nhapso(a);
			tong += tinhgiaithua(a);
			goto kquin;
		}
		else
		{
			printf("\ntong= %d", tong);
			break;
		}
	}
	return 0;
}

void nhapso(int& n)
{
	do
	{
		printf("\nnhap vao so nguyen duong = ");
		scanf_s("%d", &n);
		if (n <= 0)
		{
			printf("\nvui long chi nhap vao so nguyen duong");
		}
	} while (n <= 0);
}

int tinhgiaithua(int n)
{
	int giaithua = 1;
	for (int i = 1; i <= n; i++)
	{
		giaithua *= i;
	}
	return giaithua;
}