[ create a new paste ] login | about

Link: http://codepad.org/7ANa5fgC    [ raw code | output | fork | 5 comments ]

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

int main()
{
	int themang, n, i;

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

	themang = n;
	/*do
	{                                 
		i = themang % 10;
		themang /= 10;
	}while(themang != 0);*/                
	
	//có thể viết 
	do
	{
	  i = themang % 10;
	}while(themang /= 10);
	
	printf("\nChu so dau tien la %d", i);


	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 BT49(int n)//nhap vao n xuat ra chu so dau tien
{
int kq=0;
while(n >10)
{
n /= 10;
kq = n;
}
return kq;
}
reply
posted by dangtiendat86@gmail.com on Feb 9
#include<iostream>
using namespace std;
main(){
int n;
cout<<"n=";
cin>>n;
while (n>=10) n/=10;
cout<<"kq="<<n<<endl;
}
reply
posted by yonnon on Jul 7
#include<bits/stdc++.h>

using namespace std;
int main(){
int n;
cout <<"Enter your sentence: ";
cin >> n;
int temp = 0;
int sum = 0;
while (n >= 10){
n/=10;

}
cout<<n<<
endl;
return 0;
}
reply
posted by cuong.luucb8921 on Aug 21
#include<stdio.h>

int main(){
int n;
int t;
int s;

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 )
{
s=t%10;
t=t/10;
}

printf("Chu so dau tien cua %d la %d",n,s);
return 0;
}
reply
posted by tranngocthe111 on Oct 13
#include<iostream>
using namespace std;
int ChuSoDauTien(int a)
{
if(a<10)
return a;
else
return ChuSoDauTien(a/10);
}
int main() {
int a;
cout << "Nhap n: ";
cin >> a;
cout << "Chu so dau tien la: " << ChuSoDauTien(a)<<endl;
system("pause");
return 1;
}
reply