常用的代码语言(编程代码语言)
admin
2023-02-24 09:09:14
0

1.请大家帮我分析一下这段简单的C程序代码main(){chars

请注意:四个case后面都没有break 那也就是说不论s[k]的值是什么,只要它是不大于5的,到最后都是要执行i=3这个语句.然后就执行v[i]++,也就是执行v[3]++; 那也就是说只要看数组s里元素的个数,就知道要加多少个一到v[3]里. 因为上面的 s 数组里有8个元素,那也就是说v[3]里加8个一. 故结果就是 0 0 0 8 补充一下: 如果把那些break都补上去,那就是看s数组里各元素的个数了. 比如说s数组里有4个一,那v[0]就是4,依此类推。

那结果就是 4 2 1 1 这样解释希望你能明白。

2.再请教一段简单C语言代码

!子程序已补全。

这么长的代码,难怪没人帮你。不要把这里当成无偿索取的地方。

花了一个多小时,实在没心情调试了,自己调试吧。要求C99。

// tline.c -- by Richard Grenville// Shall use with complier supporting C99 to be safe// Not Tested#include #include #define HOUZHUI ".tmp"#define LINESIZE 256 bool chkoverwrite(char *fname); bool filecpy(FILE *source, FILE *destination); inline void erroroverflow(void){ printf(ERRMSG[8]); exit(6); } int main(int argc, char *argv[]){ const *ERRMSG[] = {"Author: Richard Grenville\nUsage: %s Source File [Destination]\n","Can't find enough argument\n","%s failed, check the order of arguments and filename.\n","Read","Write""Close file failed, check your disk.\n""%s already exists. Are you sure you want to overwrite it?(Y/N) ","Please enter \"y\" or \"n\"\n","Too many characters in a line.\n" }; char linetmp[LINESIZE + 2]; char *linepos; int ctmp; FILE fr, fw; if(argc < 1="" ||="" argc=""> 2){ printf(ERRMSG[0], argv[0]); printf(ERRMSG[1]); exit(1); } else{ if((fr = fopen(argv[1], "r") == NULL) printf(ERRMSG[0], argv[0]); printf(ERRMSG[3]); printf(ERRMSG[2], argv[1]); exit(2) if(argc == 1){ if((fw = fopen(strcat(char tmp[LINESIZE + 5], HOUZHUI), argv[1], "rb") == NULL || (fclose(fw) && chkoverwrite(argv[1]))) && fopen(tmp, "w+b") != NULL){ filecpy(fr, fw); } fclose(fr); fw = fopen(argv[1], "w"); } else if(!((fw = fopen(argv[2], "r") == NULL || (fclose(fw) && chkoverwrite(argv[2]))) && fopen(argv[2], "w") != NULL)){ printf(ERRMSG[0], argv[0]); printf(ERRMSG[3]); printf(ERRMSG[2], argv[2]); } } while(fgets(linetmp, LINESIZE + 2, fr) != EOF){ for((linepos = strchr(linetmp, '\n')) == NULL ? (getc(ctmp, fr) == EOF ? ungetc(ctmp, fr), (linepos = strchr(linetmp, '\0')): (erroroverflow(): 0; linepos > linetmp; linepos--){ putc(linepos, fw); } putc(linetmp, fw); } if(fclose(fr) || fclose(fw)){ printf(ERRMSG[5]); exit(5); } printf("Finished!\n"); getchar(); return 0; } bool chkoverwrite(char *fname){ char ans; printf(ERRMSG[6], fname); while((ans = getchar()) == 'y' ? return 1: (ans == 'n' ? return 0: 1)){ printf(ERRMSG[7]); while(getchar() != '\n'){ continue; } } } bool filecpy(FILE *source, FILE *destination){ int ch; while((ch = getc(source)) != EOF) putc(ch, destination); }。

3.求几个比较有趣,简单的C语言源代码 小白自己敲着练一下手感

例一://按"1"、"2"控制

#include"stdio.h"

#include"conio.h"

void delay(int x)

{ int y;

while(x--)

for(y=0;y<125;y++)

{;}

}

void pout(int i)

{

if(i==1)

{

printf("%c",26);

delay(1000000);

printf("\b%c",0);

}

if(i==2)

{

printf("\b%c",0);

printf("%c",27);

delay(1000000);

printf("\b%c\b\b",0);

}

}

int main()

{

int a=1;

while(1)

{

if(kbhit())

{

a=getch()-48;

}

pout(a);

}

return 0;

}

例二:猜一个1~到100的数

#include

#include

#include

using namespace std;

int main()

{

srand(time(0));//生成随机数生成器种子

int theNumber=rand()%100+1;//1-100的随机数

int tries=0,guess;

cout<<"\tWecome to Guess My Number\n\n";

do

{

cout<<"Enter a guess:";

cin>>guess;

++tries;

if(guess>theNumber)

cout<<"Too high!\n\n";

if(guess

cout<<"Too low!\n\n";

}while(guess!=theNumber);

cout<<"\nThat's it! You got it in "<

return 0;

}

4.谁给我一些简单的c语言代码 新手练习

打印菱形:

#include"stdio.h"

void main()

{

int i,j,n;

scanf("%d",&n);

for(i=0;i

{

for(j=0;j

printf(" ");

for(;j<=n+i;j++)

printf("*");

printf("\n");

}

for(i=0;i<=n;i++)

{

for(j=0;j

printf(" ");

for(;j<=2*n-i;j++)

printf("*");

printf("\n");

}

}

学习循环咯。

5.c语言100行简单一点的代码

登录幼儿园200个小朋友的数据:姓名、性别、年龄、身高、体重、出生日期,分别按年龄排序后输出。

#include

#define N 200

struct child

{

char name[10];

char sex[3];

int age;

int height;

float weight;

struct {

int year;

int month;

int day;

}bdate;

}ch[N];

void input()

{

int i;

for(i=0;i

{

printf("\n请输入第%d名小朋友信息:\n",i+1);

printf("姓名:");

scanf("%s",ch[i].name);

printf("性别:");

scanf("%s",ch[i].sex);

printf("年龄:");

scanf("%d",&ch[i].age);

printf("身高:");

scanf("%d",&ch[i].height);

printf("体重:");

scanf("%f",&ch[i].weight);

printf("出生日期[YYYY-MM-DD]:");

scanf("%d-%d-%d",&ch[i].bdate.year,&ch[i].bdate.month,&ch[i].bdate.day);

}

}

void sort()

{

struct child ct;

int i,j;

for(i=0;i

for(j=0;j

if(ch[j].height

{

ct=ch[j];

ch[j]=ch[j+1];

ch[j+1]=ct;

}

}

void output()

{

int i;

printf("\n\t幼儿园小朋友一览(依身高排序)\n");

printf("===================================================\n");

printf(" 姓名 性别 年龄 身高 体重 出生日期 \n");

printf("===================================================\n");

for(i=0;i

printf(" %-8s %-2s %2d %d %3.1f %d.%d.%d\n",ch[i].name,ch[i].sex,ch[i].age,ch[i].height,ch[i].weight,ch[i].bdate.year,ch[i].bdate.month,ch[i].bdate.day);

}

void main()

{

input();

sort();

output();

}


相关内容

热门资讯

祝家沟村:果红苗翠日子甜 转自:辽宁日报 果树枝头硕果累累、广袤稻田郁郁葱葱……日前,记者再访葫芦岛市绥中县明水满族乡祝家沟村...
涉嫌严重违纪违法,王春秋被查! 转自:上观新闻据中央纪委国家监委驻自然资源部纪检监察组、浙江省纪委监委消息:国家自然资源督察南京局原...
昆明智能化信息采集车上岗   本报讯 记者孙潇报道 在智能化飞速发展的今天,网格化管理也不断迎来智慧化变革。7月4日,记者从昆...
《翠湖》再掀“滇浪潮” 多元云...   当《去有风的地方》将大理古城包装成都市人的精神疗愈所,当《一点就到家》在普洱茶山上演绎电商创业神...
今年前5个月我国服务贸易同比增...   商务部最新数据显示,今年前5个月,我国服务进出口总额32543.6亿元人民币,同比增长7.7%。...
喜娜AI速递:昨夜今晨财经热点... 金融市场犹如变幻莫测的海洋,时刻涌动着投资与经济政策的波澜,深刻影响着全球经济的走向。在此,喜娜AI...
南亚东南亚数字信息大通道加速成...   跨境电商、游戏出海、跨境直播……昆明国际通信业务出入口局的建设,关系到云南乃至南亚东南亚数亿用户...
广西 田园牧歌 产融共富 转自:贵州日报广西壮族自治区柳州市三江自治县春茶喜获丰收。 龚...
手机挖矿哪个最赚钱(正规挖矿赚... 昨天介绍了几款挖掘用的应用,反响很好。今天,我继续介绍其他采矿应用。不要小看这些免费的挖掘软件,它可...
鱼香肉丝的家常做法-做香的厂子... 大家好,我是第一美食的阿飞,关注阿飞,有更多的家常美食供大家参考。今天,我想和大家分享一个经典名菜“...