问题是编写一个程序,该程序从终端输入一个键入的整数,并以英语提取并显示整数的每个数字.所以,如果用户输入932,程序应该显示'九三二'..
我的算法是首先反转数字,使932变为239.现在我使用mod运算符和print来提取最后一位数字.接下来我将数字除以10,然后我再次提取最后一位数字,依此类推......
是否有其他算法(更短,更有效)?
可以提取整数的最后一位数.是否可以提取第一个数字等等?
我刚开始学习UNIX并且出于好奇,我想知道shell shell脚本是否由shell编译或解释?我的猜测是解释.我不确定.
在下面的代码中,如果我在扫描数组“x”的所需长度之前声明可变长度数组“int array1[x]”,则会在执行时收到“分段错误(核心转储)”。(编译没有错误)。我在编译时使用选项 -std=c99 严格使用 ANSI C99 标准。
我的问题是为什么我不能将所有声明合并在一起?
// code to find a minimum value in a variable-length array
#include<stdio.h>
int minval(int [], int);
int main(void)
{
int x, i;
int minivalue;
printf("Enter the total number of array elements you wish to define?");
scanf("%i",&x);
int array1[x];
printf("Enter the elements now:");
for (i = 0; i < x; i++)
scanf("%i",&array1[i]);
minivalue = minval(array1, x);
printf("\nMinimum value in the array is = %i\n",minivalue);
return 0;
}
int minval(int array2[], int x)
{ …Run Code Online (Sandbox Code Playgroud) 我只是注意到一个函数,它在C中作为参数传递,在主函数中不再可用于直接调用.以下代码的编译会产生错误
"../main.c:22:8: error: called object ‘hello’ is not a function or function pointer"
Run Code Online (Sandbox Code Playgroud)
码:
#include<stdio.h>
void hello(void)
{
printf("hello there\n");
}
void main(hello)
{
int y = 100;
printf("%i",y);
if (y==100)
hello();
}
Run Code Online (Sandbox Code Playgroud)
是这样的,还是我做错了什么?
编辑:我将主调用更改为 - void main(void hello (void))现在编译没有错误,但在IF语句不执行printf语句后仍调用hello函数.
编辑NO 2:在阅读了很多答案之后,我了解到我们可以将指向函数的指针作为参数传递给另一个函数.将整个函数作为参数传递是没有意义的.实际上,这整个混乱来自以下opengl C代码,它显然在Eclipse IDE中成功运行:
#include <GL/glut.h>
#include<GL/gl.h>// Header File For The GLUT Library
void init(void)
{
glClearColor (0.0,0.0,0.4,0.0);
glShadeModel(GL_FLAT);
}
void reshape (int w, int h)
{
glViewport(0,0, (GLsizei) w, (GLsizei)h); // indicates the shape of the available screen …Run Code Online (Sandbox Code Playgroud) 我正在建立一个网站作为练习.它有一个"联系我们"页面,我在其中创建了一个表单.我已经用.php扩展名保存了该页面,相信在这种情况下,网页会将表单数据发送到另一个php页面.一旦按下发送按钮,它将导致带有html和php脚本的php页面,该脚本应自动发送电子邮件.但那并没有发生.这是PHP脚本:
<?php
if(isset($_POST['submit']))
{
$name = $_POST['name'];
$email = $_POST['email'];
$mobile = $_POST['mobile'];
$country = $_POST['country'];
$city = $_POST['city'];
$message = $_POST['contactusmessage'];
$headers = 'xxx@xxx.com';
$to = 'xxx@xxx.com';
$mail=mail($to,$message,$headers);
if($mail){
echo"<p>Thanks $name for the message.</p>";
echo"<p>We will reply to $email</p>";
}
else{
echo "Mail sending failed.";
}
}
?>
Run Code Online (Sandbox Code Playgroud)
请告诉我哪里出错了?
我有一个本地仓库。我.git用du -csh <foldername>命令检查了文件夹的大小。它是 168 MB。我把它推送到我的 bitbucket 仓库。我检查了下载的存储库大小仅为 134 mb。
这怎么可能?