[ create a new paste ] login | about

Link: http://codepad.org/NbQWG1As    [ raw code | output | fork | 11 comments ]

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

int main()
{
	int n;
	int SoNghichDao = 0;
	do
	{
		printf("\nNhap n: ");
		scanf("%d", &n);
	}while(n < 0 && printf("\nLoi: (n >= 0)"));

	printf("\nSo dao nguoc cua %d la: ", n);
	do
	{
		printf("%d", n % 10);
	}while(n /= 10); // tương đương n = n / 10; n != 0;

	// có thể viết

	/*do
	{
		SoNghichDao = SoNghichDao * 10 + n % 10;
		n /= 10;
	}while(n != 0);
	printf("\n%d", SoNghichDao);*/

	getch();
	return 0;
}


Output:
1
Line 17: error: conio.h: No such file or directory


Create a new paste based on this one


Comments:
posted by 1461512 on Oct 25
static int BT50 (int n)
{
int sdn=0;
int temp = n;
while (temp >=1)
{
sdn = sdn*10 + temp % 10;
temp /= 10;
}
return sdn;
}
reply
posted by caotuong225@gmail.com on Nov 7
cho e hỏi tại sao khi printf chỗ số nghịch đảo lại ko cần %d mà nó vẫn hiện lên số nghịch đảo ở phía sau còn có %d lại sai ạ

reply
posted by dangtiendat86@gmail.com on Feb 9
#include<iostream>
using namespace std;
main(){
int n;
cout<<"n=";
cin>>n;
cout<<"kq=";
while (n!=0){
cout<<(n%10);
n/=10;
}
cout<<endl;
}
reply
posted by yonnon on Jul 9
//Bài này t không biết giải theo cách thông thường nên thôi làm nó phức tạp xíu vậy :v
#include<bits/stdc++.h>

struct number
{
int temp;
};

using namespace std;
int main(){
int n;
int n2=0;
int i=0;
int *p;
cout << "Enter your sentence: ";
cin >> n;
p=&n;
int temp2=0;
n2=*p;
while(n2>0){

temp2++;

n2/=10;

}

number *S=new number[n];
int temp1=0;

while(n>0){
S[i].temp = n % 10;
n/=10;
i++;

}

cout<<"Day so sau khi dao nguoc la: "<<
endl;
for(int i=0; i<temp2;++i){
cout<<S[i].temp;
}
delete[] S;
return 0;

}

reply
posted by cuong.luucb8921 on Aug 21
#include<stdio.h>

int main(){
int n;
int t;
int sodaonguoc=0;

do
{
printf("Nhap vap n:\n");
scanf("%d",&n);
if(n < 1)
{
printf("n phai lon hon bang 1\n");
}
}while(n < 1);

t=n;

while(t!=0)
{
sodaonguoc = sodaonguoc*10 + t%10;
t=t/10;
}

printf("So nghich dao cua %d la %d", n, sodaonguoc);
return 0;
}
reply
posted by bbbb on Sep 12
sodaonguoc ở đay có liên quan gì đến t mà vẫn có kết quả đc nhỉ ai giải thich giúp e phần while(t!=o) với ạ
reply
posted by Lamqwe on Sep 10
Có cách làm bài này bằng for với số 3 chữ số không ạ
reply
posted by tridv on Feb 14
int n;
int chia;
int so;

printf("n = ");
scanf("%d", &n);

chia = n;

while(chia != 0){
so = chia % 10;
chia /= 10;
printf("%d", so);
}
reply
posted by tridv on Feb 14
int n;
int chia;
int so;

printf("n = ");
scanf("%d", &n);

chia = n;

while(chia != 0){
so = chia % 10;
chia /= 10;
printf("%d", so);
}
reply
posted by tridv on Feb 14
chet, sai roi @@

reply
posted by 20223768 on Sep 12
#include <iostream>
using namespace std;
int main()
{
int n; cin >>n;
int s=1;
while (n!=0)
{
s=n%10;
cout <<s;
n=n/10;
}
return 0;
}
reply