[ create a new paste ] login | about

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

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


int main()
{
	int i, n;
	int min, dem;
	dem = 0;
	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)
			dem++;
	   if(i < min)
		   min = i;
	}while(n /= 10);

	printf("\nChu so nho nhat la %d", min);
	printf("\nSo luong chu so nho nhat la %d", dem);

	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 hoangjoker on Feb 14
cho mình góp ý kiến:
biến dem phải khởi tạo lại giá trị nếu có i < min
reply
posted by manhha on Feb 11
dem phai la ++dem chu khong phai dem++

reply
posted by Ngoctruyen99 on Apr 24
Bai nay se co kq sai neu so nho nhat o dau
reply
posted by Ngoctruyen99 on Apr 24
return lại đếm là được
while(C != 0){
if((C % 10) == min)
count++;
if((C % 10) < min){
min = C % 10;
count = 1;
}
C /= 10;
}
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];
}
}
int tanso=0;
for(int i=0; i<temp2;++i){
if(temp[i].number==x.number){
tanso++;
}
}
cout<<"So lan xuat hien cua so "<<x.number<<" la "<<tanso<<
endl;

delete[] temp;
return 0;
}
reply