繁體
|
簡體
Sclub交友聊天~加入聊天室當版主
(檢舉)
分享
新浪微博
QQ空间
人人网
腾讯微博
Facebook
Google+
Plurk
Twitter
Line
加入幻想
登錄
論壇
搜索
应用程序
幫助
導航
默認風格
greenwall
uchome
jeans
私人消息 (0)
公共消息 (0)
論壇任務 (0)
系統消息 (0)
好友消息 (0)
帖子消息 (0)
应用通知 (0)
应用邀请 (0)
小貓貓大聯盟!幻與想的境界\(0w0)/
»
真的聊天
» c++練習題8
返回列表
發帖
發短消息
加為好友
Smallcat
(小貓丿)
當前離線
cutecat
UID
1
帖子
652
精華
10
積分
207113
閱讀權限
200
在線時間
215 小時
註冊時間
2013-2-8
最後登錄
2026-2-3
貓op
1
#
跳轉到
»
倒序看帖
打印
字體大小:
t
T
Smallcat
發表於 2018-11-14 16:15
|
只看該作者
c++練習題8
下載
(99.9 KB)
2018-11-14 16:14
#include<stdio.h>
int IsPrime(int x){
if(x==1){
return 0;
}
for(int i=2;i*i<=x;i++){
if(x%i==0){
return 0;
}
}
return 1;
}
int main(void){
int x;
printf("輸入數字: ");
scanf("%d",&x);
printf("%d",IsPrime(x));
}
複製代碼
#include<stdio.h>
int EvalPoly(int a,int b,int c,int x){
int pro;
pro = a*x*x+b*x+c;
return pro;
}
int main(void){
int a,b,c,x;
printf("輸入a、b、c、x: ");
scanf("%d %d %d %d",&a,&b,&c,&x);
printf("%d",EvalPoly(a,b,c,x));
}
複製代碼
收藏
分享
分享到:
QQ空间
腾讯微博
腾讯朋友
小貓貓2026了喔!
(點一下內洽傳送到小貓貓2026大事記,
如果看不到請通知我
)
發短消息
加為好友
Smallcat
(小貓丿)
當前離線
cutecat
UID
1
帖子
652
精華
10
積分
207113
閱讀權限
200
在線時間
215 小時
註冊時間
2013-2-8
最後登錄
2026-2-3
貓op
2
#
Smallcat
發表於 2018-11-14 16:16
|
只看該作者
下載
(174.21 KB)
2018-11-14 16:16
#include<stdio.h>
double Round(double x,double n){
double a;
int b;
a = x;
for(int i=1;i<=n;i++){
a *= 10;
}
b = int(a+0.5);
a = b;
for(int i=1;i<=n;i++){
a /= 10;
}
return a;
}
int main(void){
double x,n;
printf("輸入數字和有效位數: ");
scanf("%lf %lf",&x,&n);
printf("%lf",Round(x,n));
}
複製代碼
小貓貓2026了喔!
(點一下內洽傳送到小貓貓2026大事記,
如果看不到請通知我
)
TOP
發短消息
加為好友
Smallcat
(小貓丿)
當前離線
cutecat
UID
1
帖子
652
精華
10
積分
207113
閱讀權限
200
在線時間
215 小時
註冊時間
2013-2-8
最後登錄
2026-2-3
貓op
3
#
Smallcat
發表於 2018-11-14 16:17
|
只看該作者
好吧我不確定題目的意思。
下載
(393.27 KB)
2018-11-14 16:16
#include<stdio.h>
int force(double volt){
if(volt>0.2){
return 2;
}
else if(volt<-0.2){
return -1;
}else{
return 0;
}
}
int main(void){
double pos,volt;
printf("輸入初始位置: ");
scanf("%lf",&pos);
while(scanf("%lf",&volt)){
pos += force(volt);
}
printf("\n最終位置: %lf",pos);
}
複製代碼
小貓貓2026了喔!
(點一下內洽傳送到小貓貓2026大事記,
如果看不到請通知我
)
TOP
發短消息
加為好友
Smallcat
(小貓丿)
當前離線
cutecat
UID
1
帖子
652
精華
10
積分
207113
閱讀權限
200
在線時間
215 小時
註冊時間
2013-2-8
最後登錄
2026-2-3
貓op
4
#
Smallcat
發表於 2018-11-14 16:18
|
只看該作者
下載
(279.88 KB)
2018-11-14 16:18
成果圖:
下載
(81.6 KB)
2018-11-14 16:18
下載
(86.66 KB)
2018-11-14 16:19
#include<stdio.h>
int firstday(int x){
int a;
a = (x + (x-1)/4 - (x-1)/100 + (x-1)/400) % 7;
return a;
}
int leapyear(int x){
if(x%400==0){
return 1;
}
if(x%4==0 && x%100!=0){
return 1;
}
return 0;
}
void block(int day){
for(int i=1;i<=day;i++){
printf(" ");
}
}
int main(void){
int x,day,sign=28;
printf("輸入年份: ");
scanf("%d",&x);
printf("year: %d",x);
day = firstday(x);
if(leapyear(x)==1){
sign = 29;
}
printf("\n一月 \n S M T W T F S \n");
block(day);
for(int j=1;j<=31;j++){
printf("%3d",j);
day++;
if(day==7){
day = 0;
printf("\n");
}
}
printf("\n二月 \n S M T W T F S \n");
block(day);
for(int j=1;j<=sign;j++){
printf("%3d",j);
day++;
if(day==7){
day = 0;
printf("\n");
}
}
printf("\n三月 \n S M T W T F S \n");
block(day);
for(int j=1;j<=31;j++){
printf("%3d",j);
day++;
if(day==7){
day = 0;
printf("\n");
}
}
printf("\n四月 \n S M T W T F S \n");
block(day);
for(int j=1;j<=30;j++){
printf("%3d",j);
day++;
if(day==7){
day = 0;
printf("\n");
}
}
printf("\n五月 \n S M T W T F S \n");
block(day);
for(int j=1;j<=31;j++){
printf("%3d",j);
day++;
if(day==7){
day = 0;
printf("\n");
}
}
printf("\n六月 \n S M T W T F S \n");
block(day);
for(int j=1;j<=30;j++){
printf("%3d",j);
day++;
if(day==7){
day = 0;
printf("\n");
}
}
printf("\n七月 \n S M T W T F S \n");
block(day);
for(int j=1;j<=31;j++){
printf("%3d",j);
day++;
if(day==7){
day = 0;
printf("\n");
}
}
printf("\n八月 \n S M T W T F S \n");
block(day);
for(int j=1;j<=31;j++){
printf("%3d",j);
day++;
if(day==7){
day = 0;
printf("\n");
}
}
printf("\n九月 \n S M T W T F S \n");
block(day);
for(int j=1;j<=30;j++){
printf("%3d",j);
day++;
if(day==7){
day = 0;
printf("\n");
}
}
printf("\n十月 \n S M T W T F S \n");
block(day);
for(int j=1;j<=31;j++){
printf("%3d",j);
day++;
if(day==7){
day = 0;
printf("\n");
}
}
printf("\n十一月 \n S M T W T F S \n");
block(day);
for(int j=1;j<=30;j++){
printf("%3d",j);
day++;
if(day==7){
day = 0;
printf("\n");
}
}
printf("\n十二月 \n S M T W T F S \n");
block(day);
for(int j=1;j<=31;j++){
printf("%3d",j);
day++;
if(day==7){
day = 0;
printf("\n");
}
}
}
複製代碼
小貓貓2026了喔!
(點一下內洽傳送到小貓貓2026大事記,
如果看不到請通知我
)
TOP
返回列表
小說
其他遊戲
小貓貓會議室
動漫討論
小貓月連載
[收藏此主題]
[關注此主題的新回復]
[通過 QQ、MSN 分享給朋友]