[ create a new paste ] login | about

Link: http://codepad.org/yErdiZSS    [ raw code | output | fork | 9 comments ]

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


int main()
{
	int i, n;
	int max, dem;
	max = 0;
	dem = 1;
	do
	{
	printf("\nNhap n: ");
	scanf("%d", &n);
	}while(n < 0 && printf("\nLoi: n >= 0 !"));
	if(n == 0)
		dem = 1;

	do
	{
		i = n % 10;
	   if(i == max)
		   dem++;
	   if(i > max)
		   max = i;
	}while(n /= 10);
	printf("\nSo lon nhat la %d", max);
	printf("\nSo luong chu so lon 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 trungnv on Nov 26
code chạy sai rồi bạn ơi
bạn thử số 1311 nha
reply
posted by Wind123 on May 12
Thêm vô vậy chạy được không bạn?

If(i==max)
Dem++;
If(i>max){
Dem=1;
max=i;
}
reply
posted by khanhtienfz on Jun 25
code này lỗi rồi.Lỗi sao thì tự debug các bạn sẽ hiểu.Còn đây code của mình :))

#include<stdio.h>
#include<conio.h>

int main()
{
int i, n;
int max = 0, dem = 0;

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

int j = n;

do
{

int k = n % 10;

if (k > max)
{
max = k;
}
} while (n /= 10);

dem = 0;

do
{

int k = j % 10;

if (k == max)
{
dem++;
}
} while (j /= 10);

printf("\nso luong chu so lon nhat la : %d", dem);

_getch();
return 0;
}

reply
posted by maiphu.2510@gmail.com on Aug 13
#include<stdio.h>
#include<conio.h>
#include<math.h>
int main()
{
int n,m,j=0;
int s;
int max=0;
printf("\nNhap n = ");
scanf("%d",&n);
/*
k= 1+ log10(n);
printf("\nso chu so cua %d la : %d",n,k);
*/
int t=n;
int g=t;
while(n!=0)
{
m=(n%10);
if(m>max)
{
max=m;
}
n=( n/10);
}
printf("\nchu so lon nhat cua %d bang : %d ",g,max);
while(t!=0)
{
int k=(t%10);
if(k==max)
{
j++;
}
t=( t/10);
}

/* for(int i=0;n!=0;i++)
{
n=n/10;

k++;
}
*/
printf("\nso luong chu so %d cua %d bang : %d ",max,g,j);
getch();
return 0;
}
reply
posted by nguyenvantybg01 on Jan 5
code a Hiếu lỗi thật. Ví dụ nếu nhập 2211334455 sẽ in ra 5 :v
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
posted by cuong.luucb8921 on Aug 21
#include<stdio.h>

int main(){
int n;
int t;
int s1;
int s2;
int dem=0;
int max=1;

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)
{
s1 = t%10;
t = t/10;
if(s1>max)
{
max=s1;
}
}

t=n;

while(t!=0)
{
s2 = t%10;
t = t/10;
if(s2==max)
{
dem=dem+1;
}
}

printf("So luong chu so lon nhat cua %d la %d",n,dem);
return 0;
}
reply
posted by p1635162 on Feb 16
#include <stdio.h>
#include <conio.h>

void Nhap(int &n)
{
do{
printf("Nhap n de kiem tra (n > 1): ");
scanf("%d", &n);
if(n < 1){
printf("Nhap sai !!! nhap lai... \n");
}
}while(n < 1);
}

int SoDuongLonNhat(int n){
int max;
while(n != 0){
if(max < (n % 10)){
max = n % 10;
}
n /= 10;
}return max;
}

int dem(int n){
int count = 0;
int the = n;
while(the != 0){
if(SoDuongLonNhat(n) == (the % 10)){
count ++;
}
the /= 10;
}return count;
}

int main(){
int n;
Nhap(n);
printf("So luong so lon nhat trong %d la: %d", n, dem(n));
getch();
return 0;
}
reply
posted by p1635162 on Feb 16
#include <stdio.h>
#include <conio.h>

void Nhap(int &n)
{
do{
printf("Nhap n de kiem tra (n > 1): ");
scanf("%d", &n);
if(n < 1){
printf("Nhap sai !!! nhap lai... \n");
}
}while(n < 1);
}

int SoDuongLonNhat(int n){
int max;
while(n != 0){
if(max < (n % 10)){
max = n % 10;
}
n /= 10;
}return max;
}

int dem(int n){
int count = 0;
int the = n;
while(the != 0){
if(SoDuongLonNhat(n) == (the % 10)){
count ++;
}
the /= 10;
}return count;
}

int main(){
int n;
Nhap(n);
printf("So luong so lon nhat trong %d la: %d", n, dem(n));
getch();
return 0;
}

reply