小编H.S*_*.S.的帖子

鞍点的位置

我有以下问题

假设我们有一个9*8矩阵

如果某个位置是某行中的最小值并且其列中的值最大,则称该矩阵具有"鞍点".在符号中,a [i] [j]是一个鞍点

 a[i][j]=min a[i][k]  ==max a[k][k]
             1<=k<=8      1<=k<=9
Run Code Online (Sandbox Code Playgroud)

请帮我找到马鞍点的计算机位置.

algorithm

5
推荐指数
1
解决办法
5776
查看次数

制作一个实现数组函数的程序

做一个任务,我必须实现一些功能。其中一个函数是检查字符串是否为回文。

#include <stdio.h>
#include <stdlib.h>

char string[] = "cameron";
char string2[] = "mah";
char palindrome[] = "madam";
char notPalindrome[] = "music";

int removeChar(char *str1, char * str2, char c){
   int length = 0;
   for (int i = 0; str1[i] != '\0'; i++){
        length++;
   }
   for (int i = 0; i <= length; i++){
      if (str1[i] == c){
         str2[i] = '*';
      }
      else {
         str2[i] = str1[i];
      }
   }
   for (int i = 0; i<= length; i++){
    printf("%c", str2[i]);
   }
} …
Run Code Online (Sandbox Code Playgroud)

c arrays string

3
推荐指数
1
解决办法
56
查看次数

C 警告(clang 编译器)“整数文字太大而无法用有符号整数表示”

我有这段代码

#include <stdio.h>

typedef signed long long v2signed_long 
      __attribute__ ((__vector_size__ (sizeof(signed long long) * 2)));

int main()
{
        v2signed_long v = {4611686018427387904LL, -9223372036854775808LL};

        printf("%lli, %lli\n", v[0], v[1]);
        return 0;
}
Run Code Online (Sandbox Code Playgroud)

这给出了以下警告(相关问题没有帮助):

:7:45: warning: integer literal is too large to be represented in
       a signed integer type, interpreting as unsigned
  [-Wimplicitly-unsigned-literal]
    v2signed_long v = {4611686018427387904LL, -9223372036854775808LL};
Run Code Online (Sandbox Code Playgroud)

有没有办法解决这个警告?谢谢!

c clang

2
推荐指数
1
解决办法
503
查看次数

为什么 C++ 链接器不会抱怨缺少这些函数的定义?

我写了这段代码:

// print.h
#pragma once

#ifdef __cplusplus
#include <string>

void print(double);
void print(std::string const&);
extern "C"

#endif

void print();
Run Code Online (Sandbox Code Playgroud)

以及源文件:

// print.cxx
#include "print.h"
#include <iostream>

void print(double x){
  std::cout << x << '\n';
}

void print(std::string const& str){
   std::cout << str << '\n';
}

void print(){
   printf("Hi there from C function!");
}
Run Code Online (Sandbox Code Playgroud)

以及驱动程序:

// main.cxx
#include "print.h"
#include <iostream>

int main(){

  print(5);
  print("Hi there!");
  print();

  std::cout << '\n';
}
Run Code Online (Sandbox Code Playgroud)

当我编译时:

gcc -c print.cxx && g++ print.o main.cxx -o prog …
Run Code Online (Sandbox Code Playgroud)

c c++ external-links

2
推荐指数
1
解决办法
209
查看次数

while 循环代码不起作用(keepgoing='y')

所以我正在学习如何在 C 中使用 while 和 for 循环,但这段代码似乎不起作用。scanf 语句似乎被忽略了,循环只是重复自己而不需要我输入“Y”来重复。这是代码:

void showCommission();

void main() {
    char keepGoing='y';
    while(keepGoing=='y') {
        showCommission();
        printf("Do you want to calculate another?\n");
        scanf("%c",&keepGoing);
   }
}

void showCommission() {
    float sales,commission;
    const float COM_RATE=0.10;
    printf("Enter the amount of sales\n");
    scanf("%f",&sales);
    commission=sales*COM_RATE;
    printf("The commission is $%f.\n",commission);
}
Run Code Online (Sandbox Code Playgroud)

这是运行代码给我的内容:

Enter the amount of sales                                                                         
5000                                                                                              
The commission is $500.000000.                                                                    
Do you want to calclulate another?    

...Program finished with exit code 10                                                             
Press ENTER to exit console.  
Run Code Online (Sandbox Code Playgroud)

它从不提示我输入 y 并且代码只是出于某种原因退出。

c loops scanf while-loop

1
推荐指数
1
解决办法
216
查看次数

指向C中struct变量的指针

我有 :

typedef struct a{  
    int var;  
}aa;


typedef struct b{
    aa *a;
}bb;

int main()
{   
    
    bb *b;
    b->a->var;
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

struct a嵌套在b. 如何初始化变量值var使用2指针这样的: b->a->var;

c struct pointers

0
推荐指数
1
解决办法
100
查看次数

标签 统计

c ×5

algorithm ×1

arrays ×1

c++ ×1

clang ×1

external-links ×1

loops ×1

pointers ×1

scanf ×1

string ×1

struct ×1

while-loop ×1