[ create a new paste ] login | about

Link: http://codepad.org/RGgCYA1h    [ raw code | output | fork | 4 comments ]

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


int main()
{
	int i, n;
	int min;
	//min = 1;
	do
	{
	printf("\nNhap n: ");
	scanf("%d", &n);
	}while(n < 0 && printf("\nLoi: n >= 0 !"));
	min = n % 10;  // khởi tạo min
	if(n == 0)
		min = 0;

	do
	{
		i = n % 10;
	   if(i < min)
	   {
		   min = i;
	   }
	}while(n /= 10);

	printf("\nChu so nho nhat la %d", min);

	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 mouto9k on Nov 15
min=9;
if(cs<min)
min=cs;
reply
posted by yonnon on Jul 9
#include<bits/stdc++.h>

struct S{
int number;
};
using namespace std;
int main(){
int n;
cout << "Enter your sentence: ";
cin >> n;
int *p;
p=&n;
int n2,temp2=0;
n2=*p;
S *temp=new S[n];
do{
temp2++;
n2/=10;

}while(n2!=0);
for(int i=0; i<temp2;++i){
temp[i].number=n%10;
n/=10;
}
S x=temp[0];
for(int i=0; i<temp2;++i){
if(temp[i].number<x.number){
x=temp[i];
}
}
cout<<"Min of number "<<x.number<<
endl;
delete[] temp;
return 0;
}
reply
posted by cuong.luucb8921 on Aug 21
#include<stdio.h>

int main(){
int n;
int t;
int s;
int min=9;

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;
if(s<min)
{
min=s;
}
}

printf("Chu so nho nhat cua %d la %d",n,min);
return 0;
}
reply
posted by luongphongnhan on Oct 21
#include <iostream>
using namespace std;

int chuSoNhoNhat(int n) {
int phanNguyen;

int soMin = 0;
while (n!=0)
{
phanNguyen = n % 10;

if (soMin >= phanNguyen) {
soMin = phanNguyen;
}
n /= 10;
}
return soMin;
}

int main() {
int n;
do
{
cout << "Moi nhap so n: ";
cin >> n;
if (n < 0) {
cout << "so n phai lon hon 0!" << endl;
}

} while (n <=0);
cout << "Chu so nho nhat cua so " << n << " la " << chuSoNhoNhat(n) << endl;
system("pause");
return 0;
}
reply