设计一个C语言程序

作者&投稿:却育 (若有异议请与网页底部的电邮联系)
设计一个C语言程序~

#include
#include
int main()
{
FILE* file = fopen("producer.in","r");
char* buf=(char* )malloc(1<<20);
char* buf2=(char* )malloc(50);
int len;
while((len=fread(buf,1,10)
{
int i;
for(i=0;i<len;++i)
{
printf("%08s ",itoa((int)buf[i],buf2,2));
}
}

}

把producer.in文件的内容“123”转成二进制"00110001 00110010 00110011 00001010"(包含了最后的换行符,ASCII是10)了。
如果希望把答案写入文件可以追问,我追答。

#include "stdio.h"
void main()
{
int i,n;
double s=0.0 ,m;

scanf("%d",&n);
for(i=1;i<=n;i++)
{
m=1.0/i;
if((i>1)&&(i%2))
m=0.0-m;
s+=m;
}
printf("%5.4f",s);
}

#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
#include<string.h>
struct student{
int id;
char name[10];
int age;
int cell;
int tel;
}st[50];
int i=0;
void shuru() {
char a;
do{
printf("\n请输入身份证号:");
scanf("%d",&st[i].id);
fflush(stdin);
printf("\n请输入姓名:");
gets(st[i].name);
printf("\n") ;
printf("请输入年龄:");
scanf("%d",&st[i].age);
printf("\n请输入手机:");
scanf("%d",&st[i].cell);
printf("\n请输入电话:");
scanf("%d",&st[i].tel);
printf("\n是否继续输入另外一个学生信息?(y/n)");
fflush(stdin);
a=getchar();
i++;
}while(a=='y' && i<=50);

}

void xianshi()
{
int j;
printf("\t身份证号 \t姓名\t\t年龄\t\t手机\t\t电话\n");
for(j=0;j<i;j++)
printf(" \t%d\t\t%s \t\t%d\t\t%d\t\t%d\n",st[j].id,st[j].name,st[j].age,st[j].cell,st[j].tel);
getche();
}

void paixu() //按年龄从大到小排序函数
{
int j,k;
int temp;
for(j=0;j<i;j++)
{
for(k=0;k<i-1-j;k++)
{
if(st[k].age<st[k+1].age)
{
temp=st[k].age;
st[k].age=st[k+1].age;
st[k+1].age=temp;
}
}
}
xianshi(); //排序后输出
}

void chazhao()
{
int m;
char name[20],b;
do
{
printf("\n请输入想查找的学生姓名:");
fflush(stdin);
gets(name);
for(m=0;m<i;m++)
{
if(strcmp(name,st[m].name)==0)
{
printf("\n\t\t您查找的学生在第%d个位置找到了!!!\n",m+1);
break;
}
}
if(m>=20)
printf("\n\t\t没有找到这个学生!!!\n");
else
{
printf("\t身份证号 \t姓名\t\t年龄\t\t手机\t\t电话\t\t平均分\n");
printf(" \t%d\t\t%s \t\t%d\t\t%d\t\t%d\n",st[m].id,st[m].name,st[m].age,st[m].cell,st[m].tel);
}
printf("\n是否查找另一个学生的信息?(y/n)");
fflush(stdin);
b=getchar();

}while(b=='y');

}

void main() //主函数
{
int change;
do{
system("cls");
printf("============================学生信息管理系统===================================\n");
printf("\t\t\t一: 输入学生信息\n");
printf("\t\t\t二: 显示学生信息\n");
printf("\t\t\t三: 查找学生信息\n");
printf("\t\t\t四: 退出程序\n");
fflush(stdin);
printf("\n\t\t\t请输入功能选项:");
scanf("%d",&change);
switch(change)
{
case 1:
shuru(); break;
case 2:
xianshi(); break;
case 3:
chazhao(); break;
case 4:
break;
}
getch();
}while(change!=4);
}

用数据库,直接查询就可以了

符合要求,但简陋了些
/*
input
1
n1 101 m 2000-01-01 542
n2 102 w 2000-01-02 565
over 103 m 2000-01-03 595
2
n2

output
n2 102 w 2000-01-02 565

*/#include <stdio.h>
#include <stdlib.h>
#include <string.h>

struct student
{
int num; // 学号
char name[20]; //名字
char sex[10]; //性别
char birth[20]; //出生年月日
int score; //成绩
}stu[100];
int num;
void input()
{
num=0;
printf("输入学生的姓名 学号 性别 生日 成绩(姓名over结束)\n");
while(1)
{
scanf("%s %d %s %s %d",&stu[num].name,&stu[num].num,
&stu[num].sex,&stu[num].birth,&stu[num].score);
if(strcmp(stu[num].name,"over")==0) break;
num++;
}
}

void search()
{
int i,flag=0;
char name[20];
printf("请输入要查询学生的名字\n");
scanf("%s",name);
for(i=0;i<num;i++)
{
if(strcmp(stu[i].name,name)==0)
{
printf("%10s%5d%5s%10s%5d\n",stu[i].name,stu[i].num,
stu[i].sex,stu[i].birth,stu[i].score);
flag=1;
}
}
if(flag==0) printf("未找到符合要求的学生\n");
}

int main()
{
int chos;
while(1)
{
printf("1.输入数据\n");
printf("2.查询学生\n");
printf("3.退出\n");
printf("请选择");
scanf("%d",&chos);
switch(chos)
{
case 1:
input();
break;
case 2:
search();
break;
case 3:
exit(0);
}
}
return 0;
}


C语言问题,编写一个程序计算矩形的面积和周长
1.代码参考:(边长可以是整数也可以是小数;实现乘法的运算符是*)2.代码参考:

求C语言程序:如何获得一个程序运行的时间? 最好带一段简单的代码 新人...
cpu脉冲计数\/ cpu频率,获得开机以来的秒数。当然,这两个函数获得时间精度是很高的(us级别),只是我们一般用不到这么精确。linux下:include <sys\/sysinfo.h> 调用sysinfo()获得系统启动以来经历的秒数时间。这个不属于高精度计时。如果要进行高精度计时,高精度时间,C运行库的gettimeofday().(当然据...

编写一个程序读取输入,读到#字符停止(c语言)?
include<stdio.h> include<string.h> int main(){ int m=0;char a,b[111];scanf("%c",&a);while(a!='#'){ b[m]=a;\/\/出现'#'字符赋值循环终止,之后再输入不会被记录在b数组中;m++;scanf("%c",&a);\/\/这个scanf()作用是前一个a不为'#'时,继续向b数组中赋值;} for(int...

用C语言编一个程序
1. 从1到10的阶乘的和的程序 运行结果:1-10阶乘和为: 4037913 include<conio.h> include<stdio.h> int getResult(int num){ if(num == 1 ) \/* 1! =1 *\/ return 1;else \/* 如果 num != 1 那么则必然有 num! = num * (num -1)!*\/ return num * getResult(num -1);} v...

设计一个双人跳水的计分小程序(C语言)[解出来了另外加分]
编了一个小时...记得给我加分哦~~~嚯嚯 include <stdio.h> include <conio.h> void main(){ float tb[50],js[50];\/\/两个数组为同步分和技术分 int i,j;\/\/记录分数的个数 float maxtb=0,mintb=10000,maxjs=0,minjs=10000;\/\/同步分和技术分的最高和最低分,最高分初始为0,最...

c语言 某校举办才艺大赛,大赛日期由学生设置,系统会产生当天日期,请同 ...
include"stdio.h"int year,month,day,year1,month1,day1,result,n,i,x,y;int table[]={29,31,28,31,30,31,30,31,31,30,31,30,31}; \/\/定义每个月的天数int table1[] = {28,31,29,31,30,31,30,31,31,30,31,30,31};main(){printf("请输入起始日期和终止日期\\n 格式...

用C语言编写AT89C51单片机程序,设计一个智能数字钟。
这是我的课程设计,6个数码管,显示时分秒,三个按钮P0.0、P0.1、P0.2可以调时,有8个彩灯(可以不要),没闹钟、倒计时之类的。呵呵。include<AT89X52.H> define uchar unsigned char int i;\/\/***时钟的 uchar one[10]={0xbf,0xb0,0xdb,0xcf,0xe6,0xed,0xfd,0x07,0xff,0xef}...

求一个用C语言编写的小游戏代码
\/*也不知道你是什么级别的,我是一个新手,刚接触编程语言,以下是我自己变得一个小程序,在所有c语言的编译器(vc++6.0、turbo………)上都能运行,你还可以进一步改进。这是一个类似贪吃蛇的小游戏。祝你好运*\/\/*贪吃蛇*\/#include<stdio.h>#include#include<conio.h>#include<stdlib.h>int head=3 ,tail=0;in...

求C语言高手: 1小时倒计时程序怎么写 以下是我写的,但是不符合常规,总 ...
修改后的代码:#include <stdio.h>#include <stdlib.h>#include<windows.h>int main(){ int a,b,c; a=1; b=0; c=0; while(a>0) { system("cls"); printf("%d:%02d:%d%d\\n",a,b,c,0); a=a-1; b=59; c=59; while(a>=0 && b>=0) { Sl...

用C语言,输入一行数字字符,请用数组元素作为计数器来统计每个数字字符的...
2、定义变量:#include<stdio.h>main(){ char c; \/*定义c为字符型*\/ int letters = 0, space = 0, digit = 0, others = 0; \/*定义letters、space、digit、others、四个变量为基本整型*\/。3、输入字符:printf("please input some characters\\n");while ((c = getchar()) != ...

北市区15699537418: C语言程序设计1. 编写一个程序计算员工周工资,输入某雇员的每周工作时间(以小时计)和每小时的工资数,计算并输出他的工资.若雇员周工作小时超... -
茌房莱阳:[答案] 错了,抱歉,刚才不能用C++,现在改好了 #include void main() { int a,b,c;//a-时间,b-工资,c-每小时工资 printf("Please inputemployee's wage_per_hour:\n"); scanf("%d",&c); printf("Please inputemployee's work time:\n"); scanf("%d",&...

北市区15699537418: 设计一个C语言程序;输入整数x,如果x是正数,输出x的平方;如果x是负数,输出x的2倍. -
茌房莱阳:[答案] int x; scanf("%d",&x); if(x>0) printf("%d",x*x); else if(x

北市区15699537418: 简述开发一个c语言程序的步骤 -
茌房莱阳: 1 写代码.这是最基础的一步,即实现C语言的源文件(.c,必需),和可能的头文件(.h,非必需). 2 编译.将编写好的代码,通过编译工具,转换为目标文件.此步中,会对文件内部及包含的头文件进行语法语义的分析检查.如果出错,...

北市区15699537418: C语言编程,编写一个C语言程序 -
茌房莱阳: #include#define LEN 100 char n[LEN]; char m[LEN]; void write(char *t,char *s) { char d[2]; memset(d,'\0',2); d[0] = *t; strcat(s,d); } void compare(char *a,char *b) { if(*a == '\0') { memset(n,'\0',LEN); return ; } if(*b == '\0') { memset(n,'\0',LEN); return ; } ...

北市区15699537418: C语言程序设计 -
茌房莱阳: 1 # include 2 void print(int n); 3 int increment(int n); 4 int main(void) 5 { 6 int n=3; 7 increment (n); 8 print(n); 9 n = increment(n); 10 print (n); 11 print (...

北市区15699537418: 帮忙设计一个简单C语言程序 -
茌房莱阳: #include#include int main () { char s[10]="abcdef"; char *px=NULL,*py=NULL,*ppx=NULL,*ppy=NULL; px=s; py=s; ppx=s; ppy=s; char y; printf("THE s is :%s ",s); y=*px++; printf("\nTHE y=*px++ y is :%c ",y); y=*ppy--; printf("\nTHE *ppy-- y is ...

北市区15699537418: 最简单的c语言程序设计 -
茌房莱阳: 开学老师教的第一个程序就是输出”Hello World!“.#include<stdio.h> void main() { printf("Hello World!"); }

北市区15699537418: C语言程序设计 -
茌房莱阳: #include <stdio.h> void input(int *arr) {for(int i=0;i<10;i++)scanf("%d",&arr[i]); } void output(int *arr) {for(int i=0;i<10;i++)printf("%d ",arr[i]);printf("\n"); } void pro(int *arr) {int m,n,max=arr[0],min=arr[0],tmp;for(int i=0;i<10;i++){if(arr[i]>...

北市区15699537418: C语言设计程序
茌房莱阳: 很简单.循环获取10个数. 每次获取到一个数.都将其和一个max变量进行比较. 如果输入的数比max大.就将其存放到max变量中. 最后输出就是最大数. 代码如下: #include <stdio.h> void main() { int max=0,t,i; for(i=0;i<10;i++) { scanf("%d",&t); if(t>max) max=t; }printf("max=%d\n",max); }

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 星空见康网