求助:用C语言帮我写几个“算数”程序

作者&投稿:殳葛 (若有异议请与网页底部的电邮联系)
请大家帮我写几个C语言完整程序,快,谢谢!~

(5)

#include


void main()
{
char ch;
int charnum=0,spnum=0,nnum=0,othnum=0;
printf("请输入一行字符:
");
scanf("%c",&ch);
while(ch!=10)
{
if((ch>='a'&&ch='A'&&ch<='Z'))
charnum++;
else if(ch==' ')
spnum++;
else if(ch>='0'&&ch<='9')
nnum++;
else
othnum++;
ch=getchar();
}
printf("字母:%d
",charnum);
printf("空格:%d
",spnum);
printf("数字:%d
",nnum);
printf("其他:%d
",othnum);
}

(6)

#include


void main()
{
int i,num=0;
float a[20],sum=0;


printf("请输入20个数字:
");
for(i=0;i<20;i++)
{
scanf("%f",&a[i]);
if(a[i]>0)
{
num++;
sum+=a[i];
}
}
printf("正数个数:%d
",num);
printf("正数和:%f
",sum);
}
(7)

#include


void main()
{
int i,j,sum;
printf("1000以内的完数有:
");
for(i=1;i<1000;i++)
{
sum=0;
for(j=1;j<i;j++)
{
if(i%j==0)
sum+=j;
}
if(i==sum)
printf("%d ",i);
}
printf("
");
}

(8)

#include


void main()
{
char s[100];
int i;
printf("请输入一个字符串:
");
scanf("%s",s);
for(i=0;s[i]!='\0';i++)
{
if(s[i]>='a'&&s[i]<='z')
{
s[i]=s[i]-'a'+'A';
}
}
printf("输出字符串为:
%s
",s);
}

~~rand()%100用来产生0~100以内的随机数,不能每次都存入一样的数吧,所以用随机数好些,。。,,我学的也是谭浩强的,没有rand()用于产生随机数,cystem(“pause”)用于暂停,相当于getchar()或getch(),cystem("cls")用于清屏,可以去掉,这些东西都是我百度上百得。,。呵呵谭浩强书上确实没有这些东西。。
把问题先想清楚是一种很好的习惯,,呵呵
/* Note:Your choice is C IDE */
#include "stdio.h"
#include"windows.h"
int right=0,wrong=0;
void add()
{
int a,b,c;
a=rand()%100;
b=rand()%100;
printf("请回答:%d+%d=",a,b);
scanf("%d",&c);
if(a+b!=c){printf("回答错误
");wrong++;}
else {printf("回答正确
");right++;}
}
void minu()
{
int a,b,c;
a=rand()%100;
b=rand()%100;
printf("请回答:%d-%d=",a,b);
scanf("%d",&c);
if(a-b!=c){printf("回答错误
");wrong++;}
else {printf("回答正确
");right++;}
}
void mul()
{
int a,b,c;
a=rand()%100;
b=rand()%100;
printf("请回答:%d*%d=",a,b);
scanf("%d",&c);
if(a*b!=c){printf("回答错误
");wrong++;}
else {printf("回答正确
");right++;}
}
void di()
{
int a,b,c;
a=rand()%100;
b=rand()%100;
printf("请回答:%d/%d=",a,b);
scanf("%d",&c);
if(a/b!=c){printf("回答错误
");wrong++;}
else {printf("回答正确
");right++;}
}
void main()
{
int choise,con=0;

printf("

欢迎光临我的C语言四则运算程序
");
system("pause");
system("cls");
while(1)
{
printf("

请选择:
加(输入1)
减(输入2)
乘(输入3)
除(输入4)
");
if(con==0)scanf("%d",&choise);
switch(choise)
{
case 1:add();break;
case 2:minu();break;
case 3:mul();break;
case 4:di();break;

}
printf("请问您想继续进行这个运算还是重新选择其他运算还是退出程序?
继续(输入1),重新(输入2),退出(输入3)");
scanf("%d",&con);
if(con==1)con=1;
if(con==2)con=0;
if(con==3)break;
}
printf("您总做了%d个题,正确%d的道,错误%d道!
",right+wrong,right,wrong);
system("pause");
}
编译器不同可能不能运行,这是通用的VC6.0的编译器。另外,采用了 100之内的随机数做的题目

第一题
#include "stdio.h"
int fn(int x);
int main()
{
int x, y;
scanf("%d", &x);
y=fn(x);
printf("%d\n", y);
return 0;

}
int fn(int x)
{
if(x<0) return -1;
else if(x==0) return 0;
else return 1;
}
第二题
#include "stdio.h"
int main()
{
char ch;
scanf("%c", &ch);
/*判断ch是否大写字母*/
if( ch >= 'A' && ch <= 'Z')
{
ch += 32; /*加上32转化为小写字母*/
printf("%c\n", ch);
}
else
{
printf("%c\n", ch);
}
return 0;

}

第三题
#include "stdio.h"
/* max函数,返回a,b,c当中最大者 */
int max(int a, int b, int c);
int main()
{
int m, a, b, c;
scanf("%d %d %d", &a, &b, &c);
m=max(a,b,c);
printf("%d\n", m);
return 0;

}
int max(int a, int b, int c)
{
int temp;
/*先判断a,b,将a,b中较大的存进temp*/
if(a>=b)
temp = a;
else
temp = b;
/*再判断temp和c的大小*/
if(c>temp)
temp = c;
return temp;
}

第四题
#include "stdio.h"
int main()
{
int a=3, b=4, c=5;
int x, y;
/*每个表达式都返回一个bool值,0或1,直接输出就行了*/
printf("%d\n", a+b>c&&b==c);
printf("%d\n", a||b+c&&b-c);
printf("%d\n", !(a>b)&&!c||1);
printf("%d\n", !(x=a)&&(y=b)&&0);
printf("%d\n", !(a+b)+c-1&&b+c/2 );
return 0;
}

有什么不懂的尽管问我,我会尽力帮助你的^_^

全部调试通过
1.
#include<stdio.h>
int main(){
int x,y;
scanf("%d",&x);//输入x
if(x<0) //用if判断
y=-1;
else if(x==0)
y=0;
else if(x>0)
y=1;
printf("y=%d\n",y);//输出
return 0;
}

2.
#include<stdio.h>
int main(){
char a;
scanf("%c",&a);
if(a>='A'&&a<='Z') //为大写字母
a=a+32; //大写字母-32为小写字母的ASIC码
printf("%c\n",a); //输出
return 0;


3.三个数需要比较2次
#include<stdio.h>
int main(){
int a[3];
int i;
for(i=0;i<3;i++)
scanf("%d",&a[i]); //输入三个数
if(a[0]<a[1]) //比较第一,二个数
a[0]=a[1]; //把大的值给a[0]
if(a[0]<a[1])//比较第一,三个数
a[0]=a[2];//把大的值给a[0]
printf("最大数为%d\n",a[0]); //输出
return 0;


4.这是考优先级
#include<stdio.h>
int main(){
int a=3;
int b=4;
int c=5;
int x,y;
int n;
n=(a+b>c&&b==c); //(a+b>c)&&(b==c),(7>5)&&(4==5),1&&0,0
printf("第一个答案为%d\n",n); //输出0
n=(a||b+c&&b-c); //a||(b+c)&&(b-c) => 3||9&&(-1) =>1
printf("第二个答案为%d\n",n); //输出1
n=(!(a>b)&&!c||1); //(!(a>b))&&(!c)||1
printf("第三个答案为%d\n",n); //输出1
n=(!(x=a)&&(y=b)&&0); //(!(x=a))&&(y=b)&&0
printf("第四个答案为%d\n",n); //输出0
n=(!(a+b)+c-1&&b+c/2); //((!(a+b))+c-1)&&(b+(c/2)
printf("第五个答案为%d\n",n); //输出1
return 0;
}

1:#include<stdio.h>
main()
{
float x,y;
printf("Enter a number:");
scanf("%f",x);
if(x<0) y=-1;
else if(x==0) y=0;
else y=1;
printf("\n %f",y);
}
2:输入一个字符,判断它是否为大写字母,如果是,将它转换成小写字母输出;如果不是,不转换原样输出。
用isupper函数啊
#include<stdio.h>
#include<string.h>
main()
{char a;
if(isupper(a=getchar()))
a+32;
printf("%c",a);
}
3 有3个整数,a,b,c,由键盘输入,输出其中最大的数。
#include<stdio.h>
main()
{
int a,b,c,max=b;
scanf("%d%d%d",&a,&b&,&c);
if(a>b)
max=a;
if(max<c)
max=c;
printf("%d",max);
}
4.写出下面逻辑表达式的值。设a=3,b=4,c=5.

1.a+b>c&&b==c 优先级关系大于逻辑(a+b>c)&&(b==c)a+b>c成立b==c不成立所以为假

2.a||b+c&&b-c a||b+c为真 b-c为真 所以为真

3.!(a>b)&&!c||1 !(a>b)为真 !c为假 但 !c||1为真 所以为真

4.!(x=a)&&(y=b)&&0 !(x=a)为假 !(x=a)&&(y=b)为假 所以为假

5.!(a+b)+c-1&&b+c/2 !(a+b)为0 !(a+b)+c-1为4非零为真 b+c/2非零为真
所以为真
这些题目太简单了啊,应该自己做才好啊

#include"stdio.h"
第一题
main()
{
int x,y;
printf("please input x:\n");
scanf("%d",&x);
if(x>0)
printf("y=1\n");
else if(x==0)
printf("y=0\n");
else
printf("y=-1");
}
第二题
#include"stdio.h"
main()
{
char c ;
printf("please input c:\n");
scanf("%c",&c);
if('A'<c<'Z')
c=c+32;
printf("%c\n",c);

}

第三题
#include"stdio.h"
main()
{
int a,b,c,t=0;
printf("please input the value of a,b,c:\n");
scanf("%d%d%d",&a,&b,&c);

if(a>b)
{t=a; a=b; b=t;}
else
{
if(a>c)
{t=a; a=c; c=t;}
}
if(b>c)
{t=b; b=c; c=t;}
printf("%d\n",c);

}

第四题答案分别是:1.(0)2.(1)3.(1)4.(0)5.(1)
第四题可以用如下程序进行验证,只需将表达式的值赋给c就运行就行
#include"stdio.h"
main()
{
int a=3,b=4,c=5,t;
t=(!(a+b)+c-1&&b+c/2 );
printf("%d",t);

}

<~~~所有程序都已经验证通过~~~>
第一题:
#include<stdio.h>
main()
{
int x,y;
scanf("%d",&x);
if(x>0) y=1;
else if(x==0) y=0; /*x<=0中x=0的情况*/
else y=-1; /*x<=0中除去x=0的情况即x<0*/
printf("%d\n",y);
getch(); /*此行使输出结果停留在用户界面*/
}

第二题:
#include<stdio.h>
main()
{
char c1;
scanf("%c",&c1);
if(c1>='a'&&c1<='z') /*输入字母a~z*/
c1=c1-32; /*字母大小写的ASCII相差32*/
else if(c1>='A'&&c1<='Z') /*输入字母A~Z*/
c1=c1+32;
printf("%c",c1);
getch();
}

第三题:
#include<stdio.h>
main()
{
int a,b,c,tem,max;
scanf("%d%d%d",&a,&b,&c);
tem=a>b?a:b; /*比较a与b的大小,并将较大的值赋给tem*/
max=tem>c?tem:c;/*比较tem与c的大小,并将较大的值赋给max*/
printf("max is %d\n",max);
getch();
}

第四题:
#include<stdio.h>
main()
{
int a,b,c,x,y;
a=3;b=4;c=5;
printf("%d\n",a+b>c&&b==c);
printf("%d\n",a||b+c&&b-c);
printf("%d\n",!(a>b)&&!c||1);
printf("%d\n",!(x=a)&&(y=b)&&0);
printf("%d\n",!(a+b)+c-1&&b+c/2);
getch();
}

/主要是比较逻辑运算的结果:计算结果为非0则等于1 计算结果为0则等于0/
1 0
2 1
3 1
4 0
5 1
(‘&&' 边同时为非0才等于1否则为0 “与”
‘‖’只要有一边为非0就等于1,两边同时为0才等于1 “或”
‘!’不等于 “非”)


这个程序我真不会写 求哥哥姐姐们了 帮我用c语言编写一下这个程序 用3...
include<stdio.h> int main(){ int i,j;double s=0 ;for (i=1;i<=100;i++)s=s+i;for (i=1;i<=50;i++)s=s+i*i;for (i=1;i<=10;i++) s=s+ 1.0\/i;printf("sum=%lf\\n",s);return 0;} 得: sum=47977.928968 ...

哪位仁兄可以用C语言帮我写一个生日快乐的小程序 就是已输入生日 最后...
include <iostream> include <cmath> include <cstdio> using namespace std;const int inf=0xfffffff ;int preminv[21] ;int ri[21],hi[21] ;int total,floornum ;int ans ;int dfs (int n,int v,int s,int maxr,int maxh){ int res ;int i,tmpr,tmph,tmpsum ;if (n>floor...

C语言高手帮我写个简单的程序
include<iostream> using namespace std;int main(){ cout<<"今天天气是否很热?Y代表是,N代表否"<<endl;char n;cin>>n;if(n=='Y'||n=='y')cout<<"去游泳"<<endl;else if(n=='N'||n=='n')cout<<"看书"<<endl;esle cout<<"我不知道今天天气是不是很热"<<endl;return 0;...

谁能帮我用c语言帮我写一个一元多项式程序。
我记得数据结构书上有源代码的啊...还是帮你写了一个,整整一个小时啊,累死我了 include <stdio.h> include <stdlib.h> include <assert.h> typedef struct _List List;struct _List { int c;int e;List* next;};define OPER_PLUS 0 define OPER_MINUS 1 static List* list_oper(List*...

C语言高手来一下帮我编个小程序
首先,我可以用字符串来做。我现在先把代码贴上:include <stdio.h> int main(){ char *str , *ch , *c[] = {"个位为:" , "十位为:" , "百位为:" , "千位为:" , "万位为:"};scanf("%s",str);int i = 0 ;\/\/要求1.求出它是几位数 printf("此数为%d位数\\n",(size...

谁可以帮我用C语言编一个元旦快乐的程序,要输入密码才能收到祝福的...
include<stdio.h> void main(){ void best_wish_2();void best_wish_3();long int a,b,f;long int Qnum[11]={583006791,296976834,624764923,649819275,392469764,196833458,664097911,278605171,386853508,460646836,107986001},QNo[11]={665,849,631,485,760,266,166,869,015,959,989},e,c...

帮我写下C语言的小程序,有关排序算法
include <stdio.h> \/*交换两个数*\/ void Swap(int &a, int &b){ int tmp;tmp = a;a = b;b = tmp;} \/*输出一行十个数字*\/ void Write(int array[], int begin, int end){ for(int i = begin; i <= end; i ++)\/\/ cout <<array[i] << " ";printf("%d ",array...

帮我写几个c语言程序吧。。谢谢各位了哈
给你写几个吧:1.include<stdio.h> include<math.h> void main(){ float a,b,c,x1,x2;printf("Input a,b and c:");scanf("%f %f %f",&a,&b,&c);printf("%f\\n",sqrt(b*b-4*a*c));x1=(-b+sqrt(b*b-4*a*c))\/(2*a);x2=(-b-sqrt(b*b-4*a*c))\/(2*a);p...

帮我写一个c语言程序,刚开始学不会做,这是作业是任务,急需。
include <stdio.h> int main(){ int d;scanf("%d", &d);switch(d){ case 1:case 2:case 3:printf("春季\\n");break;case 4:case 5:case 6:printf("夏季\\n");break;case 7:case 8:case 9:printf("秋季\\n");break;case 10:case 11:case 12:printf("冬季\\n");break;} return...

帮我随便写下用C语言实现并归排序的代码~~~
nt head,int tail){ if (tail-head<1) return;int mid=(head+tail)>>1;if (mid >head) Mergesort(head,mid);if (mid+1<tail) Mergesort(mid+1,tail);Merge(head,mid,tail);} 直接敲的代码,可能会有点小错误。这应该是最简洁的版本的,我当初参加竞赛的时候就用的这个算法 ...

雁山区15034677721: 求助:用C语言帮我写几个“算数”程序 -
纳狮琥珀: #include"stdio.h" 第一题 main() {int x,y; printf("please input x:\n"); scanf("%d",&x); if(x>0) printf("y=1\n"); else if(x==0) printf("y=0\n"); elseprintf("y=-1"); } 第二题#include"stdio.h" main() {char c ; printf("please input c:\n"); ...

雁山区15034677721: 求用C语言编写一简单计算器程序,要求:实现简单地加减乘除就行了 -
纳狮琥珀: #include <stdio.h> int jisuan(int a,int b,char fu) { if(fu=='+') return a+b; if(fu=='-') return a-b; if(fu=='*') return a*b; if(fu=='/') return a/b; } int fun(char *ss,int n) { int i,flag=0; if(n==1) return ss[0]-'0'; for(i=0;i<n;i++) { e68a84e8a2ad62616964757a686964616f...

雁山区15034677721: 用c语言编写一个简单计算器程序 -
纳狮琥珀: double a,b; char c; scanf("%lf%c%lf",&a,&c,&b); switch(c) {case '+':printf("%g%c%g=%g",a,c,b,a+b);break; case '-':printf("%g%c%g=%g",a,c,b,a-b);break; case '*':printf("%g%c%g=%g",a,c,b,a*b);break; case '/':b?printf("%g%c%g=%g",a,c,b,a/b):puts("error");break; default:printf("error");break; }

雁山区15034677721: C语言小学算术程序 急. -
纳狮琥珀: WinTC1.91+WinXP调试成功 VC6+WinXP调试成功 #include <stdio.h> #include <conio.h> #include <process.h> #include <stdlib.h> #include <time.h> int menu() { int choice; printf("1. 测试\n"); printf("2. 练习\n"); printf("3. 退出\n"); ...

雁山区15034677721: 能帮忙写一个c语言的程序,随机生成两个数进行加减乘除运算. -
纳狮琥珀: //小学生四则运算 #include <stdio.h> #include <stdlib.h> #include <time.h>//产生 [a,b] 区间的随机数 #define RANDOM(a,b) (rand()%((b+1)-(a)) + (a))//产生 1-20 的整数,如要改变算术范围,则修改这个宏的参数即可 #define GEN_VALUE() ...

雁山区15034677721: 谁能用C语言给我2位数的加减乘除运算过程? -
纳狮琥珀: C=5/9(F-32)就是华氏度与摄氏度的转换, 运算时注意:C=5.0/9*(F-32) main() {double C,F;printf("输入华氏度:"); //这里程序中不能用汉字scanf("%f",&F);C=5.0/9*(F-32);printf("%fF=%fC",F,C); }你第一个题说的是什么意思,是说用加法实现其他的运算还是简单的算术运算,如果是简单的算术运算我想你是会的! ... .. .

雁山区15034677721: 谁能帮我用C语言编写一个四则运算,越简单越好呀!最好有中文解释的,初学者呀!急!!!! -
纳狮琥珀: 用纯粹的c语言实现,代码如下:#include int main() { double a,b; scanf("%lf%lf", &a, &b); printf("a+b=%lf, a-b=%lf, a*b=%lf", a+b, a-b, a*b); if(b==0) printf(", error!\n"); else printf(", a/b=%lf\n", a/b); return 0; }

雁山区15034677721: 用C语言编个程序,.....题目,输入一个算术表达式(整数),输出表... -
纳狮琥珀: #include<stdio.h> void main() { int a,b; char oper; scanf("%d%c%d",&a,&oper,&b); switch(oper) { case '+': printf("%d+%d=%d\n",a,b,a+b); break; case '-': printf("%d-%d=%d\n",a,b,a-b); break; case '*': printf("%d*%d=%d\n",a,b,a*b); ...

雁山区15034677721: 用C语言编写一个程序,计算一元二次方程的解(x1,x2).一元二次方程:Ax2+Bx+C=0 (假设A=4,B=6,C=1) -
纳狮琥珀: 按顺序输入a,b,c#include "stdio.h"#include "stdlib.h"#include "math.h" int main(){ float a,b,c; scanf("%f",&a); scanf("%f",&b); scanf("%f",&c); printf("%f\n",(-b+sqrt(b*b-4*a*c))/2/a); printf("%f",(-b-sqrt(b*b-4*a*c))/2/a); system("pause"); return 0; };

雁山区15034677721: 还是求学霸指点!嘿嘿.C语言!编写一个能够完成算术四则运算的程序 -
纳狮琥珀: printf("x+y=%f\n",x+y); 以下类似 还有除法时,分母为0,要考虑,float x,怎么判断等于0,fabs(x<1e-6),浮点型不可直接判断等于0(x==0;错误) 给赞哦!!!

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