㈠ 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();
}
滿意請採納。