小编use*_*538的帖子

找到C++中3个数字中最小的数字

有没有办法让这个功能更优雅?我是C++的新手,我不知道是否有更标准化的方法来做到这一点.这可以变成一个循环,所以变量的数量不受我的代码限制吗?

float smallest(int x, int y, int z) {

  int smallest = 99999;

  if (x < smallest)
    smallest=x;
  if (y < smallest)
    smallest=y;
  if(z < smallest)
    smallest=z;

  return smallest;
}
Run Code Online (Sandbox Code Playgroud)

c++ max min

28
推荐指数
6
解决办法
8万
查看次数

在C中使用不同的库

我只是从头开始编写一个程序,它可以计算用户输入的大写和小写字母以及空格.从那时起,我发现这些特定函数的代码已经在另一个库中预先编写了!我的问题是,我在下面编写的所有代码如何通过使用来简化

isupper(int c),, islower(int c)isspace(int c)哪些在中定义ctype.h.

#include <stdio.h>

int main(void){
int iochar, numdigits=0, numlower=0, numupper=0, numwhites=0;

printf("Please enter a phrase:\n\n");

while((iochar=getchar())!=EOF) 
{
    if ((iochar==' ')||(iochar=='\t')||(iochar=='\n'))
    {
        numwhites++;
        putchar(iochar);
    }
    else 
        if((iochar>='0')&&(iochar<='9')) 
        {
            numdigits++;
            putchar(iochar);
        }
        else 
            if(('a'<=iochar)&&(iochar<='z')) 
            {
                numlower++;
                putchar(iochar-32);
            } 
            else 
                if(('A'<=iochar)&&(iochar<='Z'))
                {
                    numupper++;
                    putchar(iochar);
                }
                else 
                    putchar(iochar);    
}

printf("%d white characters, %d digits, ",numwhites,numdigits);
printf("%d lowercase have been converted to ",numlower);
printf("uppercase and %d uppercase.\n",numupper);

printf("\n\n");


return 0;}
Run Code Online (Sandbox Code Playgroud)

c function

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

C++:用于循环打印地址的数组而不是值

这是我们在课堂上给出的一个例子.有人可以向我解释为什么打印29个地址而不是29"0"(零)?

int num[29]; 是一个为29个整数留出29个地址的数组 - 我得到那个部分,但是在for循环中你不打印那些地址而不是地址本身的值吗?

还有,(num+i)和之间的区别是(num[]+i)什么?

我有点困惑..

#include <iostream>
#include <cmath>

using namespace std;

int main(){
    int  num[29];
    for (int i=0;i<29;i++)
        cout << (num+i) << endl;

    return 0;
}
Run Code Online (Sandbox Code Playgroud)

c++ arrays for-loop memory-address

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

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

标签 统计

c++ ×3

arrays ×2

c ×2

for-loop ×1

function ×1

max ×1

memory-address ×1

min ×1

pointers ×1