Tim X

#include<stdio.h> #define MAX 20 int DemXTrongN(int x, int n, int a[], int &na){ na = 0; int count = 0; int vt = 0; int temp = 0; while(n>0){ temp = n %10; vt++; if(temp==x){ count++; a[na]=vt; na++; } n/=10; } return count; } void xuatVT(int a[], int n){ for(int i=0;i<n;i++) printf("%d\t",a[i]); } void nhapNvaX(int &n, int &x){ do{ printf("Nhap N va X: "); scanf("%d %d", &n, &x); }while(n<=0 && x<=0 && x>=10); } int main(){ int n,x,na; int a[MAX]; int soX = 0; nhapNvaX(n,x); soX = DemXTrongN(x,n,a,na); printf("So lan xuat hien cua x trong n la: %d\n", soX); printf("Tai cac vi tri: \n"); xuatVT(a,na); return 0; }

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.