写一个简短的C语言代码

作者&投稿:谷败 (若有异议请与网页底部的电邮联系)
求写一个简单的c语言代码,要最简单的那种。谢谢~

//#include "stdafx.h"//If the vc++6.0, with this line.#include "stdio.h"int myfact(int n){ if(n==1 || n==0) return 1; else return n*myfact(n-1);}int main(void){ int N,sum; while(1){ printf("Input N(0=0 && N<=100000){ for(sum=0;N;sum+=myfact(N%10),N/=10); printf("The result is %d.
",sum); } else printf("Error, redo: "); } return 0;}

(1)
#include "stdio.h"#include "math.h"int main(int argc,char *argv[]){float m,r;int n;printf("Please input, the number of the principal and interest rates in turn.
");if(scanf("%f,%d,%f",&m,&n,&r)!=3 || m<0 || n<0 || r<0){printf("Input error, exit...
");return 0;}printf("Interest: %.0f
",m*(pow(1+r,n)-1)*.8);return 0;}运行样例:

(2)
#include "stdio.h"int main(int argc,char *argv[]){float h,r;printf("Please enter r & h(R:) in turn.
");if(scanf("%f,%f",&r,&h)!=2 || r<0 || h<0){printf("Input error, exit...
");return 0;}printf("The volume is: %.2f
",3.14/3*h*r*r);return 0;}运行样例:

最简单的C语言代就是输出“helloWord”,通常是作为初学编程语言时的第一个程序代码。具体代码如下:

#include <stdio.h>

