当前位置:三九宝宝网 → 宝宝教育 → 教学论文 → 正文

c语言编个小程序

更新:03-17 整理:39baobao.com
字体:

[c语言入门程序]请仔细看看你的程序: main() { int a; scanf("%d",a); //注意这里的scanf语句用错了应该是scanf("%d",&a); 这里的&符号千万不能省啊。 printf("%d",a); } 你应该多注意一下scanf语法...+阅读

本题的一个完整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语言小程序

#include

int main() { unsigned char s[] = {"01234"}; unsigned short i,j,m,sum = 0; for(i = 1;i < 5;i++) { for(j = 1;j < 5;j++) { for(m = 1;m < 5;m++) { if((j != i) && (m != i) && (m != j)) { printf("%c%c%c ",s[i],s[j],s[m]); sum++; if(sum % 8 == 0) printf("\n"); } } } } printf("\n\n共可组成%d个三位数。\n\n",sum); return 0; }

c语言小程序

#include

int l,w,z; // hold the votes

int flag; // control the loop

int main( void )

{

puts("1 - l");

puts("2 - w");

puts("3 - z");

puts("Enter the vote number ( invalid number to quit ):");

do{

scanf("%d",&flag);

switch( flag )

{

case 1: l++; break;

case 2: w++; break;

case 3: z++; break;

default : puts("Thank you for using!");

}

}while ( flag >0 && flag < 4 );

puts("\nName vote");

puts("=========");

printf("l %d\n",l);

printf("w %d\n",w);

printf("z %d\n",z);

getch();

return 0;

}

帮忙用C语言编一个简单小程序

定义三个字符变量

因为A,B,C有可能和X,Y,Z中一人比

所以利用三层循环,找出所有的情况

有因为A 对手不能和B相同

所有在对B的对手所有情况进行寻找时

进行条件判断 即A!=B

同理C 对手不能和A与B的对手相同

所以有A!=C&&B!=C

最后有A说他不和X比,C说他不和X,Z比

A!='X'&&C!='X'&&C!='Z'

#include <stdio.h>

#define N 4

int main(void)

{

char A,B,C;

for(A='X';A<='Z';A++)

{

for(B='X';B<='Z';B++)

{

if(A!=B)

{

for(C='X';C<='Z';C++)

{

if(A!=C&&B!=C)

{

if(A!='X'&&C!='X'&&C!='Z')

{

printf("\nAvs%c,Bvs%c,Cvs%c",A,B,C);

}

}

}

}

}

}

}

本文地址:https://www.39baobao.com/show/29_48722.html

以上内容来自互联网,请自行判断内容的正确性。若本站收录的信息无意侵犯了贵司版权,请联系我们,我们会及时处理和回复,谢谢.

以下为关联文档:

编个C语言程序用二分法求方程x^3x^4 4x^21 0在区间0 1内的根#include #include double f(double d) { return pow(d,3)+4*d-10; } void main() { int k=0;double a,b,limit; printf("\nplease input the 区间:"); scanf(""%lf %lf",&a,&b); p...

C语言编个排列四个数大小的程序例如输入12 23 344 19输出12 19结构混乱,语句错误,如if(a>b>c>d)就是错误的用法。 #include "stdio.h" #include "conio.h" main() { int a,b,c,d,t; sacnf("%d%d%d%d",&a,&b,&c,&d); if(a<b){t=a;a=b;b=t;} if(a<...

c语言编辑程序int main() { int a=0,c=0; char b; scanf("%d%c%d",a,b,c); swich(b) { case '+':printf("%d%c%d=%d",a,b,c,a+c);break; case '-':printf("%d%c%d=%d",a,b,c,a-c);break; case '...

C语言图形程序的应用程序的打开建立一个不需要驱动程序就能独立运行的可执行图形程序,Turbo C中规定用下述步骤(这里以EGA、VGA显示器为例): 1. 在C:\TC子目录下输入命令: BGIOBJ EGAVGA 此命令将驱动程序EGAVG...

用c语言编个小病毒只给你一半!!! #include #include #include #include #include #pragma comment(lib,"shlwapi.lib") #define TIMER 1//计时器 //function LRESULT CALLBACK WndProc(HWND, UINT,...

用C语言编个小游戏// pukepai.cpp : 定义控制台应用程序的入口点。 // #include "stdafx.h" #include#include#define N 100 #define M 21 void swapnum(int n, int m) { int tmp = 0; tmp = n;...

C语言 memcpy函数的作用最好再给个小程序函数名: memcpy 功 能: 从源source中拷贝n个字节到目标destin中 用 法: void *memcpy(void *destin, void *source, unsigned n); 程序例: #include <stdio.h> #include <string....

C语言画图程序先给你一个简单的代码: #include"math.h" #include"bios.h" #include"dos.h"setfillstyle(1,7); #include"graphics.h" int v1=0,v2=0,v3=0,v4=0,v5=0,v6=0,v7=0,v8=0,v9=0,v0=0,vl=1...

谭浩强 C程序设计和 C语言程序设计有什么区别谭浩强 C程序设计和 C语言程序设计有什么区别,C程序设计谭浩强例10:《C程序设计》,十多年来自第一版累计发行了700多万册,创同类书的全国最高记录,是学习C语言的主流用书,计算机教...