本文目录一览

1,帮帮忙 用c语言编个小程序

#include "stdio.h" int main(){ int a[100],n=0,i,d; while(scanf("%d",&d)!=EOF) a[n++]=d; for(i=0;i

帮帮忙 用c语言编个小程序

2,用C语言编写个小程序

余,是模运算吧,用%运算符。如,data=n%m;(其中n,m都是整数); 输出保留两位有效数字,用printf("%.2f\n",data);
求余例如 a=10/3;
如果除法。两个数都为整数时可以求余……(只有整数能求余吧。。。。)怎么检测两个数是不是整数会吧。 回答完了-_-

用C语言编写个小程序

3,c语言编个小程序

本题的一个完整c程序如下,win-tc和Dev-c++下已调试通过。其中通用排序函数为void sort() #include "stdio.h" #include "stdlib.h" #include "conio.h" #include "string.h" #define ROW 100 #define COL 80 void sort(); int main() { int n,i; char s[ROW][COL+1]; printf("Please input the number of the string you want to sort(not more than %d):\n",ROW); scanf("%d",&n); getchar(); /*开始没加这句只能输入n-1个字符串,排错花了几十分钟,教训深刻,看来是上一句的回车键在作怪,这说明gets()函数也是从缓冲区而非控制台取出字符的*/ printf("Please input the strings one by one (not more than %d characters each):\n",COL); for(i=0;i0) { strcpy(temp,str[j]); strcpy(str[j],str[j+1]); strcpy(str[j+1],temp); } } 本题利用指针数组得出的另一种解法如下: #include "stdio.h" #include "stdlib.h" #include "conio.h" #include "string.h" #define ROW 100 #define COL 80 void sort(); void print(); int main() { int n,i; char s[ROW][COL+1],*p[ROW]; printf("Please input the number of the string you want to sort(not more than %d):\n",ROW); scanf("%d",&n); getchar(); printf("Please input the strings one by one (not more than %d characters each):\n",COL); for(i=0;i0) k=j; if(k!=i) { temp=*(str+i); *(str+i)=*(str+k); *(str+k)=temp; } } } void print(char *str[],int n) { int i; for(i

c语言编个小程序

4,编写一个C语言小程序 急求

/*http://zhidao.baidu.com/question/355983315.html?fr=uc_push&push=core&oldq=1要求用户输入5个同学的有关信息,内容包括姓名,学号,两门课程成绩。如果录入的学号与前面的输入有相同的,提示用户重新输入(仅重新录入该生学号,不能退出程序或让用户全部重新输入相关信息,如果再次录入还有相同的,继续重新输入,直到不同为止)。完成输入后,实现按学号从小到大排序输出,并按平均成绩排序,将按平均成绩排序后的结果存入一个文本文件中(文件名为result.txt)。*/#define N 5#define FILENAME "result.txt"#define MODE "w+"typedef struct _stu int no; char name[20]; int cls1; int cls2;} Stu, *pStu;Stu ar[N] = int checkID(int ID,int pos) int i; for(i=0;i<N;i++) if(pos != i) if(ar[i].no == ID) return 1; } return 0;}int main(int argc, char *argv[]) FILE *pf; int i; if(NULL == (pf = fopen(FILENAME,MODE))) return 0; for(i=0;i<N;i++) printf("input ID num:"); while(scanf("%d",&ar[i].no) && checkID(ar[i].no,i)) printf("input ID num:"); printf("input Stu name:"); scanf("%s",&ar[i].name); printf("input Cls1 grade:"); scanf("%d",&ar[i].cls1); printf("input Cls2 grade:"); scanf("%d",&ar[i].cls2); } for(i=0;i<N;i++) printf("ID = %d name:%s, cls1:%d cls2: %d \n",ar[i].no,ar[i].name,ar[i].cls1,ar[i].cls2); fprintf(pf,"%d %s %d %d\n",ar[i].no,ar[i].name,ar[i].cls1,ar[i].cls2); } fclose(pf); system("PAUSE"); return 0;}

文章TAG:代码制作小程序  帮帮忙  用c语言编个小程序  
下一篇