❶ 圖 (c語言)
我來做,等等
/*編寫無向圖的鄰接矩陣類AdjMWGraph,實現無向圖的廣度遍歷和深度遍歷。
其中,圖中頂點數據類型為字元。Input第一行圖中頂點的個數n(4<=n<=26)
第二行是圖中邊的條數m(3<=m<=351) 第三行是頂點信息(全為大寫字母)
後面的輸入數據是依附於一條邊的兩個頂點,有多少條邊,就輸入多少組信息。
注意:根結點都為A;並且所給字元連續,也就是說A B C D ……。
Output廣度優先搜索序列。 深度優先搜索序列。
Sample Input
7
6
A B C D E F G
A B
A C
B D
B E
C F
C G
Sample Output
A B C D E F G
A B D E C F G
*/
#include <stdio.h>#include <stdlib.h>
unsigned char arrMap[26][26] = {0};
int nV = 0;
void deep_prior_scan(int j);
void spread_prior_scan(int j);
void GetResult()
{
int nL = 0;//存儲邊數
int i;
char arrV[26] = {0};
char temp, pairV[2];
//輸入過程
printf("\n請輸入頂點數:");
scanf("%d", &nV);
printf("\n請輸入邊數:");
scanf("%d", &nL);
printf("\n請依次輸入頂點:\n");
for (i = 0, temp = 'A'; i < nV; )
{
temp = getchar();
if (temp >= 'A' && temp <= 'Z')
{
arrV[i++] = temp;
}
}
printf("\n請依次輸入邊:\n");
for (i = 0; i < nL*2; )
{
temp = getchar();
if (temp >= 'A' && temp <= 'Z')
{
pairV[i%2] = temp;
if (i%2 == 1)
{
arrMap[pairV[0] - 'A'][pairV[1] - 'A'] = 1;
}
++i;
}
}
//printf("\n廣度優先遍歷:\n");
//spread_prior_scan(0);
//printf("\n");
printf("\n深度優先遍歷:\n");
deep_prior_scan(0);
printf("\n");
}
int main()
{
GetResult();
system("pause");
return 0;
}
void deep_prior_scan(int j)
{
int i;
printf("%c ", j + 'A');
for (i = 0; i < nV; i++)
{
if (arrMap[j][i] != 0)
{
arrMap[j][i] = 0;
deep_prior_scan(i);
}
}
}
void spread_prior_scan(int j)
{
int i;
if (j == 0)
{
printf("\nA ");
}
if (j >= 26)
{
printf("\nj=%d\n", j);
}
for (i = 0; i < nV; i++)
{
if (arrMap[j][i] != 0)
{
printf("%c ", i + 'A');
}
}
for (i = 0; i < nV; i++)
{
if (arrMap[j][i] != 0)
{
arrMap[j][i] = 0;
spread_prior_scan(i);
}
}
}
因為懶得復制數組,所以兩種遍歷方法要分開運行,你可以通過打開和關閉對相應函數的注釋來得到兩次的結果
❷ c語言編圖
這個是3行的,下面個程序是輸出7行的,可以改動i來控制行數改動j來控制*和空格的輸出個數
#include<stdio.h>
int main()
{
int i,j,m;
for(i=0;i<=1;++i)
{
for(j=0;j<1-i;++j)
printf(" ");
for(m=0;m<2*i+1;++m)
printf("*");
printf("\n");
}
for(i=1;i>=1;--i)
{
for(j=0;j<=1-i;++j)
printf(" ");
for(m=0;m<2*i-1;++m)
printf("*");
printf("\n");
}
getch();
return 0;
}
這個是7行的.
#include<stdio.h>
int main()
{
int i,j,m;
for(i=0;i<=3;++i)
{
for(j=0;j<3-i;++j)
printf(" ");
for(m=0;m<2*i+1;++m)
printf("*");
printf("\n");
}
for(i=3;i>=1;--i)
{
for(j=0;j<=3-i;++j)
printf(" ");
for(m=0;m<2*i-1;++m)
printf("*");
printf("\n");
}
getch();
return 0;
}
❸ c語言程序圖
小寫字母a和b的ascii碼分別是97和98(即內存值),減去32之後分別是65和66,而這兩個值剛好是大寫A和B的ascii碼。所以,當以字元輸出的時候(即printf裡面是%c,表示以字元形式輸出),就輸出A和B。以整形形式(%d)輸出的時候,就是它們的值,65和66。
❹ C語言 圖
#include <stdio.h>
int sqare(int n)
{return n*n;
}
int main()
{ int i,s=0;
for(i=1;i<4;i++)
s+=sqare(i);
printf("%d ",s);
return 0;
}
❺ c語言如圖片
初始化:f1 = 0 , f2 = 1;
for循環,i=3 開始循環,到i=5,那麼就是循環了3次;
for循環體里頭的內容,需要計算三次:
1、f = f1 + f 2 -- 計算f值;
2、f1 = f2 ; -- f1重新賦值 為f2;
3、 f2 = f; -- f2重新賦值為f;
4、print(f) ; -- 循環3次就輸出三次;
輸出結果應該是: 1 2 3
❻ C語言如何畫圖
framebuffer(幀緩沖)。
幀的最低數量為24(人肉眼可見)(低於24則感覺到畫面不流暢)。
顯卡與幀的關系:由cpu調節其數據傳輸速率來輸出其三基色的配比。
三基色:RGB(紅綠藍)。
在沒有桌面和圖形文件的系統界面,可以通過C語言的編程來實現在黑色背景上畫圖!
用下面的代碼,在需要的地方(有注釋)適當修改,就能畫出自己喜歡的圖形!
PS:同樣要編譯運行後才能出效果。
#include <stdio.h>
#include <sys/mman.h>
#include <fcntl.h>
#include <linux/fb.h>
#include <stdlib.h>
#define RGB888(r,g,b) ((r & 0xff) <<16 | (g & 0xff) << 8 | (b & 0xff))
#define RGB565(r,g,b) ((r & 0x1f) <<11 | (g & 0x3f) << 5 | (b & 0x1f))
int main()
{
int fd = open("/dev/fb0", O_RDWR);
if(fd < 0){
perror("open err. ");
exit(EXIT_FAILURE);
printf("xres: %d ", info.xres);
printf("yres: %d ", info.yres);
printf("bits_per_pixel: %d ", info.bits_per_pixel);
size_t len = info.xres*info.yres*info.bits_per_pixel >> 3;
unsigned long* addr = NULL;
addr = mmap(NULL, len, PROT_WRITE|PROT_READ, MAP_SHARED, fd, 0);
if(addr == (void*)-1){
perror("mmap err. ");
❼ c語言。圖
continue;
if(j%10==0)
❽ c語言 圖片
1、如果有圖片(例如 wzzx.jpg) 程序中插一句:
system("mspaint wzzx.jpg"); 就可以 在運行時顯示這張圖片。
用字元串變數調用也可以:
char pic_name[80]="wzzx.jpg";
char cmd[100];
sprintf(cmd,"mspaint %s",pic_name);
system(cmd); // 顯示圖片
2、system函數:
原型:int system(const char * command);
功能:執行 dos(windows系統) 或 shell(Linux/Unix系統) 命令,參數字元串command為命令名;
說明:在windows系統中,system函數直接在控制台調用一個command命令。在Linux/Unix系統中,system函數會調用fork函數產生子進程,由子進程來執行command命令,命令執行完後隨即返回原調用的進程;
頭文件:stdlib.h;
返回值:命令執行成功返回0,執行失敗返回-1。
❾ C語言 圖的遍歷
思路:
以鄰接表或鄰接矩陣為存儲結構,實現連通無向圖的深度和廣度優先遍歷。以用戶指定的結點為起始點
,分別輸出每種遍歷下的結點訪問序列和相應的生成樹的邊集。
設圖的結點不超過30個,每個結點用一個編號表示。通過輸入圖的全部邊輸入一個圖,每個邊為一個數對
可以對邊的輸入順序作出某種限制。注意,生成樹和生成邊是有向邊,端點順序不能顛倒。