我正在尝试在C中创建一个程序,它接收任何日期并返回星座.我有一个函数,应该验证日期是否可能(日> 0,月> 0,如果月== x,日<31等)事情是,它应该验证月份,并确定它是30个月还是31个月它只接受一部分条件,使其成为所有月份的确定30天或a所有月份都是31天.功能名称是fnValidacion()
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
/*
Programa : Signo Zodiaco.
Autor : Samir Fersobe 1063021
Fecha : Marzo 28, 2015
*/
const char *signo[12] = {"Aries","Tauro","Geminis","Cancer","Leo","Virgo","Libra","Escorpio",
"Sagitario","Capricornio","Acuario","Piscis"};//Arreglo de Signos Zodiacales
int Ano,Mes,Dia ;//Variables de Ano , Mes y Dia.
int aprovacion = 0;//Determina si la funcion sigue o no.
int bisiesto = 1 ;//determina si el año es bisiesto.
int type ;//determina la estacion.
//Funciones
void fnFecha() ;//Consigue la fecha
void fnBisiesto() ;//Define si …
Run Code Online (Sandbox Code Playgroud) 现在我的数组是:
[[1,2,3],[4,5,6],[]]
Run Code Online (Sandbox Code Playgroud)
我想计算这个数组并返回一个结果:
[5,7,9]
Run Code Online (Sandbox Code Playgroud)
如果有空数组,请将其删除.然后加上每个子阵列的每个位置.
如果使用数组的每个方法,也许我可以得到结果.但是有没有更好的方法只使用ruby的数组方法?
我遇到了这段代码...
def coordinate(my_list):
coordinate = []
count = -1
for num in my_list:
count += 1
coordinate.append("%s-%s" % ("{:0>2d}".format(count), my_list[count]))
return coordinate
print ( coordinate(['x','y','z']))
Run Code Online (Sandbox Code Playgroud)
预期的输出类型是
coordinate(['A', 'B', 'C', 'D'])
>>>['00-A', '01-B', '02-C', '03-D']
Run Code Online (Sandbox Code Playgroud)
现在我的问题是我不明白
coordinate.append("%s-%s" % ("{:0>2d}".format(count), my_list[count]))
Run Code Online (Sandbox Code Playgroud)
这部分代码... "{:0>2d}"
and到底.format(count)
是用来做什么的?他们如何运作?请解释。
我正在寻找这样的东西:
int nVal = 130;
while(nVal % 6 != 0)
nVal--;
Run Code Online (Sandbox Code Playgroud)
在没有身体的while循环中:
int nVal = 130;
while(nVal-- % 6 != 0)
Run Code Online (Sandbox Code Playgroud)
当然这样,--
操作员经常被调用一次.这里有什么建议,还是我应该选择#1?
我正在用 C 编写一个简单的测验(使用 CodeBlocks 13.12)
它可以编译,但在第二个问题中不起作用。无论我输入什么,它总是给出答案“这很伤心”。我不明白出了什么问题。我来到这里,如果我注释第 13 行(scanf("%d", &age);),那么第二个问题就可以正常工作了。问题是什么?
#include <iostream>
#include <stdio.h>
#include <windows.h>
#include <clocale>
int main()
{
int age;
char S1;
printf("How old is your dog? \n");
scanf("%d", &age);
if (age <= 7)
{
printf(" very young. the end \n");
return 0;
}
else
{
printf("old dog. \n \n");
}
//question2
printf("Do you like dogs? y/n \n");
scanf("%c%c", &S1);
if (S1 == 'y')
{
printf("hey, that's nice \n");
}
else
{
printf(" that's …
Run Code Online (Sandbox Code Playgroud) 有人可以解释一下为什么这段代码返回0?
#include <stdio.h>
int factorial(int input)
{
if (input > 0)
{
input--;
return input * factorial(input);
}
return 1;
}
int main()
{
printf("%d", factorial(20));
return 0;
}
Run Code Online (Sandbox Code Playgroud) 我有这个代码
int e;
scanf("%d",&e);
int ar[e];
Run Code Online (Sandbox Code Playgroud)
这是动态分配吗?它看起来真的像我可以在运行时分配内存.
我用它来获取用户输入的元素数量,然后由用户再次填充.
我显然解决了一个非常简单的问题,即将字符串中的字符转换为小写tolower()
。但是,我看到有人使用它,这是一个公认的解决方案。
这是tolower()
cpp中功能的替代方法吗?如果是这样,为什么?
对问题的引用:https : //atcoder.jp/contests/abc126/tasks/abc126_a
#include <iostream>
using namespace std;
int main(int argc, char const *argv[])
{
// We want to convert "ABC" to "aBC"
string S = "ABC";
S[0] += 0x20;
// Returns "aBC"
cout << S << endl;
return 0;
}
Run Code Online (Sandbox Code Playgroud) 我试图使用mersenne_twister_engine生成64位随机数但是当我尝试包含时#include <random>
,编译器会给我一个警告,如下所示
/usr/include/c++/4.6/bits/c++0x_warning.h:32:2:错误:#error此文件需要编译器和库支持即将推出的ISO C++标准C++ 0x.此支持目前是实验性的,必须使用-std = c ++ 0x或-std = gnu ++ 0x编译器选项启用.make:* [fuse.o]错误1
我怎样才能解决这个问题?
我有这个下面的文件.我试图在visual studio 2010中运行它.但是它一直给我一个错误,说我需要包含头文件stdafx.h.但是这个文件在头文件列表中无处可见.
#include <cstdio>
#include <cstdlib>
#include <iostream>
using namespace std;
int choice();
double cylinder_volume();
double cone_volume();
double sphere_volume();
void display_result(double volume);
int main ()
{
int option;
double volume;
option=choice();
if (option==1)
{
volume=cylinder_volume();
display_result(volume);
}
else
if (option==2)
{
volume=cone_volume();
display_result(volume);
}
else
if (option==3)
{
volume=sphere_volume();
display_result(volume);
}
return 0;
}
int choice()
{
int option;
cout<<"What would you like to calculate the volume of: ";
cout<<"\nPress 1 for cylinder. ";
cout<<"\nPress 2 for cone. "; …
Run Code Online (Sandbox Code Playgroud) c ×5
c++ ×3
arrays ×1
c++11 ×1
char ×1
hex ×1
if-statement ×1
python ×1
python-3.x ×1
recursion ×1
ruby ×1
string ×1
while-loop ×1