繁體
|
簡體
Sclub交友聊天~加入聊天室當版主
(檢舉)
分享
新浪微博
QQ空间
人人网
腾讯微博
Facebook
Google+
Plurk
Twitter
Line
標題:
c++練習題6
[打印本頁]
作者:
Smallcat
時間:
2018-10-24 15:21
標題:
c++練習題6
下載
(129.8 KB)
2018-10-24 15:21
#include<stdio.h>
int main(void){
double x=0,y1,y2=10,pro,sum=0;
//a:Trapezoidal Rule
while(x<=10){
x = x+0.1;
y1 = 8*x*x*x+3*x*x+6*x+10;
pro = 0.05*(y1+y2);
sum += pro;
y2 = y1;
}
printf("a area: %lf",sum);
//b:rectangular rule
sum = 0;
x = 0;
while(x<10){
y1 = 8*x*x*x+3*x*x+6*x+10;
pro = 0.1*y1;
sum += pro;
x = x+0.1;
}
printf("\nb area: %lf",sum);
//final
}
複製代碼
圖片附件:
1540365603450.jpg
(2018-10-24 15:21, 129.8 KB) / 下載次數 405
http://smallcat.utmall.com/attachment.php?aid=451&k=293f18f68bfd76bac4b6d9dcb7078c86&t=1752873474&sid=10CfjX
作者:
Smallcat
時間:
2018-10-24 15:22
下載
(55.58 KB)
2018-10-24 15:22
#include<stdio.h>
int main(void){
int a,b,c,temp;
printf("輸入數字1: ");
scanf(" %d",&a);
printf("輸入數字2: ");
scanf(" %d",&b);
printf("輸入數字3: ");
scanf(" %d",&c);
if(a>b){
temp = a;
a = b;
b = temp;
}
if(a>c){
temp = a;
a = c;
c = temp;
}
if(b>c){
temp = b;
b = c;
c = temp;
}
printf("\n由小到大result: %d %d %d",a,b,c);
}
複製代碼
圖片附件:
1540365610696.jpg
(2018-10-24 15:22, 55.58 KB) / 下載次數 444
http://smallcat.utmall.com/attachment.php?aid=452&k=005d66c726986d5a64204d4861ceb9e8&t=1752873474&sid=10CfjX
作者:
Smallcat
時間:
2018-10-24 15:22
下載
(136.53 KB)
2018-10-24 15:22
#include<stdio.h>
int main(void){
int e=1,x,y;
int signx,signy;
while(e>0){
printf("輸入x: ");
scanf(" %d",&x);
printf("輸入y: ");
scanf(" %d",&y);
if(x==0){
signx = 0;
}
if(y==0){
signy = 0;
}
if(x>0){
signx = 1;
}
if(y>0){
signy = 1;
}
if(x<0){
signx = -1;
}
if(y<0){
signy = -1;
}
if(signx==0&&signy==0)
printf("(%d,%d) is the origin\n",x,y);
if(signx!=0&&signy==0)
printf("(%d,%d) is on the x-axis\n",x,y);
if(signx==0&&signy!=0)
printf("(%d,%d) is on the y-axis\n",x,y);
if(signx==1&&signy==1)
printf("(%d,%d) is in the first quadrant\n",x,y);
if(signx==-1&&signy==1)
printf("(%d,%d) is in the second quadrant\n",x,y);
if(signx==-1&&signy==-1)
printf("(%d,%d) is in the third quadrant\n",x,y);
if(signx==1&&signy==-1)
printf("(%d,%d) is in the fourth quadrant\n",x,y);
}
}
複製代碼
圖片附件:
1540365618667.jpg
(2018-10-24 15:22, 136.53 KB) / 下載次數 414
http://smallcat.utmall.com/attachment.php?aid=453&k=1c819798879547b0ddaf5412248f3179&t=1752873474&sid=10CfjX
作者:
Smallcat
時間:
2018-10-24 15:23
下載
(147.73 KB)
2018-10-24 15:23
#include<stdio.h>
int main(void){
int a,b;
char ope;
while(1){
printf("輸入第一個數字: ");
scanf(" %d",&a);
printf("輸入第二個數字: ");
scanf(" %d",&b);
printf("輸入運算符號: ");
scanf(" %c",&ope);
switch(ope){
case '+':
printf("%d %c %d = %d\n",a,ope,b,a+b);
break;
case '-':
printf("%d %c %d = %d\n",a,ope,b,a-b);
break;
case '*':
printf("%d %c %d = %d\n",a,ope,b,a*b);
break;
case '/':
if(b!=0){
printf("%d %c %d = %d\n",a,ope,b,a/b);
}else{
printf("denominator can not be zero\n");
}
break;
default:
printf("try again\n");
}
}
}
複製代碼
圖片附件:
1540365626702.jpg
(2018-10-24 15:23, 147.73 KB) / 下載次數 432
http://smallcat.utmall.com/attachment.php?aid=454&k=0387ce52ccaa78844cb8d6315ab8af35&t=1752873474&sid=10CfjX
作者:
Smallcat
時間:
2018-10-24 15:24
下載
(208.56 KB)
2018-10-24 15:23
#include<stdio.h>
int main(void){
int i,n,ope,prime,e=1;
while(e){
printf("--------Meun--------\n");
printf("1:Factorial of a number\n");
printf("2:Prime or not\n");
printf("3:Odd or even\n");
printf("4:Exit\n");
printf("輸入指令: ");
scanf(" %d",&ope);
switch(ope){
case 1:
printf("\n輸入數字: ");
scanf(" %d",&n);
i=1;
while(i<=n){
if(n%i==0){
printf(" %d",i);
}
i++;
}
printf("\n");
break;
case 2:
prime = 1;
printf("\n輸入數字: ");
scanf(" %d",&n);
i=2;
while(i*i<=n&&prime){
if(n%i==0){
printf("\n%d is not prime\n",n);
prime = 0;
}
i++;
}
if(prime==1){
printf("\n%d is prime\n",n);
}
break;
case 3:
printf("\n輸入數字: ");
scanf(" %d",&n);
if(n&1){
printf("\n%d is odd\n",n);
}else{
printf("\n%d is even\n",n);
}
break;
case 4:
printf("\n程式結束");
e = 0;
break;
}
}
}
複製代碼
圖片附件:
1540365635817.jpg
(2018-10-24 15:23, 208.56 KB) / 下載次數 438
http://smallcat.utmall.com/attachment.php?aid=455&k=51b8672dea1caf75787494eb43b58e5f&t=1752873474&sid=10CfjX
歡迎光臨 小貓貓大聯盟!幻與想的境界\(0w0)/ (http://smallcat.utmall.com/)
Powered by Discuz! 7.2