int main(){

    printf("Hello, World!
");

    return 0;

}

扩展资料:

1、程序的第一行#include <stdio.h>是预处理器指令,告诉 C 编译器在实际编译之前要包含 stdio.h 文件。

2、下一行intmain()是主函数,程序从这里开始执行。

3、下一行printf(...)是C中另一个可用的函数,会在屏幕上显示消息"Hello,World!"。

4、下一行return0;终止main()函数,并返回值0。

参考资料来源:百度百科-c语言



#include <stdio.h>

int main()
{
double a,b,c;
scanf("%lf",&a);
scanf("%lf",&b);
c=a+b;
printf("first number:%.2lf",a);
printf("
second number%.2lf",b);
printf("
%.2lf",a);
printf("
+%.2lf",b);
printf("
-------------
");
printf(" %.2lf
",c);

return 0;
}


能不能再懒一点,刚学就偷懒了

#include<stdio.h>
#include<stdlib.h>
int main(){
double a,b;
scanf("%f %f",&a,&b);
printf("%.2f\n",a+b);
return 0;
}


写一个简短的C语言代码
最简单的C语言代就是输出“helloWord”,通常是作为初学编程语言时的第一个程序代码。具体代码如下:include <stdio.h> int main(){ printf("Hello, World! \\n");return 0;}

c语言代码
2. 主函数定义:`int main`是C程序的入口点。程序从这里开始执行。`int`表示主函数返回一个整数值,通常返回0表示程序正常结束。3. 输出语句:在`main`函数内部,`printf`函数用于输出字符串"Hello, World!"到控制台。`\\n`是一个换行符,表示输出后换行。4. 返回语句:`return 0;`表示程序执行...

给我一个C语言Hello world程序代码。
printf("Hello, world\\n"); \/\/ printf是系统输出函数,用于向控制台打印文字。getch(); \/\/ 用于获得用户输入。在此处是为了让程序暂停,便于观察执行结果。对于Helloworld的输出没有影响。Hello World解释 Hello World ,中文意思:你好,世界。世界上的第一个程序就是Hello World,由Brian Kernighan创作。

求一个简单的C语言程序 大概四十到五十行就可以了 要求有程序名字 代 ...
j,d[N],temp; float sum=0,average;if((fp=fopen("student.txt","r"))==NULL){printf("can not open this file.\\n");exit(1);}for(i=0;

请描述一下一个简单的C语言源程序代码都包括哪些?
您好,很高兴回答您的问题。在C语言中,无论是什么样程度的代码程序,都包含有以下几个方面:宏定义(或者包含的头文件,视情况而定)函数返回值类型 主函数(类型 变量){变量定义或者初始化;输入语句;计算语句;输出语句;} 函数返回值类型 函数名(类型 变量,类型 变量,。。。)(自定义...

用C语言和数据结构编写一个简单的程序(求源代码)
j] = strNum[i];newPreStr[j+1] = 0;iCnt = 0;for (j=0;j<k;j++){ if(j != i){ tmpStr[iCnt] = strNum[j];iCnt ++ ;} } tmpStr[iCnt] = 0;GetZhe(newPreStr,tmpStr);} } } int main(int argc, char* argv[]){ GetZhe("","123456");return 0;} ...

用C语言编写一个简单的图书管理小程序
include<string> include<fstream> include<stdio.h> using namespace std;const int maxb=10000; \/\/最多的图书 class book\/\/图书类 { int tag; \/\/删除标记1:已删0:未删 int number; \/\/isbn书号 char name[20]; \/\/书名 char author[10]; \/\/主编 char ...

如何用c语言编写一个计算素数的程序?
if n % i == 0:return False return True count = 0 for i in range(2, 1000):if isPrime(i):print(i, end=" ")count += 1 if count % 10 == 0:print()print("\\n共计%d个素数。" % count)程序中首先定义了一个名为isPrime的函数,用于判断一个数是否为素数。当n小于等于1时...

求C语言代码:一个笼子里有一些鸡和兔子,总共有A只脚,至少有多少只动物...
void main(){ unsigned long int a,b,c,d;printf("这是一个用于算鸡兔同笼的小程序(仅能输入整数,使用回车键切换)\\n请输入鸡兔的总数");scanf("%d",&a);printf("\\n请输入鸡兔脚的总数");scanf("%d",&b);if(b%2 != 0){ printf("输入的鸡兔脚的总数有错误!");return 0;} c...

急求一个c语言的大约80行的代码,内容不限,易理解就好(是c语言,不是c++...
1 -i); i++){c = *(s + i);*(s + i) = *(s + len -1 -i);*(s + len - 1 - i) = c;}}void arraymove(char *s, int n){int len = jstrlen(s);for(int i = len; i >= 0; i--){*(s + i + n) =*(s + i);*(s+i) = '_';}}void itoa(...

湘桥区15745697078: 求一简单C程序代码 -
穆图枢力: 写好了,你看看吧,有要求再提 #include<stdio.h> #include<conio.h> int main(){char input[50];printf("请问 1+1=");for(;;){gets(input);if(strcmp(input,"2")==0) {puts("正确");break;}printf("重新输入 1+1=");}getch(); }

湘桥区15745697078: 求一段简单的C语言代码 -
穆图枢力: #include <iostream> using namespace std; #define countof(x) sizeof(x)/sizeof(x[0]) int main() { char szText[256]; int nBytes = 0;//字节数 int nSpace = 0;//空格数 int nRow = 0;//行数 int nAbc = 0;//大小写字母数 cout<<"请输入要统计的字符串...

湘桥区15745697078: 简单的C语言程序
穆图枢力: #include "stdio.h" void compare(double a,double b,double c,double *max,double *min){ if(a>=b){ if(b>=c) *max=a,*min=c; else if(a>=c)*max=a,*min=c; else *max=c,*min=b; } else{ if(c>=b) *max=c,*min=a; else if(a>=c) *max=b,*min=c; else *max=b,...

湘桥区15745697078: 一个简单的C语言程序 -
穆图枢力: #include int main() { int num; char ch[100]; scanf("%d",&num); itoa(num,ch,2); printf("%s\n",ch); return 0; } typedef 声明,为现有类型创建一个新的名字.typedef int array[10]; 例如;array text; 语句表示text是一个整型数组有10个元素,等同...

湘桥区15745697078: 求C语言的源代码,几个很简单的程序
穆图枢力: #include "stdio.h" #include "string.h" #define MaxContent 100 void main() { char array[MaxContent]; int i; int NUM; clrscr(); printf("How many data do you want to input:"); scanf("%d",&NUM); getchar(); for(i=0;i全部

湘桥区15745697078: 求一个简单的C语言程序 -
穆图枢力: switch((int)a) { case 0: y = a*a;break; case 1: 接下来自己写吧 }

湘桥区15745697078: 一个简单的c语言程序
穆图枢力: #include<stdio.h> int main(){ int x,y,z;scanf("%d%d%d",&x,&y,&z);z=z<(y=x<y?x:y)?z:y;printf("The results is %d .\n",z);return 0;}

湘桥区15745697078: 时间紧,求帮写一个简单C语言程序 -
穆图枢力: #include <stdio.h> void show(int i) { switch(i) { case 0: printf("零"); break; case 1: printf("壹"); break; case 2: printf("贰"); break; case 3: printf("叁"); break; case 4: printf("肆"); break; case 5: printf("伍"); ...

湘桥区15745697078: 求一个简单的C语言程序!
穆图枢力: #include<stdio.h> void main () { int x,y; int sun; printf("Please input x :"); scanf ("%d",&x); printf("\nPlease input y :"); scanf ("%d",&y); sun = x + y; printf("The sun is: %d. ",sun); }

湘桥区15745697078: 关于C语言的一段简单的代码 -
穆图枢力: 这个问题其实是涉及到getchar()函数的用法.. 执行getchar()输入"一个字符"时,键入字符后需要回车,之后程序才会响应输入,继续执行后面的语句.也会将回车作为一个字符读入..这就相当于一次读取两个字符. 把程序修改下.加个统计次数的输出,你就可以明白了: 在for循环中加个printf("\n%d\n",i);

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