coding----1wcods----坚持第7天----1152行

来源:互联网 发布:tcp动态端口 编辑:程序博客网 时间:2024/06/05 19:40
#include <stdio.h>int main(){    int x, y, z;    x = 2;    x *= (y=z=5);    printf("%d\n",x);    z = 3;    x == (y=z);    printf("%d\n",x);    x = (y==z);    printf("%d\n",x);    x = y&z;    printf("%d\n",x);    x = y&&z;    printf("%d\n",x);    x = y|z;    printf("%d\n",x);        x = y||z;    printf("%d\n",x);    return 0;}#include <stdio.h>/* 统计对应二进制数中1的个数*/int function(int x){    int count = 0;    while (x) {        count ++;        x = x &(x -1);    }    return count;}int main(){    printf ("%d\n",function(7));            return 0;}#include <stdio.h>int main(){    int a, x;    /* 先检查a<=1是否满足条件,满足再检查 !x++,否则直接退出*/    for (a = 0,x =0; a <=1 && !x++;a++) {        a ++;    }    printf ("a=%d,x=%d\n",a,x);    /* 先检查a<=1是否满足条件,满足再检查 !x++,否则直接退出*/    for (a = 0,x =0; a <=1 && !x++;) {        a ++;    }    printf ("a=%d,x=%d\n",a,x);    return 0;}#include <stdio.h>int main(){    int b = 3;    int arr[] = {6,7,8,9,10};    int *ptr = arr;    *(ptr++) += 123;    printf ("%d\n",*(ptr -1));    /* printf执行的时候是从右向左压栈,     * 也就是先执行右边参数的计算,再计算左边的     */    //printf ("%d,%d\n",*ptr,*(ptr++));    printf ("%d,%d\n",*ptr,*(++ptr));    return 0;}#include <stdio.h>#include <stdbool.h>/* 顶点类型*/typedef char vertex_type;/* 边界类型,存放权重或顶点关系*/typedef int edge_type;#define MAXVERTEX (100)/* 区分权重,代表无穷大*/#define INFINITY (65535)typedef struct {    /* 顶点表*/    vertex_type vertex[MAXVERTEX];    /* 邻接表*/    edge_type edge[MAXVERTEX][MAXVERTEX];    /* 当前图的边界,顶点数目*/    int cur_num_edge, cur_num_vertex;}graph_type;void flush (){    char ch;    while ((ch = getchar()) != '\n' && ch != EOF);}/* 创建无向网图的,邻接矩阵*/void create_undirected_graph (graph_type *graph){    printf ("enter the number of vertexs and edges\nfor example 10 10\n");    scanf ("%d %d",&graph->cur_num_vertex,&graph->cur_num_edge);    flush();    for (int i =0;i < graph->cur_num_vertex;i ++)        for (int j = 0; j < graph->cur_num_vertex; j++)            graph->edge[i][j] = INFINITY;    printf ("enter the vertexs\n");    for (int i =   0;i < graph->cur_num_vertex; i++) {        scanf ("%c",&graph->vertex[i]);        flush();    }    int i, j, weight;    for  (int k =0;  k  <graph->cur_num_edge; k++) {        printf ("enter the i,j of (vi,vj) and weight\n");        scanf ("%d %d %d",&i,&j,&weight);        flush();        graph->edge[i][j] = weight;        graph->edge[j][i] = graph->edge[i][j];    }    }/* 访问标志数组*/int visited[MAXVERTEX];/* 深度优先遍历DFS*/void DFS(graph_type *g,int i){    visited[i] = true;    /* 打印访问到的节点,也可以进行其他操作*/    printf ("%c",g->vertex[i]);    for (int j =0;j < g->cur_num_vertex;j++){        if (g->edge[i][j] ==1 && !visited[j])            DFS(g,j);    }}void DFS_traverse (graph_type *g){    for (int i =0;i < g->cur_num_vertex;i++) {        visited[i] = false;    }    for (int i =0;i < g->cur_num_vertex;i ++) {        if (!visited[i])            DFS(g,i);    }}int main (){    graph_type graph_tst;    create_undirected_graph (&graph_tst);    DFS_traverse (&graph_tst);    printf("\n");    return 0;}

0 0