[ create a new paste ] login | about

Link: http://codepad.org/iIATtpAW    [ raw code | output | fork | 2 comments ]

C, pasted on Aug 22:
#include<stdio.h>
#include<conio.h>

int main()
{
	int n;
	// Nhập n ( n > 0 )
	do
	{
		printf("\nNhap vao n ( n > 0 ): ");
		scanf_s("%d", &n);

		if (n <= 0)
		{
			printf("\nGia tri ban nhap vao khong hop le. Xin vui long nhap lai! ");
		}

	} while (n <= 0);

	bool CheckGiamDan = true;
	int themang = n;
	int ChuSoCuoi = themang % 10;  // lấy ra chữ số cuối
	themang /= 10;

	printf("\nCac chu so cua %d co giam dan tu trai sang phai khong ?\n ", n);
	while(themang != 0)
	{
		int ChuSoKeCuoi = themang % 10;
		themang /= 10;
		if (ChuSoKeCuoi < ChuSoCuoi)
		{
			CheckGiamDan = false;
			break;
		}
		else
		{
			ChuSoCuoi = ChuSoKeCuoi;  // Cập nhật lại chữ số cho lần so sánh tiếp theo
		}
	}
	if(CheckGiamDan)
		printf("\Dung !");
	else
		printf("Sai !");
	

	getch();
	return 0;
}


Output:
1
2
3
4
5
6
7
8
9
Line 17: error: conio.h: No such file or directory
In function 'main':
Line 20: error: 'bool' undeclared (first use in this function)
Line 20: error: (Each undeclared identifier is reported only once
Line 20: error: for each function it appears in.)
Line 20: error: expected ';' before 'CheckGiamDan'
Line 32: error: 'CheckGiamDan' undeclared (first use in this function)
Line 32: error: 'false' undeclared (first use in this function)
Line 9: warning: unknown escape sequence '\D'


Create a new paste based on this one


Comments:
posted by 19127646 on Oct 27
#include <stdio.h>
int main()
{
int n;
scanf_s("%d", &n);
while (n != 0)
{
int k = n % 10;
n /= 10;
if (n == 0)
continue;
if (k > n%10)
{
printf(" ko giam dan "); return 0;
}
}
printf("giam dan");
return 0;
}
reply
posted by yonnon on Jul 12
#include<bits/stdc++.h>

using namespace std;

struct S
{
int number;
};

int main(){
int n;
cout << "Enter your sentence: ";
int number=0;
cin >> n;
int tempn=0;
tempn=n;
S *temps=new S[n];
while(tempn>0){
tempn/=10;
number++;
}
int tempn2=0;
tempn2=n;
for(int i=0; i<number;++i){
temps[i].number =tempn2%10;
tempn2/=10;
}
int a;
for(int i=0; i<number-1;++i){
for(int j=i+1 ; j<number;++j){
if(temps[i].number<temps[j].number){
a=temps[i].number;
temps[i].number=temps[j].number;
temps[j].number=a;

}
}
}

int arr=0;
for(int i=0;i<number;++i){
arr=arr*10+temps[i].number;

}
if(arr==n){
cout<<"Day la day giam dan"<<
endl;
}
else{
cout<<"Day khong phai la day giam dan"<<
endl;
}

return 0;}
reply