当前位置:首页 » 编程语言 » c语言人工编程
扩展阅读
webinf下怎么引入js 2023-08-31 21:54:13
堡垒机怎么打开web 2023-08-31 21:54:11

c语言人工编程

发布时间: 2022-02-01 16:49:02

c语言编程题

根据题意:
题目1:函数参数是除数(这里传值8),返回满足条件的数字和。
题目2:函数参数是要找的项目数(这里传值10),返回对应项的值。

#include<stdio.h>

#define MIN 50

#define MAX 1000

int fa(int a);//对应题目1的函数,参数:要除的数,返回可以被整除的数之和

int getByIndex(int n);//对应题目2,返回数列第n项,错误返回-1

int main()

{

printf("1、%d~%d之间能被%d整除的数字之和为:%d ",MIN,MAX,8,fa(8));

printf("2、数列头三个数为4,5,6,以后的每个数为前三数和,求此数列第%d项:%d ",10,getByIndex(10));

return 0;

}

int fa(int a)//对应题目1的函数,参数:要除的数,返回可以被整除的数之和

{

int i,sum=0;

for(i=MIN;i<=MAX;i++)

if(i%a==0)

sum+=i;

return sum;

}

int getByIndex(int n)//对应题目2,返回数列第n项,错误返回-1

{

if(n<1)

return -1;

int i,nums[n];

nums[0]=4,nums[1]=5,nums[2]=6;

for(i=3;i<n;i++)

nums[i]=nums[i-1]+nums[i-2]+nums[i-3];

return nums[n-1];

}

㈡ 人工生命的c语言编程

咱。。。
能说点具体要求吗?
你这就一句话,怎么编程序啊?

㈢ c语言求编程步骤

#include <stdio.h>
#define NUM_COUNT 20
void swap(int *a, int *b)
{
int n = *a;
*a = *b;
*b = n;
}
int main()
{
int a[NUM_COUNT], *max, *min;
int i;
max = a;
min = a+19;
//读入数字
for(i = 0; i < NUM_COUNT; ++i)
{
printf("Input the %d# number:", i + 1);
scanf("%d", &a[i]);
}
//遍历读入的数字,并逐一与最大、最小数指针处的数字比较
//若大于当前最大数或小于当前最小数,则改变指针指向
for(i = 0; i < NUM_COUNT; ++i)
{
if(a[i] > *max)
{
max = a+i;
}
if(a[i] < *min)
{
min = a+i;
}
}
//将首尾数字与最大最小数交换位置
swap(max, a);
swap(min, a + NUM_COUNT - 1);
//输出结果
for(i = 0; i < NUM_COUNT; ++i)
{
printf("%d ", a[i]);
}
getchar();
getchar();
return 0;
}

㈣ 怎么用C语言编写人工智能程序

如果是没有学习过的话,有一定的难度,建议先去学习。

人工智能代表的范围太大了 C是必不可少的一部分 不能说是有直接关系 可以说是一个必备的组成部分;
人工智能实际的范围和实际应用:机器视觉,指纹识别,人脸识别,视网膜识别,虹膜识别,掌纹识别,专家系统,自动规划,智能搜索,定理证明,博弈,自动程序设计,智能控制,机器人学,语言和图像理解,遗传编程等,
其中几项和C语言、自动化、必不可分。
能力有限,不熟悉人工智能这块。

㈤ C语言程序编程

%c是字符型,也就是说一个%c只能存储一个字符。scanf函数在你输入的内容与编写的格式不一样时就停止输入。所以,输入a给字符a后,本应输入逗号,但是下一个是字母b,所以停止了输入。
要想改正的话,把%c改成%s试试,%s是字符串(输出的也是%s/n%s/n)

㈥ c语言如何编程

C语言编程如何快速实现

在我们初次学习C语言的时候,总想着快速的实现编译过程。那么C语言编程究竟是如何实现的呢,当然是要通过自己喜欢的编译器来编译完成,那么今天就为大家介绍C语言编程是如何快速的实现。

1. 首先我们下载一款适合C语言的编译器,今天为大家讲解的C语言编译器为CodeBlocks,该编译器没有太过复杂,很符合初学者,简单上手快。

㈦ 用c语言怎么编程

#include<stdio.h>
#defineexp1e-6
#definemax64
doublefib[max];
intmain(void)
{
inti;fib[0]=fib[1]=1.0;
for(i=2;i<max;i++)
fib[i]=fib[i-1]+fib[i-2];

doubleans=1.0;
for(i=3;i<max;i++)
{
doubleindex=fib[i-2]/fib[i];
if(i&1)index=-index;
//printf("%.2f%.2f%.2f ",fib[i-2],fib[i],index);
ans+=index;
}
printf("%f ",ans);
return0;
}

㈧ 用C语言怎么编程啊

这是c语言里的最基础题,是循环结构那地方的,你在网上一搜就搜到了

㈨ c语言编程 编程步骤

#include<stdio.h>
#include<math.h>
int a;
int main()
{
int x,y;
scanf("%d",&x)
if(x==a || x=-a)
y=0;
else if(x>-a && x<a)
y=sqrt(a*a-x*x);
else if(x<-a &&x>a)
y=x;
printf("%d",y);
return 0;
}

