C语言练习:输出N以内的随机排列组合int RandomInterval(int begin, int end){ return begin+rand()%(end-begin);}void GetPermutation(int len){ vector<int> pem(len, -1); f……继续阅读 » 水墨上仙 5年前 (2021-03-22) 1805浏览 2445个赞
给定4个1-9之间的数,通过加减乘除四则运算算出24来,可以使用括号#include "stdafx.h"#include <stdio.h>#include <stdlib.h>double sum(double a,double b){ return a+b;}double mi(doubl……继续阅读 » 水墨上仙 5年前 (2021-03-22) 2531浏览 2285个赞
C语言获取本机Mac地址的代码//linuxint GetLocalMacAddr(char *szMac,int *pnMacLen){ int sock; struct sockaddr_in sin; struct sockaddr sa; struct ifreq ifr; ……继续阅读 » 水墨上仙 5年前 (2021-03-22) 3007浏览 2890个赞
C语言实现的文件型图书管理系统#include<stdio.h>#include<stdlib.h>#include<string.h>struct book{ int num; char bname[50]; char wname[20]; char press[50]; char sort[50]……继续阅读 » 水墨上仙 5年前 (2021-03-22) 1563浏览 655个赞
C语言数据结构之队列使用范例#include<iostream.h>//#include<stdlib.h>template<class T>struct linknode{ T data; linknode<T> *link; linknode<T>(linknode<T……继续阅读 » 水墨上仙 5年前 (2021-03-22) 1802浏览 1717个赞
c语言一种改进的pow(x,y)来源:http://blog.csdn.net/wangzhicheng2013/article/details/8069524#include <iostream>#include <cstdlib>#include <ctime>using namespace std;/*……继续阅读 » 水墨上仙 5年前 (2021-03-22) 2321浏览 2876个赞
C语言添加字符串到文件#include <stdio.h> int main() { FILE *out = fopen("filename", "a"); fprintf(out, "%s", "aString"); fclo……继续阅读 » 水墨上仙 5年前 (2021-03-22) 2187浏览 1136个赞
C语言基础:输出1-100之间的数字#include <stdio.h>void main () { int value = 0; while (value <= 100) { printf("%d\n", value); value++; } }……继续阅读 » 水墨上仙 5年前 (2021-03-22) 3277浏览 766个赞
C语言基础:基本的输出语句#include <stdio.h>void main () { printf ("1001 "); printf ("C and C++ "); printf ("Tips!"); }……继续阅读 » 水墨上仙 5年前 (2021-03-22) 3307浏览 1915个赞
这段代码演示了逻辑与操作,并输出#include <stdio.h>void main () { printf("0 & 0 is %d\n", 0 & 0); printf("0 & 1 is %d\n", 0 & 1); printf(&quo……继续阅读 » 水墨上仙 5年前 (2021-03-22) 2780浏览 1279个赞
C语言基础:亦或xor操作#include <stdio.h>void main () { printf("0 ^ 0 is %d\n", 0 ^ 0); printf("0 ^ 1 is %d\n", 0 ^ 1); printf("1 ^ 1 is %d\n&quo……继续阅读 » 水墨上仙 5年前 (2021-03-22) 2350浏览 2592个赞
C语言基础:或操作#include <stdio.h>void main () { printf("0 | 0 is %d\n", 0 | 0); printf("0 | 1 is %d\n", 0 | 1); printf("1 | 1 is %d\n", ……继续阅读 » 水墨上仙 5年前 (2021-03-22) 2697浏览 287个赞
C语言基础:输出字符#include <stdio.h>void main () { printf("The letter is %c\n", 'A'); printf("The letter is %c\n", 65); }……继续阅读 » 水墨上仙 5年前 (2021-03-22) 2447浏览 2978个赞
本范例通过循环和switch语句统计元音字母数量#include <stdio.h>void main() { char letter; int vowel_count = 0; int consonant_count = 0; for (letter = 'A'; letter……继续阅读 » 水墨上仙 5年前 (2021-03-22) 2460浏览 2255个赞
通过do while循环判断用户输入字符,选择菜单#include <stdio.h>#include <conio.h>#include <ctype.h>#include <stdlib.h>void main() { char letter; do { pri……继续阅读 » 水墨上仙 5年前 (2021-03-22) 1620浏览 2614个赞
C语言基础:printf格式化输出演示代码#include <stdio.h>int main () { float value = 1.23456; printf ("%12.1e\n", value); printf ("%12.3e\n", value); print……继续阅读 » 水墨上仙 5年前 (2021-03-22) 2517浏览 282个赞
C语言基础:printf格式化输出浮点数#include <stdio.h>int main () { float pi = 3.14159; float radius = 2.0031; printf("The circle's area is %e\n", 2 * pi * radiu……继续阅读 » 水墨上仙 5年前 (2021-03-22) 2540浏览 1045个赞
C语言基础:if条件语句使用演示#include <stdio.h>void main () { int age = 21; int height = 73; if (age == 21) printf("User's age is 21\n"); if (age != 2……继续阅读 » 水墨上仙 5年前 (2021-03-22) 3159浏览 953个赞
C语言检测文件大小代码#include <stdio.h> int main() { FILE *FileToCheck; long filesize; FileToCheck = fopen("filename", "rb"); fseek(FileToChe……继续阅读 » 水墨上仙 5年前 (2021-03-22) 2551浏览 2442个赞
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; *a++……继续阅读 » 水墨上仙 5年前 (2021-03-22) 2712浏览 408个赞
C语言遍历二叉树 树结构体struct tree_node { tree_node *left; // left subtree has smaller elements tree_node *right; // right subtree has l……继续阅读 » 水墨上仙 5年前 (2021-03-22) 2801浏览 896个赞
C语言计算圆周率PI#include "stdio.h" #include "stdlib.h" #define SCALE 10000 #define ARRINIT 2000 void pi_digits(int digits) { int carry = 0; ……继续阅读 » 水墨上仙 5年前 (2021-03-22) 1970浏览 1477个赞
C语言输出斐波那契序列#include <stdio.h> main() { int a = 0; int b = 1; int x = 0; while(b < 5000) { printf("%d\n", a); ……继续阅读 » 水墨上仙 5年前 (2021-03-22) 2534浏览 853个赞
C语言计算一个月有多少天int numberOfDays; if (month == 4 || month == 6 || month == 9 || month == 11) numberOfDays = 30; else if (month == 2) { bool isLeapYear = (year % 4 == 0 &am……继续阅读 » 水墨上仙 5年前 (2021-03-22) 1684浏览 2996个赞
C语言转换字符串为大写和小写#include <ctype.h> /* * Convert a string to lowercase */ char *lc(char *str) { char *t; for (t = str; *t; t++) { /* Co……继续阅读 » 水墨上仙 5年前 (2021-03-22) 1681浏览 842个赞
C语言检测指定文件是否存在#include <stdbool.h> #include <stdio.h> bool exists(const char *filename) { FILE *f = fopen(filename, "r"); if (!f) retu……继续阅读 » 水墨上仙 5年前 (2021-03-22) 1610浏览 1512个赞
C语言删除指定的文件#include <stdio.h> int main() { remove("filename"); return 0; } ……继续阅读 » 水墨上仙 5年前 (2021-03-22) 1493浏览 2526个赞
C语言检测文件大小#include <stdio.h> int main() { FILE *FileToCheck; long filesize; FileToCheck = fopen("filename", "rb"); fseek(FileToCheck……继续阅读 » 水墨上仙 5年前 (2021-03-22) 2193浏览 2325个赞
C语言检测对象是文件还是文件夹bool file_exists ( const char * Pathname ) /* is there a regular file by the name of Pathname. */ { bool Exists; struct stat Inf……继续阅读 » 水墨上仙 5年前 (2021-03-22) 2989浏览 1478个赞
C语言生成随机数#include <stdlib.h>#include <time.h>srand(time(NULL)); /* initialize random seed */rand(); /* Generate a random int from 0 to RAND_MAX */rand(……继续阅读 » 水墨上仙 5年前 (2021-03-22) 1654浏览 367个赞
C语言获得当前工作路径(POSIX)#include <unistd.h> #include <stdio.h> #define BUF_SIZE 40 int main() { char buf[BUF_SIZE]; char *curDir = getcwd(buf, BUF_SIZ……继续阅读 » 水墨上仙 5年前 (2021-03-22) 2407浏览 2221个赞
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 */ ……继续阅读 » 水墨上仙 5年前 (2021-03-22) 2764浏览 660个赞
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 = ……继续阅读 » 水墨上仙 5年前 (2021-03-22) 2469浏览 1575个赞
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……继续阅读 » 水墨上仙 5年前 (2021-03-22) 3316浏览 1360个赞
C语言读取文件到字节数组#include <stdio.h> #include <stdlib.h> char* readFileBytes(const char *name) { FILE *fl = fopen(name, "r"); fseek(fl, 0, S……继续阅读 » 水墨上仙 5年前 (2021-03-22) 1417浏览 137个赞
C语言从文件读取文本FILE *f; f = fopen ("path/to/file.ext", "r"); while (!feof (f)) { c = fgetc (f); buff[i++] = c; } fclose (f); buff[i-……继续阅读 » 水墨上仙 5年前 (2021-03-22) 1809浏览 2351个赞
C语言翻转字符串#include <stdio.h> #include <string.h> void reverse(char* s) { int i; char temp; size_t l = strlen(s); for (i = 0; i……继续阅读 » 水墨上仙 5年前 (2021-03-22) 3051浏览 2871个赞
C语言清除字符串中的非字母字符#include <string.h> while (i != strlen (buff)) { if ((buff[i] >= 65) && (buff[i] <= 90) || (buff[i] >= 97) && (buff[i]……继续阅读 » 水墨上仙 5年前 (2021-03-22) 2584浏览 2185个赞
C语言清除字符串中的非数字字符#include <string.h> while (i != strlen (buff)) { if ((buff[i] >= 48) && (buff[i] <= 57)) { buff_02[j] = buff[i]; ……继续阅读 » 水墨上仙 5年前 (2021-03-22) 2698浏览 1758个赞
程序分析:可以这样考虑: (1)先使a右移4位。(2)设置一个低4位全为1,其余全为0的数。可用~(~0……继续阅读 » 水墨上仙 5年前 (2021-03-22) 2511浏览 893个赞
程序分析: 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……继续阅读 » 水墨上仙 5年前 (2021-03-22) 2510浏览 2806个赞
C语言创建一个链表/*creat a list*/#include "stdlib.h"#include "stdio.h"struct list{ int data;struct list *next;};typedef struct list node;typedef node *link;……继续阅读 » 水墨上仙 5年前 (2021-03-22) 2921浏览 2078个赞
C语言反向输出一个链表/*reverse output a list*/#include "stdlib.h"#include "stdio.h"struct list{ int data; struct list *next;};typedef struct list node;typedef ……继续阅读 » 水墨上仙 5年前 (2021-03-22) 3251浏览 407个赞
C语言连接两个链表的代码#include "stdlib.h"#include "stdio.h"struct list{ int data;struct list *next;};typedef struct list node;typedef node *link;link delete_no……继续阅读 » 水墨上仙 5年前 (2021-03-22) 2418浏览 2287个赞
海滩上有一堆桃子,五只猴子来分。第一只猴子把这堆桃子凭据分为五份,多了一个,这只猴子把多的一个扔入海中,拿走了一份。第二只猴子把剩下的桃子又平均分成五份,又多了一个,它同样把多的一个扔入海中,拿走了一份,第三、第四、第五只猴子都是这样做的,问海滩上原来最少有多少个桃子?main(){int i,m,j,k,count;for(i=4;i<10……继续阅读 » 水墨上仙 5年前 (2021-03-22) 2456浏览 1706个赞