Saturday, November 27, 2010

Giải bài thi toán rời rạc 2010

#include<stdio.h>
#include<conio.h>
int a[10],x[10];
int n,b,j,tong,k;
  void ketqua(int x[10]);
  void duyet(int i)
{
 for (j=0;j<=1;j++) a[i]=j;
 tong=0;
 tong+=a[i]*x[i];
 if (i==n)
 {
       if(tong==b) ketqua;
 }else duyet(i+1);
}
  void ketqua(int x[10])
{ int i;
  for(i=1;i<=n;i++)
 printf("\n x[%d]=%d",i,x[i]);
}
void main()
{
clrscr();
   printf("\n nhap gia tri cua b=");
   scanf("%d",&b);
   printf("\nnhap gia tri cho n=");
   scanf("%d",&n);
   printf("\n nhap gia tri ch0 a");
for(k=1;k<=n;k++)
 {
  printf("\n a[%d]=",k);
  scanf("%d",a[k]);
 }
  duyet(1);
  getch();
}

No comments:

Post a Comment

Popular Posts