我的任务是将十进制数转换为基数p.p由用户输入.到目前为止这是我的代码:
for(int i = 0; i < 100; i++)
{
if(a % p == 0) nn[i] = '0';
if(a % p == 1) nn[i] = '1';
if(a % p == 2) nn[i] = '2';
if(a % p == 3) nn[i] = '3';
if(a % p == 4) nn[i] = '4';
if(a % p == 5) nn[i] = '5';
if(a % p == 6) nn[i] = '6';
if(a % p == 7) nn[i] = '7';
if(a % …Run Code Online (Sandbox Code Playgroud) 这是代码
#include <stdio.h>
void swap(int *a,int *b)
{
int *tmp;
*tmp=*a;
*a=*b;
*b=*tmp;
}
void main()
{
int i,j;
printf("Enter any number\n");
scanf("%d",&i);
printf("Enter another number\n");
scanf("%d",&j);
printf("Numbers before swap\n");
printf("value of i : %d\n",i);
printf("value of j : %d\n",j);
swap(&i,&j);
printf("Numbers after swap\n");
printf("value of i : %d\n",i);
printf("value of j : %d\n",j);
}
Run Code Online (Sandbox Code Playgroud)
上面一个是我的代码,它工作正常但是当输出在控制台上打印时它会给出Segmentation故障(core dumped)这是o/p
abc:~/Desktop/C$ ./a.out Enter any number 34 Enter another number 54 Numbers before swap value of i : 34 value of j : 54 …
我在函数中有一个For循环,如下所示:
int fnSearch(int arnSalaries [10][2], int nSalary, char cFound)
{
int nRow, nCol;
printf("Please enter the Salary to find the Employee ID : ");
scanf("%d", &nSalary);
for(nRow = 0; nRow < 10; nRow++)
{
if(nSalary == arnSalaries[nRow][1])
{
printf("\%d found - Employee ID matching that salary is: %d\n",
nSalary, arnSalaries[nRow][0]);
cFound = 'Y';
//nRow = 10; /* This is to break out of the loop */
}
}
if(cFound == 'N')
{
printf("Sorry, that salary does not match an employee\n"); …Run Code Online (Sandbox Code Playgroud) 我正在使用它quicksort来查看订购大型数组的速度有多快.我订购了一百万没问题.. 200万没问题.300万给出了段错误.一些测试显示它在200万到210万之间崩溃,而GDB显示崩溃来自"填充"功能.
这是代码:
int partition(int v[], int N){
int i, j;
int x = v[N-1];
for(i = 0, j = 0; i < N - 1; i++){
if (v[i] < x) swap(v, j++, i);
}
swap(v, j, N - 1);
return j;
}
void quickSort(int v[], int N){
int p;
if (N > 1){
p = partition(v, N);
quickSort(v, p);
quickSort(v + p + 1, N - p - 1);
}
}
void fill(int v[], int N){
srand(clock()); …Run Code Online (Sandbox Code Playgroud) 该程序的目标是将大量整数存储在一个数组中,如下所示。它使用“池”函数来收集索引为 2 的整数,并将“池”返回给主函数。我尝试在 Xcode 11 中编译代码,但是在 main 中调用“pool”函数期间出现了这个错误“函数‘池’的隐式声明在 C99 中无效”。我该如何解决?如何将 Xcode 上的编译器更改为 C11 标准?
#include <stdio.h>
#include <stdlib.h>
#define SIZE 1000000000
int group[SIZE];
int main()
{
pool();
return 0;
}
int pool()
{
for (int index = 2; index < SIZE; index++)
{
group[index] = 1;
}
return 0;
}
Run Code Online (Sandbox Code Playgroud) 以下是我在固件中找到的延迟功能.它看起来有点危险,或者至少让读者感到困惑.
全局变量
static int32u masterTimerCounter; // 32-bit unsigned timer counter
Run Code Online (Sandbox Code Playgroud)
系统勾选中断处理程序
/* Called Every Millisecond */
void sysTickIrqHandler(void)
{
masterTimerCounter++;
}
Run Code Online (Sandbox Code Playgroud)
设置定时器到期功能
void setTimerExpiration(int32u *timerExpiration, int32u delay)
{
*timerExpiration = masterTimerCounter + delay;
}
Run Code Online (Sandbox Code Playgroud)
检查定时器是否过期功能
boolean timerExpired(int32u timerExpiration, int32u delay)
{
if((masterTimerCounter - timerExpiration) < delay)
return TRUE; // Timer has expired
else
return FALSE; // Timer still active
}
Run Code Online (Sandbox Code Playgroud)
设置定时器提取和阻止直到定时器到期
int32u timerExpiration;
setTimerExpiration(&timerExpiration, 15); // Set expiration timer to 15 milliseconds
while(!timerExpired(timerExpiration, 15) // Block until timer has expired …Run Code Online (Sandbox Code Playgroud) 是否有可能printf在C中的数组的第一个元素的内存地址?
我尝试以下时编译器报告错误:
printf("i%/n", @array[0])
Run Code Online (Sandbox Code Playgroud)
我宣布的地方array[] = {23, 56, 78}.