㈩ c语言编程

生命游戏
/* ------------------------------------------------------ */
/* PROGRAM game of life : */
/* This is a finite implementation of John H. Conway's */
/* Game of Life. Refere to my book for detail please. */
/* */
/* Copyright Ching-Kuang Shene July/25/1989 */
/* ------------------------------------------------------ */

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

#define MAXSIZE 50 /* board size */
#define OCCUPIED 1 /* occupied flag */
#define UNOCCUPIED 0
#define YES 1
#define NO 0

char cell[MAXSIZE][MAXSIZE]; /* the board */
char work[MAXSIZE][MAXSIZE]; /* a working */
int row; /* No. of rows you want */
int column; /* no. of columns you want */
int generations; /* maximum no. of generation*/

/* ------------------------------------------------------ */
/* FUNCTION read_in : */
/* This function reads in the number of generations, */
/* the number of rows, the number of columns and finally */
/* the initial configuration (the generation 0). Then put*/
/* your configuration to the center of the board. */
/* ------------------------------------------------------ */

void read_in(void)
{
int max_row, max_col; /* max # of row and col. */
int col_gap, row_gap; /* incremnet of row and col */
int i, j;
char line[100];

gets(line); /* read in gens, row and col*/
sscanf(line, "%d%d%d", &generations, &row, &column);
for (i = 0; i < row; i++)/* clear the board */
for (j = 0; j < column; j++)
cell[i][j] = UNOCCUPIED;
max_col = 0; /* read in the config. */
for (max_row = 0; gets(line) != NULL; max_row++) {
for (i = 0; line[i] != '\0'; i++)
if (line[i] != ' ')
cell[max_row][i] = OCCUPIED;
max_col = (max_col < i) ? i : max_col;
}
row_gap = (row - max_row)/2; /* the moving gap */
col_gap = (column - max_col)/2;
for (i = max_row + row_gap - 1; i >= row_gap; i--) {
for (j = max_col + col_gap - 1; j >= col_gap; j--)
cell[i][j] = cell[i-row_gap][j-col_gap];
for ( ; j >= 0; j--)
cell[i][j] = UNOCCUPIED;
}
for ( ; i >= 0; i--)
for (j = 0; j < column; j++)
cell[i][j] = UNOCCUPIED;
}

/* ------------------------------------------------------ */
/* FUNCTION display : */
/* Display the board. */
/* ------------------------------------------------------ */

#define DRAW_BOARDER(n) { int i; \
printf("\n+"); \
for (i = 0; i < n; i++) \
printf("-"); \
printf("+"); \
}
void display(int gen_no)
{
int i, j;

if (gen_no == 0)
printf("\n\nInitial Generation :\n");
else
printf("\n\nGeneration %d :\n", gen_no);

DRAW_BOARDER(column);
for (i = 0; i < row; i++) {
printf("\n|");
for (j = 0; j < column; j++)
printf("%c", (cell[i][j] == OCCUPIED) ? '*' : ' ');
printf("|");
}
DRAW_BOARDER(column);
}

/* ------------------------------------------------------ */
/* FUNCTION game_of_life : */
/* This is the main function of Game of Life. */
/* ------------------------------------------------------ */

void game_of_life(void)
{
int stable; /* stable flag */
int iter; /* iteration count */
int top, bottom, left, right; /* neighborhood bound */
int neighbors; /* # of neighbors */
int cell_count; /* # of cells count */
int done;
int i, j, p, q;

display(0); /* display initial config. */
done = NO;
for (iter = 1; iter <= generations && !done; iter++) {
memmove(work, cell, MAXSIZE*MAXSIZE); /**/
stable = YES; /* assume it is in stable */
cell_count = 0; /* # of survived cells = 0 */
for (i = 0; i < row; i++) { /* scan each cell...*/
top = (i == 0) ? 0 : i - 1;
bottom = (i == row - 1) ? row-1 : i + 1;
for (j = 0; j < column; j++) {
left = (j == 0) ? 0 : j - 1;
right = (j == column - 1) ? column-1 : j + 1;

/* compute number of neighbors */

neighbors = 0;
for (p = top; p <= bottom; p++)
for (q = left; q <= right; q++)
neighbors += work[p][q];
neighbors -= work[i][j];

/* determine life or dead */

if (work[i][j] == OCCUPIED)
if (neighbors == 2 || neighbors == 3) {
cell[i][j] = OCCUPIED;
cell_count++;
}
else
cell[i][j] = UNOCCUPIED;
else if (neighbors == 3) {
cell[i][j] = OCCUPIED;
cell_count++;
}
else
cell[i][j] = UNOCCUPIED;
stable = stable && (work[i][j] == cell[i][j]);
}
}
if (cell_count == 0) {
printf("\n\nAll cells die out.");
done = YES;
}
else if (stable) {
printf("\n\nSystem enters a stable state.");
done = YES;
}
else
display(iter);
}
}

/* ------------------------------------------------------ */

void main(void)
{
read_in();
game_of_life();
}

满意请采纳。