c语言项目源码
#include "stdio.h"
#define MAX 100 /*定义输入数据的最大长度*/
void countmax(int a[MAX],int N){ /*计算最值的函数*/
int minn=a[0],maxx=a[0]; /*minn表最小值,maxx表最大值*/
for(int i=0;i<=N;i++){ /*N是实际输入数组的长度*/
if(a[i]<minn) /*循环求最值*/
minn=a[i];
else
if(a[i]>maxx)
maxx=a[i];
}
printf("\n最小值:%d\n最大值:%d\n",minn,maxx);
printf("\n————————————————————————\n");
}
void found(int a[MAX],int N){ /*查找函数*/
int Flag = 1,x; /*Flag用来标记是否查找成功,0表成功,1表未成功*/
printf("请输入你要查找的数: ");
scanf("%d",&x); /*x是待查找的数*/
for(int i=0;i<=N;i++){
if(a[i]==x){
printf("所找的数在数组中的位置是第 %d 位\n",i+1);
Flag = 0;
break;
}
}
if(Flag == 1)
printf("Not Found!\n");
printf("————————————————————————\n");
}
void deletedata(int a[MAX],int N){ /*删除操作函数*/
int Flag = 1,x,pos; /*Flag用来标记是否删除成功,0表成功,1表未成功,pos用来记录删除的位置*/
printf("请输入你要删除的数: ");
scanf("%d",&x);
for(int i = 0;i <= N;i++){ /*在数组中循环查找所要删除的数*/
if(a[i]==x){
for(int j=i;j<=N;j++) /*删除位置后的数全部向前移动一位*/
a[j]=a[j+1];
Flag = 0;
N--; /*数组长度减1*/
pos = i; /*记录删除位置*/
break;
}
}
if(Flag==1)
printf("Not Found!");
else{
printf("删除成功!\n");
printf("所删除的数在数组中的位置是第 %d 位\n",pos+1);
}
printf("删除操作后的数据为:\n");
for(int j=0;j<=N;j++)
printf("%d ",a[j]);
printf("\n————————————————————————\n");
}
void sumdata(int a[MAX],int N){ /*求奇数和偶数函数*/
int SUM1=0,SUM2=0,N1=0,N2=0;
/*SUM1表示偶数之和,N1表偶数个数
**SUM2表示奇数之和,N2表奇数个数
*/
for(int i=0;i<=N;i++){
if(a[i]%2==0){
N1++;
SUM1 = SUM1 + a[i];
}
else{
N2++;
SUM2 = SUM2 + a[i];
}
}
printf("数据中的偶数个数为: %d 个,平均值为: %d\n",N1,SUM1/N1);
printf("数据中的奇数个数为: %d 个,平均值为: %d\n",N2,SUM2/N2);
printf("————————————————————————\n");
}
int main(){
int i=0,k,N,a[MAX],data;
/*k用来标记所选择的操作,data表示输入的数据,a数组用来存储输入的数据*/
printf("请输入数据:\n");
scanf("%d",&data);
while(data!=0){
a[i]=data;
scanf("%d",&data);
N=i++;
}
printf("\n您输入了%d个数据,如下所示:\n",N+1);
for(i=0;i<=N;i++)
printf("%d ",a[i]);
printf("\n————————————————————————");
printf("\n\n请选择下面的一个项目:\n");
printf("1、求最值\n2、查找\n3、删除\n4、统计及平均\n5、退出\n");
printf("————————————————————————\n");
scanf("%d",&k);
switch(k){
case 1:
countmax(a,N);
break;
case 2:
found(a,N);
break;
case 3:
deletedata(a,N);
break;
case 4:
sumdata(a,N);
break;
case 5:
break;
default:
break;
}
return 0;
}
B. 求c语言代码
#include <stdio.h>
int main()
{
int a, b, c;
printf("请输入每组加班的人数:\n");
scanf("%d%d%d", &a, &b, &c);
int i = 0;
while (++i)
{
版if ((0 == i % a) && (0 == i % b) && (0 == i % c))
{
printf("核桃的数量权为: %d\n", i);
break;
}
}
return 0;
}
C. 推荐个C语言写的开源程序,我要看源代码
额,,网上很多的么,像那些小游戏,俄罗斯方块什么的
D. 急求一个c语言编写的图书管理系统的源代码,谢谢
/* Note:Your choice is C IDE */
#include "stdio.h"
#include<graphics.h>
#include "conio.h"
#include<stdlib.h>
#include<string.h>
void main()
{void adm1(),adm2(),build(),huan(),borrow(),dele();
adm1();
}
void adm1()
{ FILE *fp,*p ;
char adp[20],password[20];
int i,n=0;
textbackground(2);
clrscr();
gotoxy(25,12);
fp=fopen("pass","r");
if(fp==NULL) { printf("no exit ");getch();exit(0);}
printf("input password:");
for(;;)
{
window(42,12,53,12);
textbackground(0);
clrscr();
gets(adp);
for(i=0;adp[i]!='\0';i++);
fgets(password,i+1,fp);
gotoxy(55,12);
if(strcmp(password,adp)==0) { window(55,12,70,12);clrscr();cprintf("YES");getch();adm2();getch();exit(0);}
else{ n++;
window(55,12,60,12);clrscr();gotoxy(55,12);cprintf("error");
for(i=0;i<30;i++) delay(8000);
if(n==2) { window(55,12,70,12);clrscr();gotoxy(55,12);cprintf("once again");for(i=0;i<=30;i++) delay(8000);}
if(n==3) { window(55,12,70,12);clrscr();gotoxy(55,12);cprintf("3 second out");for(i=0;i<=30;i++) { delay(8000);}
exit(0);
}
}
fclose(fp);clrscr();
}
}
void adm2()
{ char a;
window(1,1,80,25);
clrscr();
for(;;)
{ clrscr();
gotoxy(30,8);printf("built a new user (B)");
gotoxy(30,10);printf("return book (R)");
gotoxy(30,12);printf("borrow books (J)");
gotoxy(30,14);printf("delete user (D)");
a=getch();
if(a=='b') build();
if(a=='r') huan();
if(a=='j') borrow();
if(a=='d') dele();
else continue;
}
}
void build()
{ FILE *f,*p;
char id[20],name[20],sex[2],age[3],grad[50];
window(1,1,80,25);
clrscr();
printf("ID number:");
scanf("%s",id);
printf("name:");
scanf("%s",name);
printf("sex:");
scanf("%s",sex);
printf("grad:");
scanf("%s",grad);
p=fopen(id,"w+");
if(p==NULL) { printf("can't build that user");getch();adm2();}
fprintf(p,"%s ",name);
fprintf(p,"%s ",id);
fprintf(p,"%s ",sex);
fprintf(p,"%s ",grad);
printf("bulid success");
getch();
fclose(p);
}
void huan()
{
FILE *fp,*p,*f;
char id[20],a[5][50],name[20],c;
int i=0,m,k; clrscr();
printf("input ID number:");
scanf("%s",id);
p=fopen(id,"r");
if(p==NULL) { printf("error");getch();fclose(p);exit(0);}
fscanf(p,"%s",name);
fclose(p);
fp=fopen(name,"r");
do{ fscanf(fp,"%s",a[i++]); }while(!feof(fp));
for(k=0;k<i-1;k++) printf("\nbook %d: %s",k+1,a[k]);
fclose(fp);
f=fopen(name,"w+");
for(;;)
{
printf("\n\npress the book number that you want to return. \n\nPress 6 if you want to return all. \n\npress 7 to cancle.\n");
scanf("%d",&m);
if(m==7) { for(k=0;k<i-1;k++)
{
fprintf(f,"%s\n",a[k]);
}
fclose(f);
adm2();
}
if(m==6) remove(name);
if(m<6)
for(k=0;k<i-1;k++)
{ if(k!=m-1)
fprintf(f,"%s\n",a[k]);
}
printf("book %d has returned.",m);
printf("\ncontinue? (Y/N)");
c=getch();
if(c=='y') continue;
if(c=='n') { fclose(f);adm2(); }
}
}
void borrow()
{ FILE *f,*m,*p;
char id[20],book[5][50],name[20],c;
int i=0,n=0,k;
window(1,1,80,25);clrscr();
printf("please input the user's ID:");
scanf("%s",id);
m=fopen(id,"r");
if(m==NULL) { printf("user no exit"); getch();fclose(m);adm2();}
fscanf(m,"%s",name);
fclose(m);
p=fopen(name,"r");
if(p==NULL);
else
{ while(!feof(p))
{
fscanf(p,"%s",book[i]);
i++;
}
i--;
for(k=0;k<i;k++) printf("\nbook %d :%s",k+1,book[k]);
}
fclose(p);
f=fopen(name,"w");
printf("\nhow many book do you want to borrow?:");
do{printf("\ninput:");scanf("%d",&n); }while(i+n>=6);
for(k=i;k<i+n;k++)
{ printf("\nbook %d :",k+1);
scanf("%s",book[k]);
}
for(k=0;k<i+n;k++) fprintf(f,"%s\n",book[k]);
fputc('\0',f);
printf("success");
fclose(f);
}
void dele()
{ FILE *fp,*f;
char id[20],a[4][20],c,b[5][50];
int i=0,j=0,k;
window(1,1,80,25);clrscr();
printf("Input ID number:");
scanf("%s",id);
fp=fopen(id,"r");
if(fp==NULL) { printf("\nuser isn't exit");getch(); fclose(fp);adm2();}
else while(!feof(fp))
{ fscanf(fp,"%s",a[i++]);}
printf("\nname: %s",a[0]);
printf("\nID: %s",a[1]);
printf("\nsex: %s",a[2]);
printf("\ngrad: %s",a[3]);
f=fopen(a[0],"r");
if(f==NULL);
else {
while(!feof(f))
{ fscanf(f,"%s",b[j++]);}
for(k=0;k<j-1;k++) printf("\nbook %d: %s",k+1,b[k]);
}
printf("\nDo you want to delete? (Y/N): ");
c=getch();
fclose(fp);
fclose(f);
if(c=='y') { remove(id);remove(a[0]);printf("\nsuccess");getch();adm2();}
if(c=='n') adm2();
}
E. 求一份C语言小项目的代码,要求150行以上,很急!
我给个我写的吧,不过不完全符合要求。子函数只有7个,但有两个宏,其中一个可以换成函数。其实如果把测试改成自动的,可以超过10个,你可以自己改一改。
项目名称:UTF8StringEscaper。在Github上可以搜到,不过其实只是个单文件的小程序。代码参考了leptjson。
项目概述:此程序可以将输入的UTF8文本进行转义,例如如果手动输入 1 2 这四个字符,可以输出 1(换行)2。
采用的C语言技术,这怎么好写呢?:注释、转义序列、预处理器、指针、inline
/*测试用例:
hello,world
u4F60u597D u4E16u754C
uD869uDEA5
你好//win下失败
uqweru1234
u0068uqwer
auDFFFa
auD800a
ym
uD800u0068
uD800uqwer
*/
#include<assert.h>
#include<stdbool.h>
#include<stdio.h>
#include<stdlib.h>
#ifdefined__clang__&&!(definedWIN32||definedlinux||definenix)
#defineWIN32
#endif
#definemovenext(ch,p)(ch=*p++)
voidParse(constchar*p);
intParseUnicode(constchar**pp);
intParseHex(constchar*num);
(unsignedshorthigh,unsignedshortlow);
voidEncodeUTF8(unsignedcodePoint);
intmain(void)
{
#ifdefWIN32
system("chcp65001");
#endif
charinput[BUFSIZ];
printf(" ¥>");
while(gets(input)!=NULL)//读到EOF时返回NULL
{
Parse(input);
printf(" ¥>");
}
return0;
}
#defineHandleEscape(ch,escaped)
casech:
putchar(escaped);
break
voidParse(constchar*p)
{
charch;
while(movenext(ch,p)!='