|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
使用gcc或g++进行编译,使用gdb进行调试;
上面这些C言语基本算法案例都是经由测试和考证过了的,接待列位利用。
本文是该系列的第一篇,都是一些绝对低级的算法,很合适刚入手下手学C言语的同砚。
1、C言语打印一条语句
源代码:- /*CProgramtoprintasentence.*/#include<stdio.h>intmain(){printf("CProgramming");/*printf()printsthecontentinsidequotation*/return0;}
复制代码 输入: 2、C言语打印用户输出的一个整数
源代码:- #include<stdio.h>intmain(){intnum;printf("Enterainteger:");scanf("%d",&num);/*Storingaintegerenteredbyuserinvariablenum*/printf("Youentered:%d",num);return0;}
复制代码 输入:- Enterainteger:25Youentered:25
复制代码 3、C言语完成两个整数相加
源代码:- /*Cprogrammingsourcecodetoaddanddisplaythesumoftwointegersenteredbyuser*/#include<stdio.h>intmain(){intnum1,num2,sum;printf("Entertwointegers:");scanf("%d%d",&num1,&num2);/*Storesthetwointegerenteredbyuserinvariablenum1andnum2*/sum=num1+num2;/*Performsadditionandstoresitinvariablesum*/printf("Sum:%d",sum);/*Displayssum*/return0;}
复制代码 输入:- Entertwointegers:1211Sum:23
复制代码 4、C言语完成两个小数相乘
源代码:- /*Cprogramtomultiplyanddisplaytheproductoftwofloatingpointnumbersenteredbyuser.*/#include<stdio.h>intmain(){floatnum1,num2,product;printf("Entertwonumbers:");scanf("%f%f",&num1,&num2);/*Storesthetwofloatingpointnumbersenteredbyuserinvariablenum1andnum2respectively*/product=num1*num2;/*Performsmultiplicationandstoresit*/printf("Product:%f",product);return0;}
复制代码 输入:- Entertwonumbers:2.41.1Product:2.640000
复制代码 5、C言语查找字符的ASCII值
源代码:- /*SourcecodetofindASCIIvalueofacharacterenteredbyuser*/#include<stdio.h>intmain(){charc;printf("Enteracharacter:");scanf("%c",&c);/*Takesacharacterfromuser*/printf("ASCIIvalueof%c=%d",c,c);return0;}
复制代码 输入:- Enteracharacter:GASCIIvalueofG=71
复制代码 6、C言语依据用户输出的整数做商和余数
源代码: 输入: 7、C言语猎取整型、单精度浮点型、双精度浮点型和字符型的长度
基础语法是: 源代码: 输入:注:大概会因为体系的分歧出来的了局也不尽不异。
8、C言语猎取关头字long的长度局限
源代码: 输入: 9、C言语互换数值
源代码: 输入: 10、C言语反省数值是奇数仍是偶数
源代码: 输入1:- #include<stdio.h>intmain(){intnum;printf("Enterainteger:");scanf("%d",&num);/*Storingaintegerenteredbyuserinvariablenum*/printf("Youentered:%d",num);return0;}0
复制代码 输入2:- #include<stdio.h>intmain(){intnum;printf("Enterainteger:");scanf("%d",&num);/*Storingaintegerenteredbyuserinvariablenum*/printf("Youentered:%d",num);return0;}1
复制代码 也能够用前提运算符办理:- #include<stdio.h>intmain(){intnum;printf("Enterainteger:");scanf("%d",&num);/*Storingaintegerenteredbyuserinvariablenum*/printf("Youentered:%d",num);return0;}2
复制代码 11、C言语反省是元音仍是子音
源代码:- #include<stdio.h>intmain(){intnum;printf("Enterainteger:");scanf("%d",&num);/*Storingaintegerenteredbyuserinvariablenum*/printf("Youentered:%d",num);return0;}3
复制代码 输入1:- #include<stdio.h>intmain(){intnum;printf("Enterainteger:");scanf("%d",&num);/*Storingaintegerenteredbyuserinvariablenum*/printf("Youentered:%d",num);return0;}4
复制代码 输入2:- #include<stdio.h>intmain(){intnum;printf("Enterainteger:");scanf("%d",&num);/*Storingaintegerenteredbyuserinvariablenum*/printf("Youentered:%d",num);return0;}5
复制代码 也能够用前提运算符办理- #include<stdio.h>intmain(){intnum;printf("Enterainteger:");scanf("%d",&num);/*Storingaintegerenteredbyuserinvariablenum*/printf("Youentered:%d",num);return0;}6
复制代码 输入了局和下面的程序不异。
12、C言语完成从三个数值中查找最年夜值
完成1:- #include<stdio.h>intmain(){intnum;printf("Enterainteger:");scanf("%d",&num);/*Storingaintegerenteredbyuserinvariablenum*/printf("Youentered:%d",num);return0;}7
复制代码 完成2:- #include<stdio.h>intmain(){intnum;printf("Enterainteger:");scanf("%d",&num);/*Storingaintegerenteredbyuserinvariablenum*/printf("Youentered:%d",num);return0;}8
复制代码 完成3:- #include<stdio.h>intmain(){intnum;printf("Enterainteger:");scanf("%d",&num);/*Storingaintegerenteredbyuserinvariablenum*/printf("Youentered:%d",num);return0;}9
复制代码 输入了局不异:- Enterainteger:25Youentered:250
复制代码 13、C言语解一元二次方程
源代码:- Enterainteger:25Youentered:251
复制代码 输入1:- Enterainteger:25Youentered:252
复制代码 输入2:- Enterainteger:25Youentered:253
复制代码 14、C言语反省是不是是闰年
源代码:- Enterainteger:25Youentered:254
复制代码 输入1:- Enterainteger:25Youentered:255
复制代码 输入2:- Enterainteger:25Youentered:256
复制代码 输入3:- Enterainteger:25Youentered:257
复制代码 15、C言语反省一个数是负数、正数仍是零
源代码:- Enterainteger:25Youentered:258
复制代码 也能够利用if-else语句- Enterainteger:25Youentered:259
复制代码 输入1:- /*Cprogrammingsourcecodetoaddanddisplaythesumoftwointegersenteredbyuser*/#include<stdio.h>intmain(){intnum1,num2,sum;printf("Entertwointegers:");scanf("%d%d",&num1,&num2);/*Storesthetwointegerenteredbyuserinvariablenum1andnum2*/sum=num1+num2;/*Performsadditionandstoresitinvariablesum*/printf("Sum:%d",sum);/*Displayssum*/return0;}0
复制代码 输入2:- /*Cprogrammingsourcecodetoaddanddisplaythesumoftwointegersenteredbyuser*/#include<stdio.h>intmain(){intnum1,num2,sum;printf("Entertwointegers:");scanf("%d%d",&num1,&num2);/*Storesthetwointegerenteredbyuserinvariablenum1andnum2*/sum=num1+num2;/*Performsadditionandstoresitinvariablesum*/printf("Sum:%d",sum);/*Displayssum*/return0;}1
复制代码 输入3:- /*Cprogrammingsourcecodetoaddanddisplaythesumoftwointegersenteredbyuser*/#include<stdio.h>intmain(){intnum1,num2,sum;printf("Entertwointegers:");scanf("%d%d",&num1,&num2);/*Storesthetwointegerenteredbyuserinvariablenum1andnum2*/sum=num1+num2;/*Performsadditionandstoresitinvariablesum*/printf("Sum:%d",sum);/*Displayssum*/return0;}2
复制代码 16、C言语反省某字符串是否是字母
源代码:- /*Cprogrammingsourcecodetoaddanddisplaythesumoftwointegersenteredbyuser*/#include<stdio.h>intmain(){intnum1,num2,sum;printf("Entertwointegers:");scanf("%d%d",&num1,&num2);/*Storesthetwointegerenteredbyuserinvariablenum1andnum2*/sum=num1+num2;/*Performsadditionandstoresitinvariablesum*/printf("Sum:%d",sum);/*Displayssum*/return0;}3
复制代码 输入1:- /*Cprogrammingsourcecodetoaddanddisplaythesumoftwointegersenteredbyuser*/#include<stdio.h>intmain(){intnum1,num2,sum;printf("Entertwointegers:");scanf("%d%d",&num1,&num2);/*Storesthetwointegerenteredbyuserinvariablenum1andnum2*/sum=num1+num2;/*Performsadditionandstoresitinvariablesum*/printf("Sum:%d",sum);/*Displayssum*/return0;}4
复制代码 输入2:- /*Cprogrammingsourcecodetoaddanddisplaythesumoftwointegersenteredbyuser*/#include<stdio.h>intmain(){intnum1,num2,sum;printf("Entertwointegers:");scanf("%d%d",&num1,&num2);/*Storesthetwointegerenteredbyuserinvariablenum1andnum2*/sum=num1+num2;/*Performsadditionandstoresitinvariablesum*/printf("Sum:%d",sum);/*Displayssum*/return0;}5
复制代码 17、C言语盘算天然数的和
源代码:- /*Cprogrammingsourcecodetoaddanddisplaythesumoftwointegersenteredbyuser*/#include<stdio.h>intmain(){intnum1,num2,sum;printf("Entertwointegers:");scanf("%d%d",&num1,&num2);/*Storesthetwointegerenteredbyuserinvariablenum1andnum2*/sum=num1+num2;/*Performsadditionandstoresitinvariablesum*/printf("Sum:%d",sum);/*Displayssum*/return0;}6
复制代码 也能够利用for轮回语句- /*Cprogrammingsourcecodetoaddanddisplaythesumoftwointegersenteredbyuser*/#include<stdio.h>intmain(){intnum1,num2,sum;printf("Entertwointegers:");scanf("%d%d",&num1,&num2);/*Storesthetwointegerenteredbyuserinvariablenum1andnum2*/sum=num1+num2;/*Performsadditionandstoresitinvariablesum*/printf("Sum:%d",sum);/*Displayssum*/return0;}7
复制代码 输入:- /*Cprogrammingsourcecodetoaddanddisplaythesumoftwointegersenteredbyuser*/#include<stdio.h>intmain(){intnum1,num2,sum;printf("Entertwointegers:");scanf("%d%d",&num1,&num2);/*Storesthetwointegerenteredbyuserinvariablenum1andnum2*/sum=num1+num2;/*Performsadditionandstoresitinvariablesum*/printf("Sum:%d",sum);/*Displayssum*/return0;}8
复制代码 也能够经由过程if-else语句- /*Cprogrammingsourcecodetoaddanddisplaythesumoftwointegersenteredbyuser*/#include<stdio.h>intmain(){intnum1,num2,sum;printf("Entertwointegers:");scanf("%d%d",&num1,&num2);/*Storesthetwointegerenteredbyuserinvariablenum1andnum2*/sum=num1+num2;/*Performsadditionandstoresitinvariablesum*/printf("Sum:%d",sum);/*Displayssum*/return0;}9
复制代码 18、C言语盘算阶乘
关于恣意负数n,阶乘指的是:- Entertwointegers:1211Sum:230
复制代码 假如数值是正数,那末阶乘就不存在。而且我们划定,0的阶乘就是1。
源代码:- Entertwointegers:1211Sum:231
复制代码 输入1:- Entertwointegers:1211Sum:232
复制代码 输入2:- Entertwointegers:1211Sum:233
复制代码 先先容到这里,下一篇将分享更多的C言语基本算法,敬请等候。
英文原文:CProgrammingExamplesvia:codeceo
但不会命令而成为高手也是不可能的.这就好比学英语,什么语法都不懂,只捧着单词手册背单词是学不会英语的,但是没有单词词汇量英语水平也提不高的。 |
|