C language and Matlab

Source: Internet
Author: User

Using c language and MATLAB to find data by binary method

From the form can be found that the difference is that Matlab is a sentence to compile, and C language is a complete code snippet compiled, and C has a header file (#include (...) , and Matlab is not, for numerical operation Matlab is very simple and powerful, C is a bit cumbersome, for the algorithm requires C relatively higher.

Specific examples are as follows:

C language

#define M 10

#include <stdio.h>

void Main ()
{
static int a[m]={-12,0,6,16,23,56,80,100,110,115};
int n, low, Mid, high, found;
low=0;
High=m-1;
Found=0;
printf ("Input a number to be searched:");
scanf ("%d", &n);
while (Low<=high)
{
Mid= (Low+high)/2;
if (N==a[mid])
{
Found = 1; Break
}/* found, end loop */
else if (n > A[mid])
low=mid+1;
Else
High=mid-1; }
if (found==1)
printf ("The index of%d is%d", n,mid);
Else
printf ("There is not%d", n); }

The Mtalab implementation program is as follows:

X=fix (100*rand);  n=7;  Test=1;  For K=1:7NUMB=INT2STR (n);d ISP ("a guess is a number between 0 and") guess=input (': '); if Guess<xdisp (' low ') ElseIf GUE Ss>xdisp (' high ') Else disp ("You Win") Test=0;break;endn=n-1;endif Test==1disp (' You lost ')

  

C language and Matlab

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.