C语言检测对象是文件还是文件夹bool file_exists ( const char * Pathname ) /* is there a regular file by the name of Pathname. */ { bool Exists; struct stat Inf……继续阅读 » 水墨上仙 4年前 (2021-03-22) 1836浏览 2399个赞
C语言生成随机数#include <stdlib.h>#include <time.h>srand(time(NULL)); /* initialize random seed */rand(); /* Generate a random int from 0 to RAND_MAX */rand(……继续阅读 » 水墨上仙 4年前 (2021-03-22) 2209浏览 2402个赞
C语言获得当前工作路径(POSIX)#include <unistd.h> #include <stdio.h> #define BUF_SIZE 40 int main() { char buf[BUF_SIZE]; char *curDir = getcwd(buf, BUF_SIZ……继续阅读 » 水墨上仙 4年前 (2021-03-22) 1568浏览 276个赞
C语言实现堆排序代码void heapsort(int arr[], unsigned int N) { unsigned int n = N, i = n/2, parent, child; int t; for (;;) { /* Loops until arr is sorted */ ……继续阅读 » 水墨上仙 4年前 (2021-03-22) 2709浏览 406个赞
C语言实现归并排序算法代码// Mix two sorted tables in one and split the result into these two tables. int *Mix(int *tab1,int *tab2,int count1,int count2) { int i,i1,i2; i = i1 = ……继续阅读 » 水墨上仙 4年前 (2021-03-22) 2136浏览 2716个赞
C语言实现快速排序算法#include <stdlib.h> #include <stdio.h> static void swap(void *x, void *y, size_t l) { char *a = x, *b = y, c; while(l--) { c = *a……继续阅读 » 水墨上仙 4年前 (2021-03-22) 2600浏览 2006个赞
C语言读取文件到字节数组#include <stdio.h> #include <stdlib.h> char* readFileBytes(const char *name) { FILE *fl = fopen(name, "r"); fseek(fl, 0, S……继续阅读 » 水墨上仙 4年前 (2021-03-22) 2100浏览 2929个赞
C语言从文件读取文本FILE *f; f = fopen ("path/to/file.ext", "r"); while (!feof (f)) { c = fgetc (f); buff[i++] = c; } fclose (f); buff[i-……继续阅读 » 水墨上仙 4年前 (2021-03-22) 2287浏览 834个赞
C语言翻转字符串#include <stdio.h> #include <string.h> void reverse(char* s) { int i; char temp; size_t l = strlen(s); for (i = 0; i……继续阅读 » 水墨上仙 4年前 (2021-03-22) 1264浏览 243个赞
C语言清除字符串中的非字母字符#include <string.h> while (i != strlen (buff)) { if ((buff[i] >= 65) && (buff[i] <= 90) || (buff[i] >= 97) && (buff[i]……继续阅读 » 水墨上仙 4年前 (2021-03-22) 2448浏览 1582个赞
C语言清除字符串中的非数字字符#include <string.h> while (i != strlen (buff)) { if ((buff[i] >= 48) && (buff[i] <= 57)) { buff_02[j] = buff[i]; ……继续阅读 » 水墨上仙 4年前 (2021-03-22) 3364浏览 1553个赞
程序分析:可以这样考虑: (1)先使a右移4位。(2)设置一个低4位全为1,其余全为0的数。可用~(~0……继续阅读 » 水墨上仙 4年前 (2021-03-22) 1324浏览 190个赞
程序分析: 1 1 1 1 2 1 1 3 3 1 1 4 6 4 1 1 5 10 10 5 1 main(){int i,j;int a[10][10];printf("\n");for(i=0;i<10;i++) {a[i……继续阅读 » 水墨上仙 4年前 (2021-03-22) 1757浏览 1215个赞
C语言创建一个链表/*creat a list*/#include "stdlib.h"#include "stdio.h"struct list{ int data;struct list *next;};typedef struct list node;typedef node *link;……继续阅读 » 水墨上仙 4年前 (2021-03-22) 2176浏览 678个赞
C语言反向输出一个链表/*reverse output a list*/#include "stdlib.h"#include "stdio.h"struct list{ int data; struct list *next;};typedef struct list node;typedef ……继续阅读 » 水墨上仙 4年前 (2021-03-22) 1878浏览 2231个赞
C语言连接两个链表的代码#include "stdlib.h"#include "stdio.h"struct list{ int data;struct list *next;};typedef struct list node;typedef node *link;link delete_no……继续阅读 » 水墨上仙 4年前 (2021-03-22) 3052浏览 1727个赞
海滩上有一堆桃子,五只猴子来分。第一只猴子把这堆桃子凭据分为五份,多了一个,这只猴子把多的一个扔入海中,拿走了一份。第二只猴子把剩下的桃子又平均分成五份,又多了一个,它同样把多的一个扔入海中,拿走了一份,第三、第四、第五只猴子都是这样做的,问海滩上原来最少有多少个桃子?main(){int i,m,j,k,count;for(i=4;i<10……继续阅读 » 水墨上仙 4年前 (2021-03-22) 1242浏览 1654个赞
C语言八进制转换为十进制 main(){ char *p,s[6];int n;p=s;gets(p);n=0;while(*(p)!='\0'){n=n*8+*p-'0';p++;}printf("%d",n);}……继续阅读 » 水墨上仙 4年前 (2021-03-22) 3110浏览 677个赞
C语言求0—7所能组成的奇数个数main(){long sum=4,s=4;int j;for(j=2;j<=8;j++)/*j is place of number*/{ printf("\n%ld",sum);if(j<=2)s*=7;elses*=8;sum+=s;}printf("……继续阅读 » 水墨上仙 4年前 (2021-03-22) 2547浏览 2978个赞
C语言验证一个偶数总能表示为两个素数之和#include "stdio.h"#include "math.h"main(){ int a,b,c,d;scanf("%d",&a);for(b=3;b<=a/2;b+=2){ for(c=2;c<=sqrt(b);……继续阅读 » 水墨上仙 4年前 (2021-03-22) 2274浏览 583个赞
C语言判断一个素数能被几个9整除 main(){ long int m9=9,sum=9;int zi,n1=1,c9=1;scanf("%d",&zi);while(n1!=0){ if(!(sum%zi))n1=0;else{m9=m9*10;sum=sum+m9;c9++;}}printf(&……继续阅读 » 水墨上仙 4年前 (2021-03-22) 3075浏览 2918个赞
C语言两个字符串连接程序#include "stdio.h"main(){char a[]="acegikm";char b[]="bdfhjlnpq";char c[80],*p;int i=0,j=0,k=0;while(a[i]!='\0'&&am……继续阅读 » 水墨上仙 4年前 (2021-03-22) 2479浏览 2793个赞
某个公司采用公用电话传递数据,数据是四位的整数,在传递过程中是加密的,加密规则如下:每位数字都加上5,然后用和除以10的余数代替该数字,再将第一位和第四位交换,第二位和第三位交换。main(){int a,i,aa[4],t;scanf("%d",&a);aa[0]=a%10;aa[1]=a%100/10;aa[2……继续阅读 » 水墨上仙 4年前 (2021-03-22) 2466浏览 231个赞
C语言归并排序算法演示代码#include <iostream> using namespace std; void merge(int*,int,int,int); void mergesort(int *a, int low,int high){ int pivot; if(low<……继续阅读 » 水墨上仙 4年前 (2021-03-22) 1673浏览 194个赞
解释如下:双斜杠之后是注释掉的.前面http:相当于一个goto的标签#include <stdio.h>int main(){ http://www.shello.name/ printf("haha!!\n"); return 0;}……继续阅读 » 水墨上仙 4年前 (2021-03-22) 2222浏览 2688个赞
C语言中function(void)与function()的区别 看下面代码的编译结果void foo1(){}void foo2(void){}main(){ foo1(1); foo2(1); }编译:1.c: In&……继续阅读 » 水墨上仙 4年前 (2021-03-22) 2163浏览 1183个赞
C语言找出大于一个数的最小回文数#include <stdio.h>#include <stdlib.h>#include <string.h>/***********************************************************************************……继续阅读 » 水墨上仙 4年前 (2021-03-22) 2652浏览 3000个赞
C语言按层次遍历二叉树算法#define MaxSize 1000typedef char ElemType; typedef struct node { ElemType data; struct node *lchild; struct node *rchild;} BTNode;//创建二叉树void CreateBTNode(……继续阅读 » 水墨上仙 4年前 (2021-03-22) 3050浏览 660个赞
汉诺塔:汉诺塔(又称河内塔)问题是源于印度一个古老传说的益智玩具。大梵天创造世界的时候做了三根金刚石柱子,在一根柱子上从下往上按照大小顺序摞着64片黄金圆盘。大梵天命令婆罗门把圆盘从下面开始按大小顺序重新摆放在另一根柱子上。并且规定,在小圆盘上不能放大圆盘,在三根柱子之间一次只能移动一个圆盘。#include<stdio.h>#in……继续阅读 » 水墨上仙 4年前 (2021-03-22) 1848浏览 1026个赞
Linux环境下C语言实现贪吃蛇游戏[liul@test snake]$ more snake.c #include <stdio.h>#include <stdlib.h>#include <curses.h>#include <signal.h>#include <sys/time.h……继续阅读 » 水墨上仙 4年前 (2021-03-22) 2449浏览 2766个赞
java二叉树查找、遍历、添加与删除package com.structures.tree;import java.util.ArrayList;import java.util.NoSuchElementException;import java.util.Stack;/* * Binary Search Tree */public ……继续阅读 » 水墨上仙 4年前 (2021-03-22) 1263浏览 1598个赞
C语言分割字符串strtok函数int argc = 0; char** argv = (char **) malloc(30 * sizeof(char *)); char *token = NULL; const char* delim = ","; const char* str = "My……继续阅读 » 水墨上仙 4年前 (2021-03-22) 3011浏览 2035个赞
C语言基础:格式化浮点数输出#include <stdio.h>int main () { float value = 1.23456; printf ("%8.1f\n", value); printf ("%8.3f\n", value); printf ("……继续阅读 » 水墨上仙 4年前 (2021-03-22) 2778浏览 1155个赞
C语言基础:for循环里矢量2个循环因子变量#include <stdio.h>int main() { int i, j; for (i = 0, j = 100; i <= 100; i++, j++) printf("i = %d j = %d\n", i, j);return 1……继续阅读 » 水墨上仙 4年前 (2021-03-22) 1889浏览 148个赞
C语言二叉树遍历代码来自于郝斌老师的数据结构#include<stdio.h>#include<malloc.h>struct BTNode{char data;struct BTNode * pLchild;struct BTNode * pRchild;};void PreTraverseBTree(stru……继续阅读 » 水墨上仙 4年前 (2021-03-22) 2778浏览 2088个赞
C语言基础:for循环语句使用范例演示#include <stdio.h>int main () { int counter; for (counter = -100; counter <= 100; counter += 5) printf("%d ", counter); prin……继续阅读 » 水墨上仙 4年前 (2021-03-22) 1216浏览 1229个赞
C语言基础:for从大到小循环语句范例#include <stdio.h>int main () { int counter; for (counter = 5; counter >= 1; counter--) printf("%d ", counter); printf("……继续阅读 » 水墨上仙 4年前 (2021-03-22) 1403浏览 916个赞
C语言基础:for循环演示代码,字符循环和浮点数循环#include <stdio.h>int main () { char letter; float percent; for (letter = 'A'; letter <= 'Z'; letter++) pu……继续阅读 » 水墨上仙 4年前 (2021-03-22) 1736浏览 2718个赞
C语言基础:格式化输出带符号的数字#include <stdio.h>int main () { int int_value = 5; printf("Left justifed with sign %-+3d\n", int_value);return 1; } ……继续阅读 » 水墨上仙 4年前 (2021-03-22) 2382浏览 1383个赞
C语言基础:goto语句用法演示#include <stdio.h>int main() { int count = 1; label: printf("%d ", count++); if (count <= 100) goto label;retu……继续阅读 » 水墨上仙 4年前 (2021-03-22) 1383浏览 1240个赞
C语言基础:一个无限循环程序(死循环,不要运行)#include <stdio.h>int main () { int i; int result = 0; int value = 1; for (i = 0; i < 100; i++) { printf("%d "……继续阅读 » 水墨上仙 4年前 (2021-03-22) 2652浏览 2634个赞
C语言基础:格式化整数输出#include <stdio.h>int main () { int value = 5; printf ("%1d\n", value); printf ("%2d\n", value); printf ("%3d\n", ……继续阅读 » 水墨上仙 4年前 (2021-03-22) 1888浏览 631个赞
C语言基础:while语句使用范例#include <stdio.h>int main() { int counter = 1; // Initialize the control variable while (counter <= 100) // Test the control variable ……继续阅读 » 水墨上仙 4年前 (2021-03-22) 2689浏览 885个赞
C语言基础:向左向右对其输出数字#include <stdio.h>int main () { int int_value = 5; float flt_value = 3.33; printf("Right justified %5d value\n", int_value); printf……继续阅读 » 水墨上仙 4年前 (2021-03-22) 1561浏览 1830个赞
C语言基础:简单的数学运算#include <stdio.h>int main () { int seconds_in_an_hour; float average; seconds_in_an_hour = 60 * 60; average = (5 + 10 + 15 + 20) / 4; pr……继续阅读 » 水墨上仙 4年前 (2021-03-22) 2959浏览 346个赞