C语言程序设计第4讲.ppt

  1. 1、本文档共25页,可阅读全部内容。
  2. 2、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
  3. 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载
  4. 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
C语言程序设计第4讲

3、只需保留.cpp文件。;float f=2.3; cout<<setw(5)<<f;;举 例;#include <iostream.h> int main( ) { int a, b, x, y; cout<<"Input a, b:\n"; cin>>a>>b; x=(4*a-b)/2; y=(b-2*a)/2; cout<<"x="<<x<<", y="<<y; return 0; };#include <stdio.h> int main( ) { int a, b, x, y; printf("Input a b:\n"); scanf("%d%d", &a, &b); x=(b-2*a)/2; y=(4*a-b)/2; printf("x=%d,y=%d", x, y); return 0; };选择结构;条件;关系表达式;逻辑表达式;逻辑表达式;逻辑表达式;例1:输入一个数,若能被3整除,计算该数的立方, 并打印yes,否则,计算该数的平方,并打印no。 ;举 例;开始 ;cout<<"x1="<<-b/t<<"+"<<sqrt(-d)/t<<"i"<<endl; ;#include <iostream.h> #include <math.h> void main( ) { float a, b, c, d, t, x1, x2; cin>>a>>b>>c; d=b*b-4*a*c; t=2*a; if(d>=0) { x1=(-b+sqrt(d))/t; x2=(-b-sqrt(d))/t; cout<<"x1="<<x1<<endl<<"x2="<<x2<<endl; } else { cout<<"x1="<<-b/t<<"+"<<sqrt(-d)/t<<"i"<<endl; cout<<"x2="<<-b/t<<"-"<<sqrt(-d)/t<<"i"<<endl; } };#include <iostream.h> int main( ) { int a, b, x, y; cout<<"Input a, b:\n"; cin>>a>>b; x=(4*a-b)/2; y=(b-2*a)/2; cout<<"x="<<x<<", y="<<y; return 0; };#include <iostream.h> int main( ) { int a, b, x, y; cout<<"Input a, b:\n"; cin>>a>>b; if((4*a-b>0)&&(b-2*a>0)) { x=(4*a-b)/2; y=(b-2*a)/2; cout<<"x="<<x<<", y="<<y; } else { cout<<"Input error!"<<endl; } return 0; };if 语句的灵活使用;省略else的if语句;作 业;上机二;测 试 平 台;int main( ) { …… return 0; }

文档评论(0)

shaoye348 + 关注
实名认证
内容提供者

该用户很懒,什么也没介绍

1亿VIP精品文档

相关文档