【发布时间】:2015-03-18 04:19:08
【问题描述】:
我是编程和 Visual Studio 的新手。目前我正在使用 Visual Studio 2013,我想知道在启动本地 Windows 调试器后如何随时开始调试。在这段代码中,我想在输入要搜索的数字后开始调试。这是代码。
#include<stdio.h`
#include<math.h>
#pragma warning (disable : 4996)
#define MAX_SIZE 100
#define SWAP(x,y,t) ( (t) = (x), (x) = (y), (y) = (t))
int size_check(int n)
{
int a;
a = n;
if (a < 1 || a>100)
{
(a < 1) ? printf("\nSize can't be smaller than 1 , please try again!") : printf("\nmax size allowed is 100, pleasetry again");
printf("\nEnter the length of array :\t ");
scanf("%d", &a);
return(size_check(a)); /*or a = size_check(a)*/
}
return a;
}
void sort_array(int list[], int n)
{
int i, j, temp;
for (i = 0; i < n - 1; i++)
for (j = i + 1; j < n;j++)
if (list[i]>list[j])
{
SWAP(list[i], list[j], temp);
}
}
void b_search(int list[], int sno,int a)
{
int left, right, middle, i=1, n=a-1;
left = 0;
right = n;
while (left != right)
{
middle =( (left + right) / 2);
if (sno == list[middle])
{
printf("\nSearched number is present in array at %d ",middle);
break;
}
if (sno < list[middle])
{
right = middle - 1;
}
else
{
left = middle + 1;
}
}
if (left == right || sno != list[middle])
printf("Searched number is not present in array!");
}
void main()
{
int n, i ,sno,list[MAX_SIZE];
printf("Enter the length of array :\t ");
scanf("%d", &n);
n=size_check(n);
for (i = 0; i < n; i++)
{
printf("Enter the %d element of array:\t",i);
scanf("%d", &list[i]);
}
sort_array(list, n);
printf("\nThe shorted array :");
for (i = 0; i < n; i++)
{
printf("\n%d",list[i]);
}
printf("\nEnter the number you want to search in array:\t");
scanf("%d", &sno);
b_search(list, sno, n);
getch();
}
【问题讨论】:
标签: c++ c visual-studio visual-studio-2013 visual-studio-debugging