herrDeng網內搜尋
自訂搜尋
Ads
2009年4月28日 星期二
訂閱:
張貼留言 (Atom)
熱門文章
-
教育部為提昇全民資安素養與電腦防護能力,本部於101年9月5日至11月5日舉辦「全民資安素養自我評量」活動,請在活動期間內踴躍上網檢測資訊安全素養認知程度,並有機會參與抽獎,詳情請參閱活動網站(網址: https://isafe.moe.edu.tw/event
-
url="https://www.twse.com.tw/exchangeReport/STOCK_DAY?response=json&date=20220330&stockNo=2330"
-
先說明一下這是後知後覺的解答,所謂後知就是股票價格已知存在陣列(清單),當然就要用迴圈練習,雙迴圈暴力解需時O(n**2),當然不用,採python單一迴圈解答「最佳股票的買賣時機#LeetCode 121 Best Time to Buy and Sell Stock」,解...
-
你會用C的算子sizeof?
-
XOR prefixsum CPP python解Leetcode 1829 Maximum XOR for Each Query 其實這裡考慮的是元素個數為2^maximumBit的交換群,運算子為XOR。 [Python code請進]
-
Python C++使用字串find迴圈速解Leetcode 2490 Circular Sentence C++ & Python都有字串的find,用法都類似 split=s.find(' ', split+1)能找到s從index=split+1開...
67 則留言:
1
#include <iostream>
#include <cstdlib>
using namespace std;
int main()
{
int x=5,y=3,z,w;
x-=2;
cout<<x++<<"\n";
z=++y;
cout<<z<<"\n";
cout<<y<<"\n";
w=z<<2;
cout<<z<<"\n";
cout<<w<<"\n";
for(x=4;x<10;x++){
if (x%2==0) continue;
cout<<x<<"\n";
if (x==7) break;
};
cout<<x<<"\n";
system("Pause");
return 0;
}
答案: 3 4 4 4 16 5 7 7
2.
#include <stdio.h>
#include <stdlib.h>
int main(){
int j=2, i=0xf;
const double PT=3.1415926536;
printf("[%3x]\n",i);
printf("[%3d]\n",i);
printf("[%3d]\n",j);
printf("[%f]\n",PT);
printf("[%-15.10f]\n",PT);
system("PAUSE");
return 0;
}
答案:
[ f]
[ 15]
[ 2]
[3.141593]
[3.1415926536 ]
3.
#include <stdio.h>
#include <stdlib.h>
int main(){
int i;
for (i=0;i<7;i++)
{
if(i==0)
printf("i=%d\n",i);
else if(i==1)
printf("i=%d\n",i);
else if(i==2)
printf("i=%d\n",i);
else
printf("這是期中考\n",i);
};
printf("i=%d\n", i++);
system("Pause");
return 0;
}
答案:
i=0
i=1
i=2
這是期中考
這是期中考
這是期中考
這是期中考
i=7
5.
#include <iostream>
using namespace std;
void prCh(char ch, int rows);
int main()
{
for(int i=0;i<5;i++){
prCh('A',i+1);
prCh('X',i);
cout<<endl;
}
cin.get();
return 0;
}
void prCh(char ch, int rows){
for (int i=1;i<=rows;i++){
cout<<ch;
}
}
答案:
A
AAX
AAAXX
AAAAXXX
AAAAAXXXX
6.
#include <stdio.h>
#include <stdlib.h>
int main()
{
char x[11]="while_loop";
int i=0,n;
scanf("%d",&n);
while(i<n){
printf("%s",x);
i++;
}
system("Pause");
return 0;
}
答案:
5
while_loopwhile_loopwhile_loopwhile_loopwhile_loop請按任意鍵繼續 . . .
1.
#include <cstdlib>
#include <iostream>
using namespace std;
int main()
{
int x=5,y=3,z,w;
x-=2;
cout<<x++<<"\n";
z=++y;
cout<<z<<"\n";
cout<<y<<"\n";
w=z<<2;
cout<<z<<"\n";
cout<<w<<"\n";
for(x=4;x<10;x++)
{
if(x%2==0)
continue;
cout<<x<<"\n";
if(x==7)
break;
};
cout<<x<<"\n";
system("pause");
return 0;
}
2.
#include <stdio.h>
#include <stdlib.h>
int main()
{
int j=2, i=0xf;
const double PI=3.1415926536;
printf("[%3x]\n",i);
printf("[%3d]\n",i);
printf("[%3d]\n",j);
printf("[%3f]\n",PI);
printf("[%-15.10f]\n",PI);
system("pause");
return 0;
}
3.
#include <stdio.h>
#include <stdlib.h>
int main()
{
int i;
for(i=0;i<7;i++)
{
if(i==0)
printf("i=%d\n",i);
else if(i==1)
printf("i=%d\n",i);
else if(i==2)
printf("i=%d\n",i);
else printf("這是期中考\n",i);
}
printf("i=%d\n",i++);
system("pause");
return 0;
}
5.
原程式:
#include <iostream>
using namespace std;
void prCh(char ch,int rows);
int main()
{
for(int i=0;i<5;i++)
{
prCh('A',i+1);
prCh('x',i);
cout<<endl;
}
cin.get();
return 0;
}
void prCh(char ch,int rows)
{
for(int i=1;i<=rows;i++)
cout<<ch;
}
修改後:
#include <iostream>
using namespace std;
void prCh(char ch,int rows);
int main()
{
for(int i=3;i>=0;i--)
{
prCh(' ',i);
prCh('$',4-i);
cout<<endl;
}
cin.get();
return 0;
}
void prCh(char ch,int rows)
{
for(int i=1;i<=rows;i++)
cout<<ch;
}
6.
#include <stdio.h>
#include <stdlib.h>
int main()
{
char x[11]="while-loop";
int i=0,n;
scanf("%d",&n);
while(i<n)
{
printf("%s",x);
i++;
}
system("pause");
return 0;
}
1.
#include <cstdlib>
#include <iostream>
using namespace std;
int main ()
{
int x=5,y=3,z,w;
x-=2;
cout<<x++<<"\n";
z=++y;
cout<<z<<"\n";
cout<<y<<"\n";
w=z<<2;
cout<<z<<"\n";
cout<<w<<"\n";
for(x=4;x<10;x++)
{
if (x%2==0)
continue;
cout<<x<<"\n";
if (x==7)
break;
};
cout<<x<<"\n";
system ("pause");
return 0;
}
3.
#include <stdio.h>
#include <stdlib.h>
int main ()
{
int i;
for (i=0;i<7;i++)
{
if(i==0)
printf("i=%d\n",i);
else if (i==1)
printf("i=%d\n",i);
else if (i==2)
printf("i=%d\n",i);
else
printf ("這是期中考\n");
}
printf ("i=%d\n",i++);
system("pause");
return 0;
}
5.
#include <iostream>
using namespace std;
void prCh(char ch, int rows);
int main()
{
for(int i=3;i>=0;i--)
{
prCh(' ',i);
prCh('$',4-i);
cout<<endl;
}
cin.get();
return 0;
}
void prCh (char ch, int rows)
{
for (int i=1;i<=rows;i++)
{
cout<<ch;
}
}
6.
#include <stdio.h>
#include <stdlib.h>
int main ()
{
char x[11]="while-loop";
int i=0,n;
scanf("%d",&n);
while (i<n)
{
printf("%s",x);
i++;
}
system("pause");
return 0;
}
7.
#include <stdio.h>
#include <stdlib.h>
int main()
{
int i,s;
for (i=3;i<=1002;i++)
s=s+i*(i+1);
printf("%d\n",s);
system("pause");
return 0;
}
1.
#include <iostream>
using namespace std;
int main(){
int x=5,y=3,z,w;
x-=2;
cout<<x<<"\n";
z=++y;
cout<<z<<"\n";
cout<<y<<"\n";
w=z<<2;
cout<<z<<"\n";
cout<<w<<"\n";
for (x=4;x<10;x++){
if(x%2==0)continue;
cout<<x<<"\n";
if(x==7)break;
};
cout<<x<<"\n";
system("pause");
return 0;
}
answer:
3
4
4
4
16
5
7
7
請按任意鍵繼續 . . .
=========================================================
2.
#include <stdio.h>
#include <stdlib.h>
int main(){
int j=2,i=0xf;
const double PI=3.1415926536;
printf("[%3x]\n",i);
printf("[%3d]\n",i);
printf("[%3d]\n",j);
printf("[%f]\n",PI);
printf("[%-15.10f]\n",PI);
system("PAUSE");
return 0;
}
answer:
[ f]
[ 15]
[ 2]
[3.141593]
[3.1415926536 ]
請按任意鍵繼續 . . .
===========================================================
3.
#include <stdio.h>
#include <stdlib.h>
int main(){
int i;
for (i=0;i<7;i++)
{
if(i==0){
printf("i=%d\n",i);}
else if(i==1){
printf("i=%d\n",i);}
else if(i==2){
printf("i=%d\n",i);}
else {
printf("這是期中考\n");}
};
printf("i=%d\n",i++);
system("PAUSE");
return 0;
}
answer:
i=0
i=1
i=2
這是期中考
這是期中考
這是期中考
這是期中考
i=7
請按任意鍵繼續 . . .
==================================
6.
#include <stdio.h>
#include <stdlib.h>
int main(){
char x[11]="while-loop";
int i=0,n;
scanf("%d",&n);
while(i<n){
printf("%s",x);
i++;
}
system("pause");
return 0;
}
answer:
3
while-loopwhile-loopwhile-loop請按任意鍵繼續 . . .
1.#include <iostream>
using namespace std;
int main(){
int x=5,y=3,z,w;
x-=2;
cout<<x++<<"\n";
z=++y;
cout<<z<<"\n";
cout<<y<<"\n";
w=z<<2;
cout<<z<<"\n";
cout<<w<<"\n";
for(x=4;x<10;x++){
if(x%2==0) continue;
cout<<x<<"\n";
if(x==7) break;
};
cout<<x<<"\n";
system ("pause");
return 0;
}
answer
3
4
4
4
16
5
7
7
請按任意鍵繼續 . . .
=================================================================================
3.#include <stdio.h>
#include <stdlib.h>
int main(){
int i;
for(i=0;i<7;i++)
{
if(i==0){
printf("i=%d\n",i);}
else if(i==1){
printf("i=%d\n",i);}
else if(i==2){
printf("i=%d\n",i);}
else printf("這是期中考\n",i);}
printf("i=%d\n",i++);
system ("pause");
return 0;
}
answer
i=0
i=1
i=2
這是期中考
這是期中考
這是期中考
這是期中考
i=7
請按任意鍵繼續 . .
================================================================================
5.#include <iostream>
using namespace std;
void prCh(char ch,int rows);
int main(){
for (int i=1;i<5;i++){
prCh (' ',4-i);
prCh ('$',i);
cout<<endl;}
cin.get();
return 0;
}
void prCh(char ch,int rows){
for(int i=1;i<=rows;i++){
cout<<ch;
}
}
answer
$
$$
$$$
$$$$
=================================================================================
6.#include <stdio.h>
#include <stdlib.h>
int main(){
char x[11]="while-loop";
int i=0,n;
scanf("%d",&n);
while(i<n){
printf("%s",x);
i++;
}
system ("pause");
return 0;
}
answer
1
while-loop請按任意鍵繼續 . . .
=================================================================================
7.#include <stdio.h>
#include <stdlib.h>
int main(){
int i,s;
for(int i=3;i<=1002;i++)
s=s+i*(i+1);
printf ("%d",s);
system ("pause");
return 0;
}
answer
336342048請按任意鍵繼續 . . .
2.
#include<stdio.h>
#include<stdlib.h>
int main()
{
int j=2,i=0xf;
const double PI=3.1415926536;
printf("[%3x]\n",i);
printf("[%3d]\n",i);
printf("[%3d]\n",j);
printf("[%f]\n",PI);
printf("[%-15.10f]\n",PI);
system("pause");
return 0;
}
輸出:
[00f]
[015]
[002]
[3.141593]
[3.1415926536000]
5.
#include<iostream>
using namespace std;
void prCh(char ch, int rows);
{
for (int i=0;i<5;i++){
prCh('A',i+1);
prCh('X',i);
cout<<endl;
void prCh(char ch, int rows){
for(int i=1;i<=rows;i++){
cout<<ch;
}
}
輸出:
A
AAX
AAAXX
AAAAXXX
AAAAAXXXX
改寫為:
$
$$
$$$
$$$$
#include<iostream>
using namespace std;
void prCh(char ch, int rows);
{
for (int i=0;i<5;i++){
prCh(' ',i);
prCh('$',4-i);
cout<<endl;
void prCh(char ch, int rows){
for(int i=1;i<=rows;i++){
cout<<ch;
}
}
6.
#include<stdio.h>
#include<stdlib.h>
int main()
{
char x[11]="while-loop";
int i=0,n;
scanf("%d",&n);
while(i>=0)
{
printf("%s",x);
i++;
}
system("pause");
return 0;
}
1.
#include <cstdlib>
#include <iostream>
using namespace std;
int main()
{
int x=5,y=3,z,w;
x-=2;
cout<<x++<<"\n";
z=++y;
cout<<z<<"\n";
cout<<y<<"\n";
w=z<<2;
cout<<z<<"\n";
cout<<w<<"\n";
for(x=4;x<10;x++)
{
if (x%2==0) continue;
cout<<x<<"\n";
if (x==7) break;
};
cout<<x<<"\n";
system("pause");
return 0;
}
2.
#include <stdio.h>
#include <stdlib.h>
int main()
{
int j=2,i=0xf;
const double PI=3.1415926536;
printf("[%3x]\n",i);
printf("[%3d]\n",i);
printf("[%3d]\n",j);
printf("[%f]\n",PI);
printf("[%-15.10f]\n",PI);
system("pause");
return 0;
}
3.
#include <stdio.h>
#include <stdlib.h>
int main()
{
int i;
for(i=0;i<7;i++)
{
if(i==0)
printf("i=%d\n",i);
else if(i==1)
printf("i=%d\n",i);
else if(i==2)
printf("i=%d\n",i);
else
printf("這是其中考\n");
}
printf("i=%d\n",i++);
system("pause");
return 0;
}
6.
#include <stdio.h>
#include <stdlib.h>
int main()
{
char x[11]="while-loop";
int i=0,n;
scanf("%d",&n);
while(i<n)
{
printf("%s",x);
i++;
}
system("pause");
return 0;
}
1.
#include<cstdlib>
#include<iostream>
using namespace std;
int main()
{
int x=5,y=3,z,w;
x-=2;
cout<<x++<<"\n";
z=++y;
cout<<z<<"\n";
cout<<y<<"\n";
w=z<<2;
cout<<z<<"\n";
cout<<w<<"\n";
for(x=4;x<10;x++){
if (x%2==0) continue;
cout<<x<<"\n";
if (x==7) break;
};
cout<<x<<"\n";
system("pause");
return 0;
}
3.
#include<stdio.h>
#include<stdlib.h>
int main()
{
int i;
for (i=0;i<7;i++)
{
if(i==0){
printf("i=%d\n",i);
else if(i==1)
printf("i=%d\n",i);
else if(i==2)
printf("i=%d\n",i);
else printf("這是期中考\n",i);
}
printf("i=%d\n",i++);
system("pause");
return 0;
}
5-1.
#include<iostream>
using namespace std;
void prCh(char ch, int rows);
int main()
{
for(int i=0;i<5;i++)
{
prCh('A',i+1);
prCh('X',i);
cout<<endl;
}
cin.get();
return 0;
}
void prCh(char ch,int rows)
{
for(int i=1;i<=rows;i++)
{
cout<<ch;
}
}
5-2.
#include<iostream>
using namespace std;
void prCh(char ch, int rows);
int main()
{
for(int i=3;i>=0;i--)
{
prCh(' ',i);
prCh('$',4-i);
cout<<endl;
}
cin.get();
return 0;
}
void prCh(char ch,int rows)
{
for(int i=1;i<=rows;i++)
{
cout<<ch;
}
}
6.
#include<stdio.h>
#include<stdlib.h>
int main()
{
char x[11]="while-loop";
int i=0,n;
scanf("%d",&n);
while(i<n)
{
printf("%s",x);
i++;
}
system("pause");
return 0;
}
7.
#include<stdio.h>
#include<stdlib.h>
int main()
{
int i,s;
for(i=3;i<1002;i++)
s+=i*(i+1);
printf("%d",s);
system("pause");
return 0;
}
1.
#include <cstdlib>
#include <iostream>
using namespace std;
int main()
{
int x=5,y=3,z,w;
x-=2;
cout<<x++<<"\n";
z=++y;
cout<<z<<"\n";
cout<<y<<"\n";
w=z<<2;
cout<<z<<"\n";
cout<<w<<"\n";
for(x=4;x<10;x++){
if (x%2==0)continue;
cout<<x<<"\n";
if (x==7) break;
};
cout<<x<<"\n";
system("pause");
return 0;
}
3
4
4
4
16
5
7
7
請按任意鍵繼續 . . .
2.
#include <stdio.h>
#include <stdlib.h>
int main()
{
int j=2;
int i=0xf;
const double PI=3.1415926536;
printf("[%3x]\n",i);
printf("[%3d]\n",i);
printf("[%3d]\n",j);
printf("[%f]\n",PI);
printf("[%-15.10f]\n",PI);
system("PAUSE");
return 0;
}
[ f]
[ 15]
[ 2]
[3.141593]
[3.1415926536 ]
請按任意鍵繼續 . . .
3.
#include <stdio.h>
#include <stdlib.h>
int main()
{
int i;
for (i=0;i<7;i++)
if (i==0){
printf("i=%d\n",i);}
else if(i==1){
printf("i=%d\n",i);}
else if(i==2){
printf("i=%d\n",i);}
else{
printf("這是期中考\n");}
printf("i=%d\n",i++);
system("PAUSE");
return 0;
}
i=0
i=1
i=2
這是期中考
這是期中考
這是期中考
這是期中考
i=7
請按任意鍵繼續 . . .
5.
改前
#include <iostream>
using namespace std;
void prCh(char ch, int rows);
int main(){
for(int i=0;i<5;i++){
prCh('A',i+1);
prCh('x',i);
cout<<endl;
}
cin.get();
return 0;
}
void prCh(char ch, int rows){
for (int i=1;i<=rows;i++){
cout<<ch;
}
}
A
AAx
AAAxx
AAAAxxx
AAAAAxxxx
改後
#include <iostream>
using namespace std;
void prCh(char ch, int rows);
int main(){
for(int i=3;i>=0;i--){
prCh(' ',i);
prCh('$',4-i);
cout<<endl;
}
cin.get();
return 0;
}
void prCh(char ch, int rows){
for (int i=1;i<=rows;i++){
cout<<ch;
}
}
$
$$
$$$
$$$$
6.
#include <stdio.h>
#include <stdlib.h>
int main()
{
char x[11]="while-loop";
int i=0,n;
scanf("%d",&n);
while(i<n){
printf("%s", x);
i++;}
system("PAUSE");
return 0;
}
1.
#include <cstdlib>
#include <iostream>
using namespace std;
int main()
{
int x=5,y=3,z,w;
x-=2;
cout<<x++<<"\n";
z=++y;
cout<<z<<"\n";
cout<<y<<"\n";
w=z<<2;
cout<<z<<"\n";
cout<<w<<"\n";
for(x=4;x<10;x++){
if (x%2==0) continue;
cout<<x<<"\n";
if (x==7) break;
};
cout<<x<<"\n";
system("pause");
return 0;
}
輸出:
3
4
4
4
16
5
7
7
5.
#include <iostream>
using namespace std;
void prCh(char ch, int rows);
int main()
{
for(int i=0;i<5;i++){
prCh('A',i+1);
prCh('X',i);
cout<<endl;
}
cin.get();
return 0;
}
void prCh(char ch, int rows){
for (int i=1; i<=rows; i++){
cout<<ch;
}
}
輸出:
A
AAX
AAAXX
AAAAXXX
AAAAAXXXX
改寫:
#include <iostream>
using namespace std;
void prCh(char ch, int rows);
int main()
{
for(int i=3;i>=0;i--){
prCh(' ',i);
prCh('$',4-i);
cout<<endl;
}
cin.get();
return 0;
}
void prCh(char ch, int rows){
for (int i=1; i<=rows; i++){
cout<<ch;
}
}
輸出:
$
$$
$$$
$$$$
6.
#include <stdio.h>
#include <stdlib.h>
int main()
{
char x[11]="while-loop";
int i=0, n;
scanf("%d",&n);
while(i>=0){
printf("%s",x);
i++;
}
system("PAUSE");
return 0;
}
7.
#include <stdio.h>
#include <stdlib.h>
int main()
{
int i,s;
for(i=3;i<=1002;i++)
s+=i*(i+1);
printf("%d",i);
system("pause");
return 0;
}
第一題.
#include <cstdlib>
#include <iostream>
using namespace std;
int main()
{
int x=5,y=3,z,w;
x-=2;
cout<<x++<<"\n";
z=++y;
cout<<z<<"\n";
cout<<y<<"\n";
w=z<<2;
cout<<z<<"\n";
cout<<w<<"\n";
for(x=4;x<10;x++){
if (x%2==0)continue;
cout<<x<<"\n";
if (x==7) break;
};
cout<<x<<"\n";
system ("pause");
return 0;
}
ANSWER:
3
4
4
4
16
5
7
7
第三題.
#include <stdio.h>
#include <stdlib.h>
int main()
{
int i;
for (i=0;i<7;i++)
{
if(i==0)
{
printf("i=%d\n",i);
}
else if(i==1)
{
printf("i=%d\n",i);
}
else if(i==2)
{
printf("i=%d\n",i);
}
else
{
printf("這是期中考\n",i);
}
};
printf("i=%d\n", i++);
system("pause");
return 0;
}
ANSWER:
i=0
i=1
i=2
這是期中考
這是期中考
這是期中考
這是期中考
i=7
第五題.(1)修改前
#include <iostream>
using namespace std;
void prCh(char ch, int rows);
int main(){
for(int i=0;i<5;i++){
prCh('A',i+1);
prCh('X',i);
cout<<endl;
}
cin.get();
return 0;
}
void prCh(char ch, int rows){
for (int i=1;i<=rows;i++){
cout<<ch;
}
}
ANSWER:
A
AAX
AAAXX
AAAAXXX
AAAAAXXXX
第五題.(2)修改後
#include <iostream>
using namespace std;
void prCh(char ch, int rows);
int main(){
for(int i=3;i>=0;i--){
prCh(' ',i);
prCh('$',4-i);
cout<<endl;
}
cin.get();
return 0;
}
void prCh(char ch, int rows){
for (int i=1;i<=rows;i++){
cout<<ch;
}
}
ANSWER:
$
$$
$$$
$$$$
第六題.
#include <stdio.h>
#include <stdlib.h>
int main()
{
char x[11]="while-loop";
int i=0,n;
scanf("%d",&n);
while(i<n){
printf("%s",x);
i++;
}
system ("pause");
return 0;
}
第七題.
#include <stdio.h>
#include <stdlib.h>
int main()
{
int i,s;
for(i=3;i<=1002;i++)
s=s+i*(i+1);
printf("%d",s);
system("pause");
return 0;
}
1.
#include <iostream>
#include <cstdlib>
using namespace std;
int main()
{
int x=5,y=3,z,w;
x-=2;
cout<<x++<<"\n";
z=++y;
cout<<z<<"\n";
cout<<y<<"\n";
w=z<<2;
cout<<z<<"\n";
cout<<w<<"\n";
for(x=4;x<10;x++){
if (x%2==0)continue;
cout<<x<<"\n";
if (x==7) break;
};
cout<<x<<endl;
system("pause");
return 0;
}
答案:
3
4
4
4
16
5
7
7
2.
#include <stdio.h>
#include <stdlib.h>
int main()
{
int j=2,i=0xf;
const double PI=3.1415926536;
printf("[%3x]\n",i);
printf("[%3d]\n",i);
printf("[%3d]\n",j);
printf("[%f]\n",PI);
printf("[%-15.10f]\n",PI);
system("PAUSE");
return 0;
}
答案:
[ f]
[ 15]
[ 2]
[3.141593]
[3.1415926536 ]
3.
#include<stdio.h>
#include<stdlib.h>
int main()
{
int i;
for (i=0;i<7;i++)
{
if(i==0)
printf("i=%d\n",i);
else if(i==1)
printf("i=%d\n",i);
else if(i==2)
printf("i=%d\n",i);
else
printf("這是期中考 \n");
};
printf("i=%d\n", i++);
system("pause");
return 0;
}
答案:
i=0
i=1
i=2
這是期中考
這是期中考
這是期中考
這是期中考
i=7
5.
#include <iostream>
using namespace std;
void prCh(char ch, int rows);
int main()
{
prCh(' ',3);
prCh('$',1);
cout<<endl;
prCh(' ',2);
prCh('$',2);
cout<<endl;
prCh(' ',1);
prCh('$',3);
cout<<endl;
prCh('$',4);
cout<<endl;
cin.get();
return 0;
}
void prCh(char ch, int rows){
for (int i=1; i<=rows;i++){
cout<<ch;
}
}
答案:
$
$$
$$$
$$$$
6.
#include<stdio.h>
#include<stdlib.h>
int main()
{
char x[11]="while-loop";
int i=0,n;
scanf("%d",&n);
while(i<n)
{
printf("%s",x);
i++;
}
system("pause");
return 0;
}
答案:
4
while-loopwhile-loopwhile-loopwhile-loop
1.
#include<cstdlib>
#include<iostream>
using namespace std;
int main()
{
int x=5,y=3,z,w;
x-=2;
cout<<x++<<"\n";
z=++y;
cout<<z<<"\n";
cout<<y<<"\n";
w=z<<2;
cout<<z<<"\n";
cout<<w<<"\n";
for(x=4;x<10;x++)
{
if(x%2==0)continue;
cout<<x<<"\n";
if(x==7)break;
};
cout<<x<<"\n";
system("pause");
return 0;
}
ans:
3
4
4
4
16
5
7
7
3.
#include<stdio.h>
#include<stdlib.h>
int main()
{
int i;
for(i=0;i<7;i++)
{
if(i==0)
{
printf("i=%d\n",i);
}
else if(i==1)
{
printf("i=%d\n",i);
}
else if(i==2)
{
printf("i=%d\n",i);
}
else
{
printf("這是期中考\n");
}
}
printf("i=%d\n",i++);
system("pause");
return 0;
}
ans:
i=0
i=1
i=2
這是期中考
這是期中考
這是期中考
這是期中考
i=7
5.
(1)
#include<iostream>
using namespace std;
void prCh(char ch,int rows);
int main()
{
for(int i=0;i<=5;i++)
{
prCh('A',i+1);
prCh('X',i);
cout<<endl;
}
cin.get();
return 0;
}
void prCh(char ch,int rows)
{
for(int i=1;i<=rows;i++)
{
cout<<ch;
}
}
ans:
A
AAX
AAAXX
AAAAXXX
AAAAAXXXX
AAAAAAXXXXX
(2)
#include<iostream>
using namespace std;
void prCh(char ch,int rows);
int main()
{
for(int i=3;i>=0;i--)
{
prCh(' ',i);
prCh('$',4-i);
cout<<endl;
}
cin.get();
return 0;
}
void prCh(char ch,int rows)
{
for(int i=1;i<=rows;i++)
{
cout<<ch;
}
}
ans:
$
$$
$$$
$$$$
6.
#include<stdio.h>
#include<stdlib.h>
int main()
{
char x[11]="while-loop";
int i=0,n;
scanf("%d",&n);
while(i<n)
{
printf("%s",x);
i++;
}
system("pause");
return 0;
}
第一題:
#include <iostream>
#include <cstdlib>
using namespace std;
int main(){
int x=5 ,y=3 ,z ,w ;
x-=2;
cout<<x++<<"\n";
z=++y;
cout<<z<<"\n";
cout<<y<<"\n";
w=z<<2;
cout<<z<<"\n";
cout<<w<<"\n";
for(x=4 ;x<10 ;x++){
if (x%2==0) continue;
cout<<x<<"\n";
if(x==7)break;
};
cout<<x<<"\n";
system("pause");
return 0;
}
輸出:
3
4
4
4
16
5
7
7
第二題:
#include <stdio.h>
#include <stdlib.h>
int main(){
int i;
for (i=0 ;i<7 ;i++)
{
switch(i){
case 0:printf("i=%d\n",i);break;
case 1:printf("i=%d\n",i);break;
case 2:printf("i=%d\n",i);break;
default:printf("這是期中考\n");break;
};
};
printf("i=%d\n",i++);
system("pause");
return 0;
}
輸出:
i=0
i=1
i=2
這是期中考
這是期中考
這是期中考
這是期中考
i=7
第六題:
#include <stdio.h>
#include <stdlib.h>
int main(){
char x[11]="while-loop";
int i=0, n;
scanf("%d",&n);
while(i<n){
printf("%s", x);
i++;
}
system("pause");
return 0;
}
1.
#include<cstdlib>
#include<iostream>
using namespace std;
int main()
{
int x=5,y=3,z,w;
x-=2;
cout<<x++<<"\n";
z=++y;
cout<<z<<"\n";
cout<<y<<"\n";
w=z<<2;
cout<<z<<"\n";
cout<<w<<"\n";
for(x=4;x<10;x++){
if (x%2==0) continue;
cout<<x<<"\n";
if (x==7) break;
};
cout<<x<<"\n";
system("pause");
return 0;
}
ANS:3
4
4
4
16
5
7
7
3.
#include<stdio.h>
#include<stdlib.h>
int main()
{
int i;
for (i=0;i<7;i++)
{
if(i==0){
printf("i=%d\n",i);
else if(i==1)
printf("i=%d\n",i);
else if(i==2)
printf("i=%d\n",i);
else printf("這是期中考\n",i);
}
printf("i=%d\n",i++);
system("pause");
return 0;
}
ANS:i=0
i=1
i=2
這是期中考
這是期中考
這是期中考
這是期中考
i=7
5-1.
#include<iostream>
using namespace std;
void prCh(char ch, int rows);
int main()
{
for(int i=0;i<5;i++)
{
prCh('A',i+1);
prCh('X',i);
cout<<endl;
}
cin.get();
return 0;
}
void prCh(char ch,int rows)
{
for(int i=1;i<=rows;i++)
{
cout<<ch;
}
}
ANS:A
AAX
AAAXX
AAAAXXX
AAAAAXXXX
5-2.
#include<iostream>
using namespace std;
void prCh(char ch, int rows);
int main()
{
for(int i=3;i>=0;i--)
{
prCh(' ',i);
prCh('$',4-i);
cout<<endl;
}
cin.get();
return 0;
}
void prCh(char ch,int rows)
{
for(int i=1;i<=rows;i++)
{
cout<<ch;
}
}
ANS: $
$$
$$$
$$$$
6.
#include<stdio.h>
#include<stdlib.h>
int main()
{
char x[11]="while-loop";
int i=0,n;
scanf("%d",&n);
while(i<n)
{
printf("%s",x);
i++;
}
system("pause");
return 0;
}
7.
#include<stdio.h>
#include<stdlib.h>
int main()
{
int i,s;
for(i=3;i<1002;i++)
s+=i*(i+1);
printf("%d",s);
system("pause");
return 0;
}
ANS:335337048
1.
#include <cstdlib>
#include <iostream>
using namespace std;
int main()
{
int x=5 y=3,z,w;
x-=2;
cout<<x++<<"\n";
z=++y;
cout<<z<<"\n";
cout<<y<<"\n";
w=z<<2;
cout<<z<<"\n";
cout<<w<<"\n";
for(x=4;x<10;;x++){
if(x%2==0) continue;
cout<<x<<"\n";
i (x==7) break;
};
cout<<x<<"\n";
system("pause");
return0;
}
輸出:
3
4
4
4
16
5
7
7
2.
#include<stdio.h>
#include<stdlib.h>
int main()
{
int j=2,i=0xf;
const double PI=3.1415926536;
printf("[%3x]\n",i);
printf("[%3d]\n",i);
printf("[%3d]\n",j);
printf("[%f]\n",PI);
printf("[%-15.10f]\n",PI);
system("pause");
return 0;
}
輸出:
[00f]
[015]
[002]
[3.141593]
[3.1415926536000]
3.
#include <stdio.h>
#include <stdlib.h>
int main()
{
int i;
for(i=0;i<7;i++)
{
if(i==0)
printf("i=%d\n",i);
else if(i==1)
printf("i=%d\n",i);
else if(i==2) '
printf("i=%d\n",i);
else
printf("這是期中考\n");
}
printf("i=%d\n",i++);
system("pause");
return0;
}
輸出:
i=0
i=1
i=2
這是期中考
這是期中考
這是期中考
這是期中考
i=7
5.
#include<iostream>
using namespace std;
void prCh(char ch, int rows);
{
for (int i=0;i<5;i++){
prCh('A',i+1);
prCh('X',i);
cout<<endl;
void prCh(char ch, int rows){
for(int i=1;i<=rows;i++){
cout<<ch;
}
}
輸出:
A
AAX
AAAXX
AAAAXXX
AAAAAXXXX
改寫為:
$
$$
$$$
$$$$
#include<iostream>
using namespace std;
void prCh(char ch, int rows);
{
for (int i=0;i<5;i++){
prCh(' ',i);
prCh('$',4-i);
cout<<endl;
void prCh(char ch, int rows){
for(int i=1;i<=rows;i++){
cout<<ch;
}
}
6.
#include<stdio.h>
#include<stdlib.h>
int main()
{
char x[11]="while-loop";
int i=0,n;
scanf("%d",&n);
while(i>=0)
{
printf("%s",x);
i++;
}
system("pause");
return 0;
}
7.
#include <stdio.h>
#include <stdlib.h>
int main()
{
int i,s;
for(i=3;i<=1002;i++)
s=s+i*(i+1);
printf("%d",s);
system("pause");
return0;
}
1.
#include <cstdlib>
#include <iostream>
using namespace std;
int main()
{
int x=5,y=3,z,w;
x-=2;
cout<<x++<<"\n";
z=++y;
cout<<z<<"\n";
cout<<y<<"\n";
w=z<<2;
cout<<z<<"\n";
cout<<w<<"\n";
for(x=4;x<10;x++)
{
if(x%2==0)
continue;
cout<<x<<"\n";
if(x==7)
break;
};
cout<<x<<"\n";
system("pause");
return 0;
}
輸出:
3
4
4
4
16
5
7
7
2.
#include <stdio.h>
#include <stdlib.h>
int main()
{
int j=2, i=0xf;
const double PI=3.1415926536;
printf("[%3x]\n",i);
printf("[%3d]\n",i);
printf("[%3d]\n",j);
printf("[%3f]\n",PI);
printf("[%-15.10f]\n",PI);
system("pause");
return 0;
}
輸出:
[□□f]
[□15]
[□□2]
[3.141593]
[3.1415926536□□□]
3.
#include <stdio.h>
#include <stdlib.h>
int main()
{
int i;
for(i=0;i<7;i++)
{
if(i==0)
printf("i=%d\n",i);
else if(i==1)
printf("i=%d\n",i);
else if(i==2)
printf("i=%d\n",i);
else printf("這是期中考\n",i);
}
printf("i=%d\n",i++);
system("pause");
return 0;
}
輸出:
i=0
i=1
i=2
這是期中考
這是期中考
這是期中考
這是期中考
i=7
5.
原程式:
#include <iostream>
using namespace std;
void prCh(char ch,int rows);
int main()
{
for(int i=0;i<5;i++)
{
prCh('A',i+1);
prCh('x',i);
cout<<endl;
}
cin.get();
return 0;
}
void prCh(char ch,int rows)
{
for(int i=1;i<=rows;i++)
cout<<ch;
}
輸出:
A
AAX
AAAXX
AAAAXXX
AAAAAXXXX
修改後:
#include <iostream>
using namespace std;
void prCh(char ch,int rows);
int main()
{
for(int i=3;i>=0;i--)
{
prCh(' ',i);
prCh('$',4-i);
cout<<endl;
}
cin.get();
return 0;
}
void prCh(char ch,int rows)
{
for(int i=1;i<=rows;i++)
cout<<ch;
}
輸出:
$
$$
$$$
$$$$
6.
#include <stdio.h>
#include <stdlib.h>
int main()
{
char x[11]="while-loop";
int i=0,n;
scanf("%d",&n);
while(i<n)
{
printf("%s",x);
i++;
}
system("pause");
return 0;
}
1.
#include <cstdlib>
#include <iostream>
using namespace std;
int main()
{
int x=5,y=3,z,w;
x-=2;
cout<<x++<<"\n";
z=++y;
cout<<z<<"\n";
cout<<y<<"\n";
w=z<<2;
cout<<z<<"\n";
cout<<w<<"\n";
for(x=4;x<10;x++)
{
if (x%2==0) continue;
cout<<x<<"\n";
if (x==7) break;
};
cout<<x<<"\n";
system("pause");
return 0;
}
Ans:3,4,4,4,16,5,7,7
2.
#include <stdio.h>
#include <stdlib.h>
int main()
{
int j=2,i=0xf;
const double PI=3.1415926536;
printf("[%3x]\n",i);
printf("[%3d]\n",i);
printf("[%3d]\n",j);
printf("[%f]\n",PI);
printf("[%-15.10f]\n",PI);
system("pause");
return 0;
}
Ans:[ f]
[ 15]
[ 2]
[3.141593]
[3.1415926536 ]
3.
#include <stdio.h>
#include <stdlib.h>
int main()
{
int i;
for(i=0;i<7;i++)
{
if(i==0)
printf("i=%d\n",i);
else if(i==1)
printf("i=%d\n",i);
else if(i==2)
printf("i=%d\n",i);
else
printf("這是其中考\n");
}
printf("i=%d\n",i++);
system("pause");
return 0;
}
Ans:i=0
i=1
i=2
這是期中考
這是期中考
這是期中考
這是期中考
i=7
6.
#include <stdio.h>
#include <stdlib.h>
int main()
{
char x[11]="while-loop";
int i=0,n;
scanf("%d",&n);
while(i<n)
{
printf("%s",x);
i++;
}
system("pause");
return 0;
}
1
#include <cstdlib>
#include <iostream>
using namespace std;
int main(){
int x=5,y=3,z,w;
x-=2;
cout<<x++<<"\n";
z=++y;
cout<<z<<"\n";
cout<<y<<"\n";
w=z<<2;
cout<<z<<"\n";
cout<<w<<"\n";
for(x=4;x<10;x++)
{
if (x%2==0) continue;
cout<<x<<"\n";
if (x==7) break;
};
cout<<x<<"\n";
system("pause");
return 0;
}
輸出
3
4
4
4
16
5
7
7
2
#include <stdio.h>
#include <stdlib.h>
int main(){
int j=2, i=0xf;
const double PI=3.1415926536;
printf("[%3x]\n",i);
printf("[%3d]\n",i);
printf("[%3d]\n",j);
printf("[%f]\n",PI);
printf("[%-15.10f]\n",PI);
system("pause");
return 0;
}
輸出
[ f]
[ 15]
[ 2]
[3.141593]
[3.1415926536 ]
3
#include <stdio.h>
#include <stdlib.h>
int main(){
int i;
for (i=0;i<7;i++)
{
switch(i){
case 0:printf("i=%d\n",i);break;
case 1:printf("i=%d\n",i);break;
case 2:printf("i=%d\n",i);break;
default:printf("這是期中考\n");break;
};
};
printf("i=%d\n",i++);
system("pause");
return 0;
}
輸出
i=0
i=1
i=2
這是期中考
這是期中考
這是期中考
這是期中考
i=7
6
#include <stdio.h>
#include <stdlib.h>
int main(){
char x[11]="while-loop";
int i=0, n;
scanf("%d",&n);
while(i<n){
printf("%s",x);
i++;
}
system("pause");
return 0;
}
輸出
5
while-loopwhile-loopwhile-loopwhile-loopwhile-loop
第一題
#include <cstdlib>
#include <iostream>
using namespace std;
int main()
{
int x=5,y=3,z,w;
x-=2;
cout<<x++<<"\n";
z=++y;
cout<<z<<"\n";
cout<<y<<"\n";
w=z<<2;
cout<<z<<"\n";
cout<<w<<"\n";
for (x=4;x<10;x++)
{
if (x%2==0) continue;
cout<<x<<"\n";
if (x==7) break;
};
cout<<x<<"\n";
system("pause");
return 0;
}
答案
3
4
4
4
16
5
7
7
第2題
#include <stdio.h>
#include <stdlib.h>
int main()
{
int j=2,i=0xf;
const double PI=3.1415926536;
printf("[%3x]\n",i);
printf("[%3d]\n",i);
printf("[%3d]\n",j);
printf("[%f]\n",PI);
printf("[%-15.10f]\n",PI);
system ("pause");
return 0;
}
答案
[○○f]
[○15]
[2]
[3.141593]
[3.1415926536 ]
第3題
#include<stdio.h>
#include<stdlib.h>
int main()
{
int i;
for (i=0;i<7;i++)
{
if(i==0)
printf("i=%d\n",i);
else if (i==1)
printf("i=%d\n",i);
else if (i==2)
printf("i=%d\n",i);
else
printf("這是期中考\n");
}
printf("i=%d\n",i++);
system("pause");
return 0;
}
答案
i=0
i=1
i=2
這是期中考
這是期中考
這是期中考
這是期中考
i=7
第5題
#include<iostream>
using namespace std;
void prCh(char ch, int rows);
int main()
{
for(int i=3;i>=0;i--)
{
prCh (' ',i);
prCh ('$',4-i);
cout<<endl;
}
cin.get();
return 0;
}
void prCh(char ch,int rows)
{
for(int i=1; i<=rows; i++)
{
cout<<ch;
}
}
答案
$
$$
$$$
$$$$
第6題
#include <stdio.h>
#include <stdlib.h>
int main ()
{
char x[11]="while-loop";
int i=0,n;
scanf("%d",&n);
while (i<n)
{
printf("%s",x);
i++;
}
system("pause");
return 0;
}
答案
5
while-loopwhile-loopwhile-loopwhile-loopwhile-loop
第7題
#include<stdio.h>
#include<stdlib.h>
int main()
{
int i=3,s;
for (i;i<1002;i++)
s=s+i*(i+1);
printf("%d\n",s);
system ("pause");
return 0;
}
答案
335337043
1.#include <iostream>
using namespace std;
int main(){
int x=5,y=3,z,w;
x-=2;
cout<<x++<<"\n";
z=++y;
cout<<z<<"\n";
cout<<y<<"\n";
w=z<<2;
cout<<z<<"\n";
cout<<w<<"\n";
for(x=4;x<10;x++){
if(x%2==0) continue;
cout<<x<<"\n";
if(x==7) break;
};
cout<<x<<"\n";
system ("pause");
return 0;
}
answer
3
4
4
4
16
5
7
7
請按任意鍵繼續 . . .
=================================================================================
#include <stdio.h>
#include <stdlib.h>
int main()
{
int j=2,i=0xf;
const double PI=3.1415926536;
printf("[%3x]\n",i);
printf("[%3d]\n",i);
printf("[%3d]\n",j);
printf("[%f]\n",PI);
printf("[%-15.10f]\n",PI);
system("pause");
return 0;
}
[ f]
[ 15]
[ 2]
[3.141593]
[3.141592653 ]
請按任意鍵繼續 . . .
============================================================================================
3.#include <stdio.h>
#include <stdlib.h>
int main(){
int i;
for(i=0;i<7;i++)
{
if(i==0){
printf("i=%d\n",i);}
else if(i==1){
printf("i=%d\n",i);}
else if(i==2){
printf("i=%d\n",i);}
else printf("這是期中考\n",i);}
printf("i=%d\n",i++);
system ("pause");
return 0;
}
answer
i=0
i=1
i=2
這是期中考
這是期中考
這是期中考
這是期中考
i=7
請按任意鍵繼續 . .
================================================================================
5.#include <iostream>
using namespace std;
void prCh(char ch,int rows);
int main(){
for (int i=1;i<5;i++){
prCh (' ',4-i);
prCh ('$',i);
cout<<endl;}
cin.get();
return 0;
}
void prCh(char ch,int rows){
for(int i=1;i<=rows;i++){
cout<<ch;
}
}
answer
$
$$
$$$
$$$$
#include<iostream>
using namespace std;
void prCh(char ch, int rows);
int main()
{
for(int i=0;i<5;i++){
prCh('A',i+1);
prCh('x',i);
cout<<endl;
}
cin.get();
return 0;
}
void prCh(char ch, int rows){
for(int i=1;i<=rows;i++){
cout<<ch;
}
}
A
AAx
AAAxx
AAAAxxx
AAAAAxxxx
=================================================================================
6.
#include <stdio.h>
#include <stdlib.h>
int main()
{
char x[11]="while-loop";
int i=0,n;
scanf("%d",&n);
while(i<n)
{
printf("%s",x);
i++;
}
system("pause");
return 0;
}
====================================================================================
7.
#include <stdio.h>
#include <stdlib.h>
int main()
{
int i,s;
for(i=3;i<=1002;i++);
s+=i*(i++);
printf("%d",s);
system("pause");
return 0;
}
1006052請按任意鍵繼續 . .
1.
#include <cstdlib>
#include <iostream>
using namespace std;
int main ()
{
int x=5,y=3,z,w;
x-=2;
cout<<x++<<"\n";
z=++y;
cout<<z<<"\n";
cout<<y<<"\n";
w=z<<2;
cout<<z<<"\n";
cout<<w<<"\n";
for(x=4;x<10;x++)
{
if (x%2==0)
continue;
cout<<x<<"\n";
if (x==7)
break;
};
cout<<x<<"\n";
system ("pause");
return 0;
}
輸出:
3
4
4
4
16
5
7
7
3.
#include <stdio.h>
#include <stdlib.h>
int main ()
{
int i;
for (i=0;i<7;i++)
{
if(i==0)
printf("i=%d\n",i);
else if (i==1)
printf("i=%d\n",i);
else if (i==2)
printf("i=%d\n",i);
else
printf ("這是期中考\n");
}
printf ("i=%d\n",i++);
system("pause");
return 0;
}
輸出:
i=0
i=1
i=2
這是期中考
這是期中考
這是期中考
i=7
5.
#include <iostream>
using namespace std;
void prCh(char ch, int rows);
int main()
{
for(int i=0;i<5;i++)
{
prCh('A',i+1);
prCh('X',i);
cout<<endl;
}
cin.get();
return 0;
}
void prCh (char ch, int rows)
{
for (int i=1;i<=rows;i++)
{
cout<<ch;
}
}
輸出:
A
AAX
AAAXX
AAAAXXX
AAAAAXXXX
修改後:
#include <iostream>
using namespace std;
void prCh(char ch, int rows);
int main()
{
for(int i=3;i>=0;i--)
{
prCh(' ',i);
prCh('$',4-i);
cout<<endl;
}
cin.get();
return 0;
}
void prCh (char ch, int rows)
{
for (int i=1;i<=rows;i++)
{
cout<<ch;
}
}
輸出:
$
$$
$$$
$$$$
6.
#include <stdio.h>
#include <stdlib.h>
int main ()
{
char x[11]="while-loop";
int i=0,n;
scanf("%d",&n);
while (i<n)
{
printf("%s",x);
i++;
}
system("pause");
return 0;
}
7.
#include <stdio.h>
#include <stdlib.h>
int main()
{
int i,s;
for (i=3;i<=1002;i++)
s=s+i*(i+1);
printf("%d\n",s);
system("pause");
return 0;
}
輸出:
336342057
第一題
#include <iostream>
using namespace std;
int main ()
{
int x=5,y=3,z,w;
x-=2;
cout<<x++<<"\n";
z=++y;
cout<<z<<"\n";
cout<<y<<"\n";
w=z<<2;
cout<<z<<"\n";
cout<<w<<"\n";
for (x=4;x<10;x++)
{
if (x%2==0)
continue;
cout<<x<<"\n";
if(x==7)break;
};
cout<<x<<"\n";
system ("pause");
return 0;
}
輸出:
3
4
4
4
16
5
7
7
第二題
#include <stdio.h>
#include <stdlib.h>
int main ()
{
int j=2,i=0xf;
const double PI=3.1415926536;
printf("[%3x]\n",i);
printf("[%3d]\n",i);
printf("[%3d]\n",j);
printf("[%f]\n",PI);
printf("[%-15.10f]\n",PI);
system("pause");
return 0;
}
輸出:
[ f]
[ 15]
[ 2]
[3.141593]
[3.1415926536 ]
第三題
#include <stdio.h>
#include <stdlib.h>
int main ()
{
int i;
for (i=0;i<7;i++)
{
if(i==0)
printf("i=%d\n",i);
else if (i==1)
printf("i=%d\n",i);
else if (i==2)
printf ("i=%d\n",i);
else
printf("這是期中考\n");
};
printf ("i=%d\n",i++);
system ("pause");
return 0;
}
答案:
i=0
i=1
i=2
這是期中考
這是期中考
這是期中考
這是期中考
i=7
第五題
#include <iostream>
using namespace std;
void prch(char ch, int rows);
int main()
{
for (int i=3;i>=0;i--)
{
prch (' ',i);
prch ('$',4-i);
cout<<endl;
}
cin.get();
return 0;
}
void prch (char ch, int rows)
{
for (int i=1;i<=rows; i++)
{
cout<<ch ;
}
}
輸出答案
&
&&
&&&
&&&&
第六題
#include <stdio.h>
#include <stdlib.h>
int main (){
char x[11]="while-loop";
int i=0,n;
scanf ("%d",&n);
while(i<n){
printf ("%s",x);
i++;
}
system ("pause");
return 0;
}
輸出答案
5
while-loopwhile-loopwhile-loopwhile-loopwhile-loop請按任意鍵繼續 . . .
第七題
#include <stdio.h>
#include <stdlib.h>
int main ()
{
int i,s ;
for (i=3;i<=1002;i++)
s+=i*(i+1);
printf ("%d",s);
system ("pause");
return 0;
}
輸出答案
336342048
1.
#include <iostream>
#include <cstdio>
using namespace std;
int main()
{
int x=5,y=3,w,z;
x-=2;
cout<<x++<<"\n";
z=++y;
cout<<z<<"\n";
cout<<y<<"\n";
w=z<<2;
cout<<z<<"\n";
cout<<w<<"\n";
for(x=4;x<10;x++){
if (x%2==0) continue;
cout<<x<<"\n";
if (x==7) break;
};
cout<<x<<"\n";
system ("pause");
return 0;
}
A:
3
4
4
4
16
5
7
7
---------------------------------------------
2.
#include <stdio.h>
#include <stdlib.h>
int main()
{
int j=2,i=0xf;
const double PI=3.1415926536;
printf("[%3x]\n",i);
printf("[%3d]\n",i);
printf("[%3d]\n",j);
printf("[%f]\n",PI);
printf("[%-15.10f]\n",PI);
system("pause");
return 0;
}
A:
[ f]
[ 15]
[ 2]
[3.141593]
[3.145926536]
---------------------------------------------
3.
#include <stdio.h>
#include <stdlib.h>
int main()
{
int i;
for(i=0;i<7;i++)
{
if(i==0){
printf("i=%d\n",i);
}
else if(i==1){
printf("i=%d\n",i);
}
else if(i==2){
printf("i=%d\n",i);
}
else
printf("這是期中考\n");
};
printf("i=%d\n",i++);
system ("pause");
return 0;
}
A:
i=0
i=1
i=2
這是期中考
這是期中考
這是期中考
這是期中考
i=7
--------------------------------------------
5.
#include <iostream>
using namespace std;
void prCh(char ch,int rows);
int main(){
for (int i=1;i<5;i++){
prCh (' ',4-i);
prCh ('$',i);
cout<<endl;}
cin.get();
return 0;
}
void prCh(char ch,int rows){
for(int i=1;i<=rows;i++){
cout<<ch;
}
}
A:
$
$$
$$$
$$$$
--------------------------------------------
6.
A:
#include <stdio.h>
#include <stdlib.h>
int main()
{
char x[11]="while-loop";
int i=0, n;
scanf("%d",&n);
while(i<=0){
printf("%s",x);
i++;
}
system ("pause");
}
--------------------------------------------
7.
#include <stdio.h>
#include <stdlib.h>
int main()
{
int i,s;
for(i=3;i<=1002;i++)
{
s+=i*(i+1);
}
printf("%d",s);
system ("pause");
return 0;
}
A:
336342049
1.#include <iostream>
using namespace std;
int main(){
int x=5,y=3,z,w;
x-=2;
cout<<x++<<"\n";
z=++y;
cout<<z<<"\n";
cout<<y<<"\n";
w=z<<2;
cout<<z<<"\n";
cout<<w<<"\n";
for(x=4;x<10;x++){
if(x%2==0) continue;
cout<<x<<"\n";
if(x==7) break;
};
cout<<x<<"\n";
system ("pause");
return 0;
}
answer
3
4
4
4
16
5
7
7
請按任意鍵繼續 . . .
=================================================================================
2.
#include <stdio.h>
#include <stdlib.h>
int main()
{
int j=2,i=0xf;
const double PI=3.1415926536;
printf("[%3x]\n",i);
printf("[%3d]\n",i);
printf("[%3x]\n",j);
printf("[%f]\n",PI);
printf("[%-15.10f]\n",PI);
system("pause");
return 0;
}
answer
[ f]
[ 15]
[ 1]
[3.141593]
[3.141592636 ]
=================================================================================
3.#include <stdio.h>
#include <stdlib.h>
int main(){
int i;
for(i=0;i<7;i++)
{
if(i==0){
printf("i=%d\n",i);}
else if(i==1){
printf("i=%d\n",i);}
else if(i==2){
printf("i=%d\n",i);}
else printf("這是期中考\n",i);}
printf("i=%d\n",i++);
system ("pause");
return 0;
}
answer
i=0
i=1
i=2
這是期中考
這是期中考
這是期中考
這是期中考
i=7
請按任意鍵繼續 . .
================================================================================
5.#include <iostream>
using namespace std;
void prCh(char ch,int rows);
int main(){
for (int i=1;i<5;i++){
prCh (' ',4-i);
prCh ('$',i);
cout<<endl;}
cin.get();
return 0;
}
void prCh(char ch,int rows){
for(int i=1;i<=rows;i++){
cout<<ch;
}
}
answer
$
$$
$$$
$$$$
=================================================================================
6.
#include <stdio.h>
#include <stdlib.h>
int main()
{
char x[11]="while-loop";
int i=0, n;
scanf("%d",&n);
while(i<n)
{
printf("%s",x);
i++;
}
system("pause");
return 0;
}
=================================================================================
7.
#include <stdio.h>
#include <stdlib.h>
int main()
{
int i,s;
for(i=3;i<=1002;i++)
{
s=s+i*(i+1);
}
printf("%d\n",s);
system("pause");
return 0;
}
answer
336342043
1.
#include <iostream>
using namespace std;
int main(){
int x=5,y=3,z,w;
x-=2;
cout<<x++<<"\n";
z=++y;
cout<<z<<"\n";
cout<<y<<"\n";
w=z<<2;
cout<<z<<"\n";
cout<<w<<"\n";
for(x=4;x<10;x++){
if(x%2==0) continue;
cout<<x<<"\n";
if(x==7) break;
};
cout<<x<<"\n";
system ("pause");
return 0;
}
answer
3
4
4
4
16
5
7
7
請按任意鍵繼續 . . .
2.
#include <stdio.h>
#include <stdlib.h>
int main()
{
int j=2,i=0xf;
const double PI=3.1415926536;
printf("[%3x]\n",i);
printf("[%3d]\n",i);
printf("[%3d]\n",j);
printf("[%f]\n",PI);
printf("[%-15.10f]\n",PI);
system("pause");
return 0;
}
answer
[ f]
[ 15]
[ 2]
[3.141593]
[3.1415926536]
請按任意鍵繼續...
=================================================================================
3.
#include <stdio.h>
#include <stdlib.h>
int main(){
int i;
for(i=0;i<7;i++)
{
if(i==0){
printf("i=%d\n",i);}
else if(i==1){
printf("i=%d\n",i);}
else if(i==2){
printf("i=%d\n",i);}
else printf("這是期中考\n",i);}
printf("i=%d\n",i++);
system ("pause");
return 0;
}
answer
i=0
i=1
i=2
這是期中考
這是期中考
這是期中考
這是期中考
i=7
請按任意鍵繼續 . . .
================================================================================
5-1
#include<iostream>
using namespace std;
void prCh(char ch, int rows);
int main()
{
for(int i=0;i<5;i++){
prCh('A',i+1);
prCh('x',i);
cout<<endl;
}
cin.get();
return 0;
}
void prCh(char ch, int rows){
for(int i=1;i<=rows;i++){
cout<<ch;
}
}
answer
A
AAXX
AAAXXX
AAAAXXXX
================================================================================
5-2.
#include <iostream>
using namespace std;
void prCh(char ch,int rows);
int main(){
for (int i=1;i<5;i++){
prCh (' ',4-i);
prCh ('$',i);
cout<<endl;}
cin.get();
return 0;
}
void prCh(char ch,int rows){
for(int i=1;i<=rows;i++){
cout<<ch;
}
}
answer
$
$$
$$$
$$$$
=================================================================================
6.
#include <stdio.h>
#include <stdlib.h>
int main()
{
char x[11]="while-loop";
int i=0,n;
scanf("%d",&n);
while(i<n)
{
printf("%s",x);
i++;
}
system("pause");
return 0;
}
=================================================================================
7.
#include <stdio.h>
#include <stdlib.h>
int main()
{
int i,s;
for(i=3;i<=1002;i++);
s+=i*(i++);
printf("%d",s);
system("pause");
return 0;
}
answer
1006052請按任意鍵繼續 . . .
1.
#include<cstdlib>
#include<iostream>
using namespace std;
int main()
{
int x=5,y=3,z,w;
x-=2;
cout<<x++<<"\n";
z=++y;
cout<<z<<"\n";
cout<<y<<"\n";
w=z<<2;
cout<<z<<"\n";
cout<<w<<"\n";
for(x=4;x<10;x++){
if(x%2==0)continue;
cout<<x<<"\n";
if(x==7)break;
};
cout<<x<<"\n";
system("pause");
return 0;
}
輸出:
3
4
4
4
16
5
7
7
3.
#include<stdio.h>
#include<stdlib.h>
int main()
{
int i;
for(i=0;i<7;i++)
{
if(i==0)
printf("i=%d\n",i);
else if(i==1)
printf("i=%d\n",i);
else if(i==2)
printf("i=%d\n",i);
else
printf("這是期中考\n");
};
printf("i=%d\n",i++);
system("pause");
return 0;
}
輸出:
i=0
i=1
i=2
這是期中考
這是期中考
這是期中考
這是期中考
i=7
6.
#include<stdio.h>
#include<stdlib.h>
int main(){
char x[11]="while-loop";
int i=0, n;
scanf("%d",&n);
while(i<n){
printf("%s", x);
i++;
}
system("pause");
return 0;
}
輸出:
5
while-loopwhile-loopwhile-loopwhile-loopwhile-loop
#include<cstdlib>
#include<iostream>
using namespace std;
int main()
{
int x=5,y=3,z,w;
x=-2;
cout<<x++<<"\n";
z=++y;
cout<<z<<"\n";
cout<<y<<"\n";
w=z<<2;
cout<<z<<"\n";
cout<<w<<"\n";
for(x=4;x<10;x++)
{
if (x%2==0) continue;
cout<<x<<"\n";
if (x==7) break;
}
cout<<x<<"\n";
system ("pause");
return 0;
}
題目1:
#include <cstdlib>
#include <iostream>
using namespace std;
int main (){
int x=5, y=3,z,w;
x-=2;
cout<<x++<<"\n";
z=++y;
cout<<z<<"\n";
cout<<y<<"\n";
w=z<<2;
cout<<z<<"\n";
cout<<w<<"\n";
for (x=4;x<10;x++){
if (x%2==0) continue;
cout<<x<<"\n";
if (x==7) break;
};
cout<<x<<"\n";
system ("pause");
return 0;
}
ANS:
3
4
4
4
16
5
7
7
請按任意鍵繼續 . . .
題目2:
#include <stdio.h>
#include <stdlib.h>
int main ()
{
int j=2,i=0xf;
const double PI=3.1415926536;
printf("[%3x]\n",i);
printf("[%3d]\n",i);
printf("[%3d]\n",j);
printf("[%f]\n",PI);
printf("[%-15.10f]\n",PI);
system ("PAUSE");
return 0;
}
ANS:
[ f]
[ 15]
[ 2]
[3.141593]
[3.1415926536 ]
請按任意鍵繼續 . . .
題目3:
#include <stdio.h>
#include <stdlib.h>
int main ()
{
int i;
for (i=0;i<7;i++)
{
if (i==0)
{
printf("i=%d\n",i);
}
else if (i==1)
{
printf("i=%d\n",i);
}
else if (i==2)
{
printf("i=%d\n",i);
}
else
{
printf("這是期中考\n");
};
};
printf("i=%d\n",i++);
system ("pause");
return 0;
}
ANS:
i=0
i=1
i=2
這是期中考
這是期中考
這是期中考
這是期中考
i=7
請按任意鍵繼續 . . .
題目六:
#include <stdio.h>
#include <stdlib.h>
int main ()
{
char x[11]="while-loop";
int i=0,n;
scanf("%d",&n);
while(i<n){
printf("%s",x);
i++;
}
system ("PAUSE");
return 0;
}
ANS:
5
while-loopwhile-loopwhile-loopwhile-loopwhile-loop請按任意鍵繼續 . . .
1.
#include <iostream>
#include <cstdio>
using namespace std;
int main()
{
int x=5,y=3,z,w;
x-=2;
cout<<x++<<"\n";
z=++y;
cout<<z<<"\n";
cout<<y<<"\n";
w=z<<2;
cout<<z<<"\n";
cout<<w<<"\n";
for(x=4;x<10;x++){
if (x%2==0) continue;
cout<<x<<"\n";
if(x==7) break;
};
cout<<x<<"\n";
system ("Pause");
return 0;
}
3
4
4
4
16
5
7
7
請按任意鍵繼續 . . .
------------------------------------------------------------------------------------
2.
#include <stdio.h>
#include <stdlib.h>
int main()
{
int j=2,i=0xf;
const double PI=3.1415926536;
printf("[%3x]\n",i);
printf("[%3d]\n",i);
printf("[%3d]\n",j);
printf("[%f]\n",PI);
printf("[%-15.10f]\n",PI);
system("Pause");
return 0;
}
[ f]
[ 15]
[ 2]
[3.141593]
[3.1415926536 ]
請按任意鍵繼續 . . .
----------------------------------------------------------------------------------------
3.
#include <stdio.h>
#include <stdlib.h>
int main(){
int i;
for(i=0;i<7;i++)
{
if(i==0){
printf("i=%d\n",i);}
else if(i==1){
printf("i=%d\n",i);}
else if(i==2){
printf("i=%d\n",i);}
else printf("這是期中考\n",i);}
printf("i=%d\n",i++);
system ("pause");
return 0;
}
i=0
i=1
i=2
這是期中考
這是期中考
這是期中考
這是期中考
i=7
請按任意鍵繼續 . . .
-----------------------------------------------------------------------------------
5.
#include <iostream>
using namespace std;
void prCh(char ch,int rows);
int main(){
for (int i=1;i<5;i++){
prCh (' ',4-i);
prCh ('$',i);
cout<<endl;}
cin.get();
return 0;
}
void prCh(char ch,int rows){
for(int i=1;i<=rows;i++){
cout<<ch;
}
}
$
$$
$$$
$$$$
---------------------------------------------------------------------------------------
6.
#include <stdio.h>
#include <stdlib.h>
int main()
{
char x[11]="while-loop";
int i=0, n;
scanf("%d",&n);
while(i<=0){
printf("%s",x);
i++;
}
system ("pause");
}
-----------------------------------------------------------------------------------------
7.
#include <stdio.h>
#include <stdlib.h>
int main()
{
int i=3,s;
for(i=3;i<=1002;i++)
s+=i*(i+1);
printf("%d\n",s);
system("Pause");
return 0;
}
336342049
請按任意鍵繼續 . . .
1.
#include <cstdio>
#include <iostream>
using namespace std;
int main()
{
int x=5,y=3,z,w;
x-=2;
cout<<x++<<"\n";
z=++y;
cout<<z<<"\n";
cout<<y<<"\n";
w=z<<2;
cout<<z<<"\n";
cout<<w<<"\n";
for (x=4;x<10;x++)
{
if(x%2==0) continue;
cout<<x<<"\n";
if(x==7) break;
};
cout<<x<<"\n";
system("pause");
return 0;
}
3
4
4
4
16
5
7
7
2.
#include <iostream>
using namespace std;
int main()
{
int j=2,i=0xf;
const double PI=3.1415926536;
printf("[%3x]\n",i);
printf("[%3d]\n",i);
printf("[%3d]\n",j);
printf("[%f]\n",PI);
printf("[%-15.10f]\n",PI);
system("pause");
return 0;
}
[ f]
[ 15]
[ 2]
[3.141593]
[3.14159026536 ]
5.
修改前
#include <iostream>
using namespace std;
void prCh(char ch, int rows);
int main()
{
for (int i=0 ;i<5;i++)
{
prCh('A',i+1);
prCh('X',i);
cout<<endl;
}
cin.get();
return 0;
}
void prCh(char ch,int rows)
{
for (int i=1;i<=rows;i++)
{
cout<<ch;
}
}
A
AAX
AAAXX
AAAAXXX
AAAAAXXXX
修改後
#include <iostream>
using namespace std;
void prCh(char ch, int rows);
int main()
{
for (int i=0 ;i<=3;i++)
{
prCh(' ',3-i);
prCh('$',1+i);
cout<<endl;
}
cin.get();
return 0;
}
void prCh(char ch,int rows)
{
for (int i=1;i<=rows;i++)
{
cout<<ch;
}
}
$
$$
$$$
$$$$
6.
#include <stdio.h>
#include <stdlib.h>
int main()
{
char x[11]="while-loop";
int i=0,n;
scanf("%d",&n);
while(i<n)
{
printf("%s",x);
i++;
}
system("pause");
return 0;
}
7.
#include<stdio.h>
#include<stdlib.h>
int main()
{
int i,s=0;
for (i=3;i<=1002;i++)
{
s+=i*(i+1);
}
printf("%d\n",s);
system("pause");
return 0;
}
336342000
1.
#include <iostream>
#include <cstdlib>
using namespace std;
int main()
{
int x=5,y=3,z,w;
x-=2;
cout<<x++<<"\n";
z=++y;
cout<<z<<"\n";
cout<<y<<"\n";
w=z<<2;
cout<<z<<"\n";
cout<<w<<"\n";
for(x=4;x<10;x++)
{
if (x%2==0) continue;
cout<<x<<"\n";
if (x==7) break;
};
cout<<x<<"\n";
system("pause");
return 0;
}
答:
3
4
4
4
16
5
7
7
2.
#include <stdio.h>
#include <stdlib.h>
int main()
{
int j=2,i=0xf;
const double PI=3.1415926536;
printf("[%3x]\n",i);
printf("[%3d]\n",i);
printf("[%3x]\n",j);
printf("[%f]\n",PI);
printf("[%-15.10f]\n",PI);
system("pause");
return 0;
}
答:
[00f]
[015]
[002]
[3.141593]
[3.141592636000]
3.
#include <stdio.h>
#include <stdlib.h>
int main()
{
int i;
for(i=0;i<7;i++)
{
if(i==0)
{
printf("i=%d\n",i);
}
else if (i==1)
{
printf("i=%d\n",i);
}
else if (i==2)
{
printf("i=%d\n",i);
}
else
{
printf("這是期中考\n");
}
};
printf("i=%d\n",i++);
system("pause");
return 0;
}
答:
i=0
i=1
i=2
這是期中考
這是期中考
這是期中考
這是期中考
i=7
5.
#include <iostream>
using namespace std;
void prCh(char ch, int rows);
int main()
{
for(int i=0;i<5;i++)
{
prCh('A',i+1);
prCh('X',i);
cout<<endl;
}
cin.get();
return 0;
}
void prCh(char ch, int rows){
for(int i=1;i<=rows;i++){
cout<<ch;
}
}
答:
A
AAX
AAAXX
AAAAXXX
AAAAAXXXX
↓
改寫:
#include <iostream>
using namespace std;
void prCh(char ch, int rows);
int main()
{
prCh(' ',3);
prCh('$',1);
cout<<endl;
prCh(' ',2);
prCh('$',2);
cout<<endl;
prCh(' ',1);
prCh('$',3);
cout<<endl;
prCh('$',4);
cout<<endl;
cin.get();
return 0;
}
void prCh(char ch, int rows){
for(int i=1;i<=rows;i++){
cout<<ch;
}
}
輸出:
$
$$
$$$
$$$$
6.
#include <stdio.h>
#include <stdlib.h>
int main()
{
char x[11]="while-loop";
int i=0, n;
scanf("%d,&n");
while(i>=0)
{
printf("%s",x);
i++;
}
system("pause");
return 0;
7.
#include <stdio.h>
#include <stdlib.h>
int main()
{
int i,s;
for(i=3;i<=1002;i++)
s+=i*(i+1);
printf("%d",s);
system("pause");
return 0;
}
一、
#include <iostream>
#include <cstdlib>
using namespace std;
int main(){
int x=5,y=3,z,w;
x-=2;
cout<<x++<<"\n";
z=++y;
cout<<z<<"\n";
cout<<y<<"\n";
w=z<<2;
cout<<z<<"\n";
for(x=4;x<10;x++)
{
if (x%2==0) continue;
cout<<x<<"\n";
if (x==7) break;
}
cout<<x<<"\n";
system("pause");
return 0;
}
3
4
4
4
5
7
7
--------------------------------
二、
#include <stdio.h>
#include <stdlib.h>
int main()
{
int j=2,i=0xf;
const double PI=3.1415926536;
printf("[%3x]\n",i);
printf("[%3d]\n",i);
printf("[%3d]\n",j);
printf("[%f]\n",PI);
printf("[%-15.10f]\n",PI);
system("pause");
return 0;
}
[ f]
[ 15]
[ 2]
[3.141593]
[3.1415926536 ]
---------------------------------
三、
#include <stdio.h>
#include <stdlib.h>
int main()
{
int i;
for(i=0;i<7;i++)
{
if(i==0)
printf("i=%d\n",i);
else if(i==1)
printf("i=%d\n",i);
else if(i==2)
printf("i=%d\n",i);
else
printf("這是期中考\n");
};
printf("i=%d\n",i++);
system("pause");
return 0;
}
i=0
i=1
i=2
這是期中考
這是期中考
這是期中考
這是期中考
i=7
---------------------------------
四、
#include <iostream>
#include <cstdlib>
#include <math.h>
using namespace std;
int Prime[]={2,3,5,11,13,17,19,23};
bool isPrimebelow400(int n)
{
int n_sqrt=(int)sqrt((double)n);
for (int i=0; Prime[i]<=n_sqrt; i++)
{
if (n%Prime[i]==0 && n>Prime[i])
return 0;
}
return 1;
}
int main(){
for(int i=2;i<=400;i++)
{
if(isPrimebelow400(i))
cout<<i<<'\t';
}
system("pause");
return 0;
}
2 3 5 7 11 13 17 19 23 29
31 37 41 43 47 49 53 59 61 67
71 73 77 79 83 89 91 97 101 103
107 109 113 119 127 131 133 137 139 149
151 157 161 163 167 173 179 181 191 193
197 199 203 211 217 223 227 229 233 239
241 251 257 259 263 269 271 277 281 283
287 293 301 307 311 313 317 329 331 337
343 347 349 353 359 367 371 373 379 383
389 397
-------------------------------------------------------------------------
五、
#include <iostream>
#include <cstdlib>
using namespace std;
void prCh(char ch, int rows);
int main()
{
for(int i=0;i<5;i++){
prCh('A',i+1);
prCh('X',i);
cout<<endl;
}
cin.get();
return 0;
}
void prCh(char ch, int rows){
for(int i=1;i<=rows;i++){
cout<<ch;
}
}
A
AAX
AAAXX
AAAAXXX
AAAAAXXXX
改:
#include <iostream>
#include <cstdlib>
using namespace std;
void prCh(char ch, int rows);
int main()
{
for(int i=3;i>=0;i--){
prCh(' ',i);
prCh('$',4-i);
cout<<endl;
}
cin.get();
return 0;
}
void prCh(char ch, int rows){
for(int i=1;i<=rows;i++){
cout<<ch;
}
}
$
$$
$$$
$$$$
------------------------------------------
六、
char x[11]="while-loop";
int i=0,n;
scanf("%d",&n);
while(i<n){
printf("%s",x);
i++;
}
system("pause")
-------------------------------------------
七、
#include <stdio.h>
#include <stdlib.h>
int main()
{
int s,i;
for(i=3;i<=1002;i++)
s+=i*(i+1);
printf("%d\n",s);
system("pause");
return 0;
}
336342002
1.
#include <cstdlib>
#include <iostream>
using namespace std;
int main()
{
int x=5,y=3,z,w;
x-=2;
cout<<x++<<"\n";
z=++y;
cout<<z<<"\n";
cout<<y<<"\n";
w=z<<2;
cout<<z<<"\n";
cout<<w<<"\n";
for(x=4;x<10;x++){
if (x%2==0) continue;
cout<<x<<"\n";
if (x==7) break;
};
cout<<x<<"\n";
system("pause");
return 0;
}
3
4
4
4
16
5
7
7
3.
#include <cstdlib>
#include <iostream>
using namespace std;
int main()
{
int i;
for (i=0;i<7;i++)
{
if(i==0){
printf("i=%d\n",i);}
else if (i==1){
printf("i=%d\n",i);}
else if (i==2){
printf("i=%d\n",i);}
else
printf("這是期中考\n");
};
printf("i=%d\n",i++);
system("pause");
return 0;
}
i=0
i=1
i=2
這是期中考
這是期中考
這是期中考
這是期中考
i=7
5.
修改前
#include <iostream>
using namespace std;
void prCh(char ch, int rows);
int main()
{
for(int i=0;i<5;i++)
{
prCh('A',i+1);
prCh('X',i);
cout<<endl;
}
cin.get();
return 0;
}
void prCh(char ch, int rows){
for (int i=1; i<=rows; i++){
cout<<ch;
}
}
A
AAX
AAAXX
AAAAXXX
AAAAAXXXX
修改後
#include <iostream>
using namespace std;
void prCh(char ch, int rows);
int main()
{
for(int i=3;i>=0;i--)
{
prCh(' ',i);
prCh('$',4-i);
cout<<endl;
}
cin.get();
return 0;
}
void prCh(char ch, int rows){
for (int i=1; i<=rows; i++){
cout<<ch;
}
}
$
$$
$$$
$$$$
6.
#include <stdio.h>
#include <stdlib.h>
int main()
{
char x[11]="while-loop";
int i=0,n;
scanf("%d",&n);
while (i<n)
{
printf("%s",x);
i++;
}
system("pause");
return 0;
}
7.
#include <stdio.h>
#include <stdlib.h>
int main()
{
int i,s ;
s=0;
for(int i=3;i<=1002;i++)
s=s+i*(i+1);
printf("%d\n",s);
system("pause");
return 0;
}
336342000
一
#include <iostream>
using namespace std;
int main ()
{
int x=5,y=3,z,w;
x-=2;
cout<<x++<<"\n";
z=++y;
cout<<z<<"\n";
cout<<y<<"\n";
w=z<<2;
cout<<z<<"\n";
cout<<w<<"\n";
for (x=4;x<10;x++)
{
if (x%2==0)
continue;
cout<<x<<"\n";
if(x==7)break;
};
cout<<x<<"\n";
system ("pause");
return 0;
}
輸出:
3
4
4
4
16
5
7
7
二
#include <stdio.h>
#include <stdlib.h>
int main ()
{
int j=2,i=0xf;
const double PI=3.1415926536;
printf("[%3x]\n",i);
printf("[%3d]\n",i);
printf("[%3d]\n",j);
printf("[%f]\n",PI);
printf("[%-15.10f]\n",PI);
system("pause");
return 0;
}
輸出:
[ f]
[ 15]
[ 2]
[3.141593]
[3.1415926536 ]
三
#include <stdio.h>
#include <stdlib.h>
int main ()
{
int i;
for (i=0;i<7;i++)
{
if(i==0)
printf("i=%d\n",i);
else if (i==1)
printf("i=%d\n",i);
else if (i==2)
printf ("i=%d\n",i);
else
printf("這是期中考\n");
};
printf ("i=%d\n",i++);
system ("pause");
return 0;
}
答案:
i=0
i=1
i=2
這是期中考
這是期中考
這是期中考
這是期中考
i=7
五
#include <iostream>
using namespace std;
void prch(char ch, int rows);
int main()
{
for (int i=3;i>=0;i--)
{
prch (' ',i);
prch ('$',4-i);
cout<<endl;
}
cin.get();
return 0;
}
void prch (char ch, int rows)
{
for (int i=1;i<=rows; i++)
{
cout<<ch ;
}
}
輸出答案
&
&&
&&&
&&&&
六
#include <stdio.h>
#include <stdlib.h>
int main (){
char x[11]="while-loop";
int i=0,n;
scanf ("%d",&n);
while(i<n){
printf ("%s",x);
i++;
}
system ("pause");
return 0;
}
輸出答案
5
while-loopwhile-loopwhile-loopwhile-loopwhile-loop請按任意鍵繼續 . . .
七
#include <stdio.h>
#include <stdlib.h>
int main ()
{
int i,s ;
for (i=3;i<=1002;i++)
s+=i*(i+1);
printf ("%d",s);
system ("pause");
return 0;
}
輸出答案
336342048
#include <cstlib>
#include<isotream>
using namespace std;
int main()
{
int x=5,y=3,z,w;
x-=2;
cout<<x++<<"\n";
z=++y;
cout<<z++<<"\n";
cout<<y<<"\n";
w=z<<2;
cout<<z<<"\n";
cout<<w<<"\n";
for(x=4;x<10;x++)
{
if(x%2==0)
contine;
cout<<x<<"\n";
if(x==7)
break;
};
cout<<x<<"\n";
system("pause");
return 0;
}
ans
3
4
4
4
16
5
7
7
#include <stdio.h>
#include<stdlib.h>
int main()
{
int j=2, i=oxf;
const double PI3.1415926536;
printf("[%3x]\n",i);
printf("[%3d]\n",i);
printf("[%3d]\n",j);
printf("[%3f]\n",PI);
printf("[%-15.10F]\n",PI);
system("pause");
return 0;
}
ans
[--f]
[-15]
[--2]
[3.141593]
[3.1415926536---]
#include <stdio.h>
#include <stdlib.h>
int main()
{
int i;
for (i=0;i<7;j++)
{
if (i==0)
printf("i=%d\n",i);
else if (i==1)
printf("i=%d\n",i);
else if (i==2)
printf("i=%d\n",i);
else
printf("這是期中考\n")
ans
i=0
i=1
i=2
這是期中考
這是期中考
這是期中考
這是期中考
i=7
#include <cstdlib>
#include <iostream>
using namespace std;
void prCh(char ch, int rows);
int main()
{
for(int i=4; i<0;i--){
prCh(' ',i-1);
prCh('$',5);}
cout<<endl;
}
cin.get();
return 0;
}
void prCh(char ch, int rows){
for(int i=1;i<=rows; i++){
cout<<ch;
}
}
ans
---$
--$$
-$$$
$$$$
#include <stdio.h>
#include <stdlib.h>
int main()
{
char x[11]="chile-loop";
int i=0,n;
scanf("%d",&n);
while(i>=0){
printf("%s",x);
i++;
}
system("pause");
return 0;
}
1.
#include<cstdlib>
#include<iostream>
using namespace std;
int main()
{
int x=5,y=3,z,w;
x-=2;
cout<<x++<<"\n";
z=++y;
cout<<z<<"\n";
cout<<y<<"\n";
w=z<<2;
cout<<z<<"\n";
cout<<w<<"\n";
for(x=4;x<10;x++){
if(x%2==0)continue;
cout<<x<<"\n";
if(x==7)break;
};
cout<<x<<"\n";
system("pause");
return 0;
}
ans:
3
4
4
4
16
5
7
7
2.
#include<stdio.h>
#include<stdlib.h>
int main()
{
int j=2,i=0xf;
const double PI=3.1415926536;
printf("[%3x]\n",i);
printf("[%3d]\n",i);
printf("[%3d]\n",j);
printf("[%f]\n",PI);
printf("[%-15.10f]\n",PI);
system("pause");
return 0;
}
ans:
[ f]
[ 15]
[ 2]
[3.141593]
[3.1415926536]
3.
#include<stdio.h>
#include<stdlib.h>
int main()
{
int i;
for(i=0;i<7;i++)
{
if(i==0)
{
printf("i=%d\n",i);
}
else if(i==1)
{
printf("i=%d\n",i);
}
else if(i==2)
{
printf("i=%d\n",i);
}
else
{
printf("這是期中考\n");
}
}
printf("i=%d\n",i++);
system("pause");
return 0;
}
ans:
i=0
i=1
i=2
這是期中考
這是期中考
這是期中考
這是期中考
i=7
5.
(1)
#include<iostream>
using namespace std;
void prCh(char ch,int rows);
int main()
{
for(int i=0;i<=5;i++)
{
prCh('A',i+1);
prCh('X',i);
cout<<endl;
}
cin.get();
return 0;
}
void prCh(char ch,int rows)
{
for(int i=1;i<=rows;i++)
{
cout<<ch;
}
}
ans:
A
AAX
AAAXX
AAAAXXX
AAAAAXXXX
AAAAAAXXXXX
(2)
#include<iostream>
using namespace std;
void prCh(char ch,int rows);
int main()
{
for(int i=3;i>=0;i--)
{
prCh(' ',i);
prCh('$',4-i);
cout<<endl;
}
cin.get();
return 0;
}
void prCh(char ch,int rows)
{
for(int i=1;i<=rows;i++)
{
cout<<ch;
}
}
ans:
$
$$
$$$
$$$$
6.
#include<stdio.h>
#include<stdlib.h>
int main()
{
char x[11]="while-loop";
int i=0,n;
scanf("%d",&n);
while(i<n)
{
printf("%s",x);
i++;
}
system("pause");
return 0;
}
7.#include<stdio.h>
#include<stdlib.h>
int main()
{
int i,s;
s=0;
for(i=3;i<=1002;i++)
s=s+i*(i+1);
printf("%d",s);
system("pause");
return 0;
}
一、
#include <iostream>
#include <cstdlib>
using namespace std;
int main(){
int x=5,y=3,z,w;
x-=2;
cout<<x++<<"\n";
z=++y;
cout<<z<<"\n";
cout<<y<<"\n";
w=z<<2;
cout<<z<<"\n";
for(x=4;x<10;x++)
{
if (x%2==0) continue;
cout<<x<<"\n";
if (x==7) break;
}
cout<<x<<"\n";
system("pause");
return 0;
}
3
4
4
4
5
7
7
--------------------------------
二、
#include <stdio.h>
#include <stdlib.h>
int main()
{
int j=2,i=0xf;
const double PI=3.1415926536;
printf("[%3x]\n",i);
printf("[%3d]\n",i);
printf("[%3d]\n",j);
printf("[%f]\n",PI);
printf("[%-15.10f]\n",PI);
system("pause");
return 0;
}
[ f]
[ 15]
[ 2]
[3.141593]
[3.1415926536 ]
---------------------------------
三、
#include <stdio.h>
#include <stdlib.h>
int main()
{
int i;
for(i=0;i<7;i++)
{
if(i==0)
printf("i=%d\n",i);
else if(i==1)
printf("i=%d\n",i);
else if(i==2)
printf("i=%d\n",i);
else
printf("這是期中考\n");
};
printf("i=%d\n",i++);
system("pause");
return 0;
}
i=0
i=1
i=2
這是期中考
這是期中考
這是期中考
這是期中考
i=7
---------------------------------
四、
#include <iostream>
#include <cstdlib>
#include <math.h>
using namespace std;
int Prime[]={2,3,5,11,13,17,19,23};
bool isPrimebelow400(int n)
{
int n_sqrt=(int)sqrt((double)n);
for (int i=0; Prime[i]<=n_sqrt; i++)
{
if (n%Prime[i]==0 && n>Prime[i])
return 0;
}
return 1;
}
int main(){
for(int i=2;i<=400;i++)
{
if(isPrimebelow400(i))
cout<<i<<'\t';
}
system("pause");
return 0;
}
2 3 5 7 11 13 17 19 23 29
31 37 41 43 47 49 53 59 61 67
71 73 77 79 83 89 91 97 101 103
107 109 113 119 127 131 133 137 139 149
151 157 161 163 167 173 179 181 191 193
197 199 203 211 217 223 227 229 233 239
241 251 257 259 263 269 271 277 281 283
287 293 301 307 311 313 317 329 331 337
343 347 349 353 359 367 371 373 379 383
389 397
-------------------------------------------------------------------------
五、
#include <iostream>
#include <cstdlib>
using namespace std;
void prCh(char ch, int rows);
int main()
{
for(int i=0;i<5;i++){
prCh('A',i+1);
prCh('X',i);
cout<<endl;
}
cin.get();
return 0;
}
void prCh(char ch, int rows){
for(int i=1;i<=rows;i++){
cout<<ch;
}
}
A
AAX
AAAXX
AAAAXXX
AAAAAXXXX
改:
#include <iostream>
#include <cstdlib>
using namespace std;
void prCh(char ch, int rows);
int main()
{
for(int i=3;i>=0;i--){
prCh(' ',i);
prCh('$',4-i);
cout<<endl;
}
cin.get();
return 0;
}
void prCh(char ch, int rows){
for(int i=1;i<=rows;i++){
cout<<ch;
}
}
$
$$
$$$
$$$$
------------------------------------------
六、
char x[11]="while-loop";
int i=0,n;
scanf("%d",&n);
while(i<n){
printf("%s",x);
i++;
}
system("pause")
-------------------------------------------
七、
#include <stdio.h>
#include <stdlib.h>
int main()
{
int s,i;
for(i=3;i<=1002;i++)
s+=i*(i+1);
printf("%d\n",s);
system("pause");
return 0;
}
336342002
1.
#include <iostream>
#include <cstdlib>
using namespace std;
int main()
{
int x=5,y=3,z,w;
x-=2;
cout<<x++<<"\n";
z=++y;
cout<<z<<"\n";
cout<<y<<"\n";
w=z<<2;
cout<<z<<"\n";
cout<<w<<"\n";
for(x=4;x<10;x++){
if (x%2==0) continue;
cout<<x<<"\n";
if (x==7) break;
};
cout<<x<<"\n;
system("pause");
return 0;
}
輸出:3
4
4
4
16
5
7
7
2.
#include<stdio.h>
#include<stdlib.h>
int main()
{
int j=2,i=0xf;
const double PI=3.1415926536;
printf("[%3x]\n",i);
printf("[%3d]\n",i);
printf("[%3d]\n",j);
printf("[%f]\n",PI);
printf("[%-15.10f]\n",PI);
system("pause");
return 0;
}
輸出:
0當空格
[00f]
[015]
[002]
[3.141593]
[3.1415926536000]
3.
#include<stdio.h>
#include<stdlib.h>
int main()
{
int i;
for (i=0;i<7;i++)
{
if (i==0)
printf("i=%d\n",i);
else if (i==1)
printf("i=%d\n",i);
else if (i==2)
printf("i=%d\n",i);
else
printf("這是期中考\n");
};
printf("i=%d\n",i++);
system("pause");
return 0;
}
輸出:
i=0
i=1
i=2
這是期中考
這是期中考
這是期中考
這是期中考
i=7
5.
#include <iostream>
using namespace std;
void prCh(char ch, int rows);
int main()
{
for(int i=4;i<0;i--){
prCh('_',i-1);
prCh('$',5-i);
cout<<endl;}
cin.get();
return 0;}
void prCh(char ch, int rows){
for (int i=1; i<=rows; i++){
cout<<ch;
}
}
輸出: 原程式輸出:
---$ A
--$$ AAX
-$$$ AAAXX
$$$$ AAAAXXX
AAAAAXXXX
6.
#include <stdio.h>
#include <stdlib.h>
int main()
{
char x[11]="while-loop";
int i=0,n;
scanf("%d",&n);
while(i>=0){
printf("%s",x);
i++;
}
system("pause");
return 0; }
一
#include <iostream>
using namespace std;
int main ()
{
int x=5,y=3,z,w;
x-=2;
cout<<x++<<"\n";
z=++y;
cout<<z<<"\n";
cout<<y<<"\n";
w=z<<2;
cout<<z<<"\n";
cout<<w<<"\n";
for (x=4;x<10;x++)
{
if (x%2==0)
continue;
cout<<x<<"\n";
if(x==7)break;
};
cout<<x<<"\n";
system ("pause");
return 0;
}
輸出:
3
4
4
4
16
5
7
7
二
#include <stdio.h>
#include <stdlib.h>
int main ()
{
int j=2,i=0xf;
const double PI=3.1415926536;
printf("[%3x]\n",i);
printf("[%3d]\n",i);
printf("[%3d]\n",j);
printf("[%f]\n",PI);
printf("[%-15.10f]\n",PI);
system("pause");
return 0;
}
輸出:
[ f]
[ 15]
[ 2]
[3.141593]
[3.1415926536 ]
三
#include <stdio.h>
#include <stdlib.h>
int main ()
{
int i;
for (i=0;i<7;i++)
{
if(i==0)
printf("i=%d\n",i);
else if (i==1)
printf("i=%d\n",i);
else if (i==2)
printf ("i=%d\n",i);
else
printf("這是期中考\n");
};
printf ("i=%d\n",i++);
system ("pause");
return 0;
}
答案:
i=0
i=1
i=2
這是期中考
這是期中考
這是期中考
這是期中考
i=7
五
#include <iostream>
using namespace std;
void prch(char ch, int rows);
int main()
{
for (int i=3;i>=0;i--)
{
prch (' ',i);
prch ('$',4-i);
cout<<endl;
}
cin.get();
return 0;
}
void prch (char ch, int rows)
{
for (int i=1;i<=rows; i++)
{
cout<<ch ;
}
}
輸出答案
&
&&
&&&
&&&&
六
#include <stdio.h>
#include <stdlib.h>
int main (){
char x[11]="while-loop";
int i=0,n;
scanf ("%d",&n);
while(i<n){
printf ("%s",x);
i++;
}
system ("pause");
return 0;
}
輸出答案
5
while-loopwhile-loopwhile-loopwhile-loopwhile-loop請按任意鍵繼續 . . .
七
#include <stdio.h>
#include <stdlib.h>
int main ()
{
int i,s ;
for (i=3;i<=1002;i++)
s+=i*(i+1);
printf ("%d",s);
system ("pause");
return 0;
}
輸出答案
336342048
一
#include <iostream>
using namespace std;
int main ()
{
int x=5,y=3,z,w;
x-=2;
cout<<x++<<"\n";
z=++y;
cout<<z<<"\n";
cout<<y<<"\n";
w=z<<2;
cout<<z<<"\n";
cout<<w<<"\n";
for (x=4;x<10;x++)
{
if (x%2==0)
continue;
cout<<x<<"\n";
if(x==7)break;
};
cout<<x<<"\n";
system ("pause");
return 0;
}
輸出:
3
4
4
4
16
5
7
7
二
#include <stdio.h>
#include <stdlib.h>
int main ()
{
int j=2,i=0xf;
const double PI=3.1415926536;
printf("[%3x]\n",i);
printf("[%3d]\n",i);
printf("[%3d]\n",j);
printf("[%f]\n",PI);
printf("[%-15.10f]\n",PI);
system("pause");
return 0;
}
輸出:
[ f]
[ 15]
[ 2]
[3.141593]
[3.1415926536 ]
三
#include <stdio.h>
#include <stdlib.h>
int main ()
{
int i;
for (i=0;i<7;i++)
{
if(i==0)
printf("i=%d\n",i);
else if (i==1)
printf("i=%d\n",i);
else if (i==2)
printf ("i=%d\n",i);
else
printf("這是期中考\n");
};
printf ("i=%d\n",i++);
system ("pause");
return 0;
}
答案:
i=0
i=1
i=2
這是期中考
這是期中考
這是期中考
這是期中考
i=7
五
#include <iostream>
using namespace std;
void prch(char ch, int rows);
int main()
{
for (int i=3;i>=0;i--)
{
prch (' ',i);
prch ('$',4-i);
cout<<endl;
}
cin.get();
return 0;
}
void prch (char ch, int rows)
{
for (int i=1;i<=rows; i++)
{
cout<<ch ;
}
}
輸出答案
&
&&
&&&
&&&&
六
#include <stdio.h>
#include <stdlib.h>
int main (){
char x[11]="while-loop";
int i=0,n;
scanf ("%d",&n);
while(i<n){
printf ("%s",x);
i++;
}
system ("pause");
return 0;
}
輸出答案
5
while-loopwhile-loopwhile-loopwhile-loopwhile-loop請按任意鍵繼續 . . .
七
#include <stdio.h>
#include <stdlib.h>
int main ()
{
int i,s ;
for (i=3;i<=1002;i++)
s+=i*(i+1);
printf ("%d",s);
system ("pause");
return 0;
}
輸出答案
336342048
一
#include <iostream>
using namespace std;
int main ()
{
int x=5,y=3,z,w;
x-=2;
cout<<x++<<"\n";
z=++y;
cout<<z<<"\n";
cout<<y<<"\n";
w=z<<2;
cout<<z<<"\n";
cout<<w<<"\n";
for (x=4;x<10;x++)
{
if (x%2==0)
continue;
cout<<x<<"\n";
if(x==7)break;
};
cout<<x<<"\n";
system ("pause");
return 0;
}
輸出:
3
4
4
4
16
5
7
7
二
#include <stdio.h>
#include <stdlib.h>
int main ()
{
int j=2,i=0xf;
const double PI=3.1415926536;
printf("[%3x]\n",i);
printf("[%3d]\n",i);
printf("[%3d]\n",j);
printf("[%f]\n",PI);
printf("[%-15.10f]\n",PI);
system("pause");
return 0;
}
輸出:
[ f]
[ 15]
[ 2]
[3.141593]
[3.1415926536 ]
三
#include <stdio.h>
#include <stdlib.h>
int main ()
{
int i;
for (i=0;i<7;i++)
{
if(i==0)
printf("i=%d\n",i);
else if (i==1)
printf("i=%d\n",i);
else if (i==2)
printf ("i=%d\n",i);
else
printf("這是期中考\n");
};
printf ("i=%d\n",i++);
system ("pause");
return 0;
}
答案:
i=0
i=1
i=2
這是期中考
這是期中考
這是期中考
這是期中考
i=7
五
#include <iostream>
using namespace std;
void prch(char ch, int rows);
int main()
{
for (int i=3;i>=0;i--)
{
prch (' ',i);
prch ('$',4-i);
cout<<endl;
}
cin.get();
return 0;
}
void prch (char ch, int rows)
{
for (int i=1;i<=rows; i++)
{
cout<<ch ;
}
}
輸出答案
&
&&
&&&
&&&&
六
#include <stdio.h>
#include <stdlib.h>
int main (){
char x[11]="while-loop";
int i=0,n;
scanf ("%d",&n);
while(i<n){
printf ("%s",x);
i++;
}
system ("pause");
return 0;
}
輸出答案
5
while-loopwhile-loopwhile-loopwhile-loopwhile-loop請按任意鍵繼續 . . .
七
#include <stdio.h>
#include <stdlib.h>
int main ()
{
int i,s ;
for (i=3;i<=1002;i++)
s+=i*(i+1);
printf ("%d",s);
system ("pause");
return 0;
}
輸出答案
336342048
第一題
#include <iostream>
#include <cstdlib>
using namespace std;
int main(){
int x=5,y=3,z,w;
x-=2;
cout<<x++<<"\n";
z=++y;
cout<<z<<"\n";
cout<<y<<"\n";
w=z<<2;
cout<<z<<"\n";
for(x=4;x<10;x++)
{
if (x%2==0) continue;
cout<<x<<"\n";
if (x==7) break;
}
cout<<x<<"\n";
system("pause");
return 0;
}
3
4
4
4
5
7
7
--------------------------------
第二題
#include <stdio.h>
#include <stdlib.h>
int main()
{
int j=2,i=0xf;
const double PI=3.1415926536;
printf("[%3x]\n",i);
printf("[%3d]\n",i);
printf("[%3d]\n",j);
printf("[%f]\n",PI);
printf("[%-15.10f]\n",PI);
system("pause");
return 0;
}
[ f]
[ 15]
[ 2]
[3.141593]
[3.1415926536 ]
---------------------------------
第三題
#include <stdio.h>
#include <stdlib.h>
int main()
{
int i;
for(i=0;i<7;i++)
{
if(i==0)
printf("i=%d\n",i);
else if(i==1)
printf("i=%d\n",i);
else if(i==2)
printf("i=%d\n",i);
else
printf("這是期中考\n");
};
printf("i=%d\n",i++);
system("pause");
return 0;
}
i=0
i=1
i=2
這是期中考
這是期中考
這是期中考
這是期中考
i=7
---------------------------------
第四題
#include <iostream>
#include <cstdlib>
#include <math.h>
using namespace std;
int Prime[]={2,3,5,11,13,17,19,23};
bool isPrimebelow400(int n)
{
int n_sqrt=(int)sqrt((double)n);
for (int i=0; Prime[i]<=n_sqrt; i++)
{
if (n%Prime[i]==0 && n>Prime[i])
return 0;
}
return 1;
}
int main(){
for(int i=2;i<=400;i++)
{
if(isPrimebelow400(i))
cout<<i<<'\t';
}
system("pause");
return 0;
}
2 3 5 7 11 13 17 19 23 29
31 37 41 43 47 49 53 59 61 67
71 73 77 79 83 89 91 97 101 103
107 109 113 119 127 131 133 137 139 149
151 157 161 163 167 173 179 181 191 193
197 199 203 211 217 223 227 229 233 239
241 251 257 259 263 269 271 277 281 283
287 293 301 307 311 313 317 329 331 337
343 347 349 353 359 367 371 373 379 383
389 397
-------------------------------------------------------------------------
第五題
#include <iostream>
#include <cstdlib>
using namespace std;
void prCh(char ch, int rows);
int main()
{
for(int i=0;i<5;i++){
prCh('A',i+1);
prCh('X',i);
cout<<endl;
}
cin.get();
return 0;
}
void prCh(char ch, int rows){
for(int i=1;i<=rows;i++){
cout<<ch;
}
}
A
AAX
AAAXX
AAAAXXX
AAAAAXXXX
改:
#include <iostream>
#include <cstdlib>
using namespace std;
void prCh(char ch, int rows);
int main()
{
for(int i=3;i>=0;i--){
prCh(' ',i);
prCh('$',4-i);
cout<<endl;
}
cin.get();
return 0;
}
void prCh(char ch, int rows){
for(int i=1;i<=rows;i++){
cout<<ch;
}
}
$
$$
$$$
$$$$
------------------------------------------
第六題
char x[11]="while-loop";
int i=0,n;
scanf("%d",&n);
while(i<n){
printf("%s",x);
i++;
}
system("pause")
-------------------------------------------
第七題
#include <stdio.h>
#include <stdlib.h>
int main()
{
int s,i;
for(i=3;i<=1002;i++)
s+=i*(i+1);
printf("%d\n",s);
system("pause");
return 0;
}
336342002
第1題
#include <cstdlib>
#include <iostream>
using namespace std;
int main()
{
int x=5,y=3,z,w;
x-=2;
cout<<x++<<"\n";
z=++y;
cout<<z<<"\n";
cout<<y<<"\n";
w=z<<2;
cout<<z<<"\n";
cout<<w<<"\n";
for(x=4;x<10;x++){
if (x%2==0) continue;
cout<<x<<"\n";
if (x==7) break;
};
cout<<x<<"\n";
system("pause");
return 0;
}
輸出
3
4
4
4
16
5
7
7
第2題
#include <stdio.h>
#include <stdlib.h>
int main()
{
int j=2, i=0xf;
const double PI=3.1415926536;
printf("[%3x]\n",i);
printf("[%3d]\n",i);
printf("[%3d]\n",j);
printf("[%f]\n",PI);
printf("[%-15.10f]\n",PI);
system("pause");
return 0;
}
輸出
[__f]
[_15]
[__2]
[3.141593]
[3.1415926536___]
第3題
#include <iostream>
using namespace std;
int main()
{
int i;
for (i=0;i<7;i++)
{
switch(i){
case 0:printf("i=%d\n",i);break;
case 1:printf("i=%d\n",i);break;
case 2:printf("i=%d\n",i);break;
default:printf("這是期中考\n");break;
};
};
printf("i=%d\n",i++);
system("pause");
return 0;
}
輸出
i=0
i=1
i=2
這是期中考
這是期中考
這是期中考
這是期中考
i=7
改寫
#include <stdio.h>
#include <stdlib.h>
int main()
{
int i;
for(i=0;i<7;i++)
{
if(i==0)
{
printf("i=%d\n",i);
}
else if (i==1)
{
printf("i=%d\n",i);
}
else if (i==2)
{
printf("i=%d\n",i);
}
else
{
printf("這是期中考\n");
}
};
printf("i=%d\n",i++);
system("pause");
return 0;
}
第5題
#include <iostream>
using namespace std;
void prCh(char ch, int rows);
int main()
{
for(int i=0;i<5;i++){
prCh('A',i+1);
prCh('X',i);
cout<<endl;
}
cin.get();
return 0;
}
void prCh(char ch, int rows){
for (int i=1; i<=rows; i++){
cout<<ch;
}
}
輸出:
A
AAX
AAAXX
AAAAXXX
AAAAAXXXX
改寫:
#include <iostream>
using namespace std;
void prCh(char ch, int rows);
int main()
{
for(int i=3;i>=0;i--){
prCh(' ',i);
prCh('$',4-i);
cout<<endl;
}
cin.get();
return 0;
}
void prCh(char ch, int rows){
for (int i=1; i<=rows; i++){
cout<<ch;
}
}
輸出:
$
$$
$$$
$$$$
第6題
#include <stdio.h>
#include <stdlib.h>
int main()
{
char x[11]="while-loop";
int i=0, n;
scanf("%d",&n);
while(i>=0){
printf("%s",x);
i++;
}
system("PAUSE");
return 0;
}
第一題
#include <cstdlib>
#include <iostream>
using namespace std;
int main()
{
int x=5,y=3,z,w;
x-=2;
cout<<x++<<"\n";
z=++y;
cout<<z<<"\n";
cout<<y<<"\n";
w=z<<2;
cout<<z<<"\n";
cout<<w<<"\n";
for (x=4;x<10;x++){
if (x%2==0) continue;
cout<<x<<"\n";
if (x==7) break;
};
cout<<x<<"\n";
system ("pause");
return 0;
}
輸出
3
4
4
4
16
5
7
7
第二題
#include <stdio.h>
#include <stdlib.h>
int main()
{
int j=2,i=0xf;
const double PI=3.1415926536;
printf("[%3x]\n",i);
printf("[%3d]\n",i);
printf("[%3x]\n",j);
printf("[%f]\n",PI);
printf("[%-15.10f]\n",PI);
system ("pause");
return 0;
}
[ f]
[ 15]
[ 2]
[3.141593]
[3.1415926536 ]
第三題
#include <stdio.h>
#include <stdlib.h>
int main()
{
int i;
for (i=0;i<7;i++)
{
if(i==0)
printf("i=%d\n",i);
else if(i==1)
printf("i=%d\n",i);
else if(i==2)
printf("i=%d\n",i);
else
printf("這是期中考\n");
}
printf("i=%d\n",i++);
system("pause");
return 0;
}
i=0
i=1
i=2
這是期中考
這是期中考
這是期中考
這是期中考
i=7
第五題(1)
#include <iostream>
using namespace std;
void prCh (char ch, int rows);
int main ()
{
for(int i=0;i<5;i++)
{
prCh('A',i+1);
prCh('X',i);
cout<<endl;
}
cin.get();
return 0;
}
void prCh (char ch, int rows){
for (int i=1 ; i<=rows; i++){
cout<<ch;
}
}
A
AAX
AAAXX
AAAAXXX
AAAAAXXXX
第五題(2)
#include <iostream>
using namespace std;
void prCh (char ch, int rows);
int main ()
{
for(int i=1;i<=4;i++)
{
prCh(' ',4-i);
prCh('$',i);
cout<<endl;
}
cin.get();
return 0;
}
void prCh (char ch, int rows){
for (int i=1 ; i<=rows; i++){
cout<<ch;
}
}
$
$$
$$$
$$$$
第六題
#include <stdio.h>
#include <stdlib.h>
int main()
{
char x[11]="while-loop";
int i=0,n;
scanf("%d",&n);
while(i<n){
printf("%s",x);
i++;
}
system("pause");
return 0;
}
第七題
#include <stdio.h>
#include <stdlib.h>
int main()
{
int i,s;
for(i=3;i<=1002;i++)
s=s+i*(i+1);
printf("%d",s);
system("pause");
return 0;
}
336342049請按任意鍵繼續 . . .
一、
#include <iostream>
#include <cstdlib>
using namespace std;
int main(){
int x=5,y=3,z,w;
x-=2;
cout<<x++<<"\n";
z=++y;
cout<<z<<"\n";
cout<<y<<"\n";
w=z<<2;
cout<<z<<"\n";
for(x=4;x<10;x++)
{
if (x%2==0) continue;
cout<<x<<"\n";
if (x==7) break;
}
cout<<x<<"\n";
system("pause");
return 0;
}
3
4
4
4
5
7
7
--------------------------------
二、
#include <stdio.h>
#include <stdlib.h>
int main()
{
int j=2,i=0xf;
const double PI=3.1415926536;
printf("[%3x]\n",i);
printf("[%3d]\n",i);
printf("[%3d]\n",j);
printf("[%f]\n",PI);
printf("[%-15.10f]\n",PI);
system("pause");
return 0;
}
[ f]
[ 15]
[ 2]
[3.141593]
[3.1415926536 ]
---------------------------------
三、
#include <stdio.h>
#include <stdlib.h>
int main()
{
int i;
for(i=0;i<7;i++)
{
if(i==0)
printf("i=%d\n",i);
else if(i==1)
printf("i=%d\n",i);
else if(i==2)
printf("i=%d\n",i);
else
printf("這是期中考\n");
};
printf("i=%d\n",i++);
system("pause");
return 0;
}
i=0
i=1
i=2
這是期中考
這是期中考
這是期中考
這是期中考
i=7
---------------------------------
四、
#include <iostream>
#include <cstdlib>
#include <math.h>
using namespace std;
int Prime[]={2,3,5,11,13,17,19,23};
bool isPrimebelow400(int n)
{
int n_sqrt=(int)sqrt((double)n);
for (int i=0; Prime[i]<=n_sqrt; i++)
{
if (n%Prime[i]==0 && n>Prime[i])
return 0;
}
return 1;
}
int main(){
for(int i=2;i<=400;i++)
{
if(isPrimebelow400(i))
cout<<i<<'\t';
}
system("pause");
return 0;
}
2 3 5 7 11 13 17 19 23 29
31 37 41 43 47 49 53 59 61 67
71 73 77 79 83 89 91 97 101 103
107 109 113 119 127 131 133 137 139 149
151 157 161 163 167 173 179 181 191 193
197 199 203 211 217 223 227 229 233 239
241 251 257 259 263 269 271 277 281 283
287 293 301 307 311 313 317 329 331 337
343 347 349 353 359 367 371 373 379 383
389 397
-------------------------------------------------------------------------
五、
#include <iostream>
#include <cstdlib>
using namespace std;
void prCh(char ch, int rows);
int main()
{
for(int i=0;i<5;i++){
prCh('A',i+1);
prCh('X',i);
cout<<endl;
}
cin.get();
return 0;
}
void prCh(char ch, int rows){
for(int i=1;i<=rows;i++){
cout<<ch;
}
}
A
AAX
AAAXX
AAAAXXX
AAAAAXXXX
改:
#include <iostream>
#include <cstdlib>
using namespace std;
void prCh(char ch, int rows);
int main()
{
for(int i=3;i>=0;i--){
prCh(' ',i);
prCh('$',4-i);
cout<<endl;
}
cin.get();
return 0;
}
void prCh(char ch, int rows){
for(int i=1;i<=rows;i++){
cout<<ch;
}
}
$
$$
$$$
$$$$
------------------------------------------
六、
char x[11]="while-loop";
int i=0,n;
scanf("%d",&n);
while(i<n){
printf("%s",x);
i++;
}
system("pause")
-------------------------------------------
七、
#include <stdio.h>
#include <stdlib.h>
int main()
{
int s,i;
for(i=3;i<=1002;i++)
s+=i*(i+1);
printf("%d\n",s);
system("pause");
return 0;
}
336342002
第一題
#include <iostream>
#include <cstdlib>
using namespace std;
int main()
{
int x=5,y=3,z,w;
x-=2;
cout<<x++<<"\n";
z=++y;
cout<<z<<"\n";
cout<<y<<"\n";
w=z<<2;
cout<<z<<"\n";
cout<<w<<"\n";
for(x=4;x<10;x++)
{
if (x%2==0) continue;
cout<<x<<"\n";
if (x==7) break;
};
cout<<x<<"\n";
system("pause");
return 0;
}
答:
3
4
4
4
16
5
7
7
第二題
#include <stdio.h>
#include <stdlib.h>
int main()
{
int j=2,i=0xf;
const double PI=3.1415926536;
printf("[%3x]\n",i);
printf("[%3d]\n",i);
printf("[%3x]\n",j);
printf("[%f]\n",PI);
printf("[%-15.10f]\n",PI);
system("pause");
return 0;
}
答:
[00f]
[015]
[002]
[3.141593]
[3.141592636000]
第三題
#include <iostream>
using namespace std;
int main()
{
int i;
for (i=0;i<7;i++)
{
switch(i){
case 0:printf("i=%d\n",i);break;
case 1:printf("i=%d\n",i);break;
case 2:printf("i=%d\n",i);break;
default:printf("這是期中考\n");break;
};
};
printf("i=%d\n",i++);
system("pause");
return 0;
}
答:
i=0
i=1
i=2
這是期中考
這是期中考
這是期中考
這是期中考
i=7
↓
改寫:
#include <stdio.h>
#include <stdlib.h>
int main()
{
int i;
for(i=0;i<7;i++)
{
if(i==0)
{
printf("i=%d\n",i);
}
else if (i==1)
{
printf("i=%d\n",i);
}
else if (i==2)
{
printf("i=%d\n",i);
}
else
{
printf("這是期中考\n");
}
};
printf("i=%d\n",i++);
system("pause");
return 0;
}
第五題
#include <iostream>
using namespace std;
void prCh(char ch, int rows);
int main()
{
for(int i=0;i<5;i++)
{
prCh('A',i+1);
prCh('X',i);
cout<<endl;
}
cin.get();
return 0;
}
void prCh(char ch, int rows){
for(int i=1;i<=rows;i++){
cout<<ch;
}
}
答:
A
AAX
AAAXX
AAAAXXX
AAAAAXXXX
↓
改寫:
#include <iostream>
using namespace std;
void prCh(char ch, int rows);
int main()
{
prCh(' ',3);
prCh('$',1);
cout<<endl;
prCh(' ',2);
prCh('$',2);
cout<<endl;
prCh(' ',1);
prCh('$',3);
cout<<endl;
prCh('$',4);
cout<<endl;
cin.get();
return 0;
}
void prCh(char ch, int rows){
for(int i=1;i<=rows;i++){
cout<<ch;
}
}
輸出:
$
$$
$$$
$$$$
第六題
#include <stdio.h>
#include <stdlib.h>
int main()
{
char x[11]="while-loop";
int i=0, n;
scanf("%d,&n");
while(i>=0)
{
printf("%s",x);
i++;
}
system("pause");
return 0;
第七題
#include <stdio.h>
#include <stdlib.h>
int main()
{
int i,s;
for(i=3;i<=1002;i++)
s+=i*(i+1);
printf("%d",s);
system("pause");
return 0;
}
第一題
#include <cstdlib>
#include <iostream>
using namespace std;
int main ()
{
int x=5,y=3,z,w;
x-=2;
cout <<x++<<"\n";
z=++y;
cout <<z<<"\n";
cout <<y<<"\n";
w=z<<2;
cout<<z<<"\n";
cout<<w<<"\n";
for (x=4;x<10;x++)
{
if (x%2==0) continue;
cout <<x<<"\n";
if (x==7) break;
};
cout<<x<<"\n";
system ("pause");
return 0;
}
輸出:
3
4
4
4
16
5
7
7
第二題
#include <stdio.h>
#include <stdlib.h>
int main ()
{
int j=2, i=0xf;
const double PI=3.1415926536;
printf("[%3x]\n",i);
printf("[%3d]\n",i);
printf("[%3d]\n",j);
printf("[%f]\n",PI);
printf("[%-15.10f]\n",PI);
system ("pause");
return 0;
}
輸出:
[ f]
[ 15]
[ 2]
[3.141593]
[3.1415926536 ]
第三題
#include <stdio.h>
#include <stdlib.h>
int main ()
{
int i;
for (i=0;i<7;i++)
{
if (i==0)
printf ("i=%d\n",i);
else if (i==1)
printf ("i=%d\n",i);
else if (i==2)
printf ("i=%d\n",i);
else
printf("這是期中考\n");
}
printf("i=%d\n",i++);
system ("pause");
return 0;
}
輸出
i=0
i=1
i=2
這是期中考
這是期中考
這是期中考
這是期中考
i=7
第五題 (1)
#include <iostream>
using namespace std;
void prCh (char ch, int rows);
int main ()
{
for (int i=0;i<5;i++)
{
prCh('A',i+1);
prCh('X',i);
cout<<endl;
}
cin.get ();
return 0;
}
void prCh (char ch, int rows)
{
for (int i=1; i<=rows; i++)
{
cout<<ch;
}
}
輸出:
A
AAX
AAAXX
AAAAXXX
AAAAAXXXX
第五題 (2)
#include <iostream>
using namespace std;
void prCh (char ch, int rows);
int main ()
{
for (int i=1;i<=4;i++)
{
prCh(' ',4-i);
prCh('$',i);
cout<<endl;
}
cin.get ();
return 0;
}
void prCh (char ch, int rows)
{
for (int i=1; i<=rows; i++)
{
cout<<ch;
}
}
輸出:
$
$$
$$$
$$$$
第六題
#include <stdio.h>
#include <stdlib.h>
int main ()
{
char x[11]="while-loop";
int i=0, n;
scanf ("%d",&n);
while (i<n)
{
printf ("%s",x);
i++;
}
system ("pause");
return 0;
}
第七題
#include <stdio.h>
#include <stdlib.h>
int main ()
{
int i,s;
for (i=3;i<=1002;i++)
s=s+i*(i+1);
printf("%d",s);
system ("pause");
return 0;
}
輸出:
336342057
1.
#include<cstdlib>
#include<iostream>
using namespace std;
int main()
{
int x=5,y=3,z,w;
x-=2;
cout<<x++<<"\n";
z=++y;
cout<<z<<"\n";
cout<<y<<"\n";
w=z<<2;
cout<<z<<"\n";
cout<<w<<"\n";
for(x=4;x<10;x++){
if(x%2==0)continue;
cout<<x<<"\n";
if(x==7)break;
};
cout<<x<<"\n";
system("pause");
return 0;
}
ans:
3
4
4
4
16
5
7
7
3.
#include<stdio.h>
#include<stdlib.h>
int main()
{
int i;
for(i=0;i<7;i++)
{
if(i==0)
{
printf("i=%d\n",i);
}
else if(i==1)
{
printf("i=%d\n",i);
}
else if(i==2)
{
printf("i=%d\n",i);
}
else
{
printf("這是期中考\n");
}
}
printf("i=%d\n",i++);
system("pause");
return 0;
}
ans:
i=0
i=1
i=2
這是期中考
這是期中考
這是期中考
這是期中考
i=7
5.
(1)
#include<iostream>
using namespace std;
void prCh(char ch,int rows);
int main()
{
for(int i=0;i<=5;i++)
{
prCh('A',i+1);
prCh('X',i);
cout<<endl;
}
cin.get();
return 0;
}
void prCh(char ch,int rows)
{
for(int i=1;i<=rows;i++)
{
cout<<ch;
}
}
ans:
A
AAX
AAAXX
AAAAXXX
AAAAAXXXX
AAAAAAXXXXX
(2)
#include<iostream>
using namespace std;
void prCh(char ch,int rows);
int main()
{
for(int i=3;i>=0;i--)
{
prCh(' ',i);
prCh('$',4-i);
cout<<endl;
}
cin.get();
return 0;
}
void prCh(char ch,int rows)
{
for(int i=1;i<=rows;i++)
{
cout<<ch;
}
}
ans:
$
$$
$$$
$$$$
6.
#include<stdio.h>
#include<stdlib.h>
int main()
{
char x[11]="while-loop";
int i=0,n;
scanf("%d",&n);
while(i<n)
{
printf("%s",x);
i++;
}
system("pause");
return 0;
}
7.#include<stdio.h>
#include<stdlib.h>
int main()
{
int i,s;
s=0;
for(i=3;i<=1002;i++)
s=s+i*(i+1);
printf("%d",s);
system("pause");
return 0;
}
1.
#include<cstdlib>
#include<iostream>
using namespace std;
int main()
{
int x=5,y=3,z,w;
x-=2;
cout<<x++<<"\n";
z=++y;
cout<<z<<"\n";
cout<<y<<"\n";
w=z<<2;
cout<<z<<"\n";
cout<<w<<"\n";
for(x=4;x<10;x++){
if(x%2==0)continue;
cout<<x<<"\n";
if(x==7)break;
};
cout<<x<<"\n";
system("pause");
return 0;
}
ans:
3
4
4
4
16
5
7
7
3.
#include<stdio.h>
#include<stdlib.h>
int main()
{
int i;
for(i=0;i<7;i++)
{
if(i==0)
{
printf("i=%d\n",i);
}
else if(i==1)
{
printf("i=%d\n",i);
}
else if(i==2)
{
printf("i=%d\n",i);
}
else
{
printf("這是期中考\n");
}
}
printf("i=%d\n",i++);
system("pause");
return 0;
}
ans:
i=0
i=1
i=2
這是期中考
這是期中考
這是期中考
這是期中考
i=7
5.
(1)
#include<iostream>
using namespace std;
void prCh(char ch,int rows);
int main()
{
for(int i=0;i<=5;i++)
{
prCh('A',i+1);
prCh('X',i);
cout<<endl;
}
cin.get();
return 0;
}
void prCh(char ch,int rows)
{
for(int i=1;i<=rows;i++)
{
cout<<ch;
}
}
ans:
A
AAX
AAAXX
AAAAXXX
AAAAAXXXX
AAAAAAXXXXX
(2)
#include<iostream>
using namespace std;
void prCh(char ch,int rows);
int main()
{
for(int i=3;i>=0;i--)
{
prCh(' ',i);
prCh('$',4-i);
cout<<endl;
}
cin.get();
return 0;
}
void prCh(char ch,int rows)
{
for(int i=1;i<=rows;i++)
{
cout<<ch;
}
}
ans:
$
$$
$$$
$$$$
6.
#include<stdio.h>
#include<stdlib.h>
int main()
{
char x[11]="while-loop";
int i=0,n;
scanf("%d",&n);
while(i<n)
{
printf("%s",x);
i++;
}
system("pause");
return 0;
}
7.#include<stdio.h>
#include<stdlib.h>
int main()
{
int i,s;
s=0;
for(i=3;i<=1002;i++)
s=s+i*(i+1);
printf("%d",s);
system("pause");
return 0;
}
第一題
#include <iostream>
#include <cstdlib>
using namespace std;
int main()
{
int x=5,y=3,z,w;
x-=2;
cout<<x++<<"\n";
z=++y;
cout<<z<<"\n";
cout<<y<<"\n";
w=z<<2;
cout<<z<<"\n";
cout<<w<<"\n";
for(x=4;x<10;x++){
if (x%2==0)continue;
cout<<x<<"\n";
if (x==7) break;
};
cout<<x<<"\n";
system("PAUSE");
return 0;
}
輸出為:
3
4
4
4
16
5
7
7
..........................................
第二題
#include <stdio.h>
#include <stdlib.h>
int main(){
int j=2;
int i=0xf;
const double PI=3.1415926536;
printf("[%3x]\n",i);
printf("[%3d]\n",i);
printf("[%3d]\n",j);
printf("[%f]\n",PI);
printf("[%-15.10f]\n",PI);
system("PAUSE");
return 0;
}
輸出為:
[ f]
[ 15]
[ 2]
[3.141593]
[3.1415926536 ]
----------------------------------------
第三題
#include <stdio.h>
#include <stdlib.h>
int main()
{
int i;
for (i=0;i<7;i++)
{
if(i==0)
{
printf("i=%d\n",i);
}
else if(i==1)
{
printf("i=%d\n",i);
}
else if(i==2)
{
printf("i=%d\n",i);
}
else
{
printf("這是期中考\n");
}
};
printf("i=%d\n",i++);
system("pause");
return 0;
}
輸出為:
i=0
i=1
i=2
這是期中考
這是期中考
這是期中考
這是期中考
i=7
----------------------------------------------------------
第六題
#include <stdio.h>
#include <stdlib.h>
int main()
{
char x[11]="while-loop";
int i=0,n;
scanf("%d",&n);
while(i<n){
printf("%s",x);
i++;
}
system("PAUSE");
return 0;
}
------------------------------------------
第七題
#include <stdio.h>
#include <stdlib.h>
int main()
{
int i,s;
for(i=3;i<1003;i++)
s+=i*(i+1);
printf("%d",s);
system("pause");
return 0;
}
輸出為336342045
第一題
#include <cstdlib>
#include <iostream>
using namespace std;
int main ()
{
int x=5,y=3,z,w;
x-=2;
cout <<x++<<"\n";
z=++y;
cout <<z<<"\n";
cout <<y<<"\n";
w=z<<2;
cout<<z<<"\n";
cout<<w<<"\n";
for (x=4;x<10;x++)
{
if (x%2==0) continue;
cout <<x<<"\n";
if (x==7) break;
};
cout<<x<<"\n";
system ("pause");
return 0;
}
輸出:
3
4
4
4
16
5
7
7
第二題
#include <stdio.h>
#include <stdlib.h>
int main ()
{
int j=2, i=0xf;
const double PI=3.1415926536;
printf("[%3x]\n",i);
printf("[%3d]\n",i);
printf("[%3d]\n",j);
printf("[%f]\n",PI);
printf("[%-15.10f]\n",PI);
system ("pause");
return 0;
}
輸出:
[ f]
[ 15]
[ 2]
[3.141593]
[3.1415926536 ]
第三題
#include <stdio.h>
#include <stdlib.h>
int main ()
{
int i;
for (i=0;i<7;i++)
{
if (i==0)
printf ("i=%d\n",i);
else if (i==1)
printf ("i=%d\n",i);
else if (i==2)
printf ("i=%d\n",i);
else
printf("這是期中考\n");
}
printf("i=%d\n",i++);
system ("pause");
return 0;
}
輸出
i=0
i=1
i=2
這是期中考
這是期中考
這是期中考
這是期中考
i=7
第五題 (1)
#include <iostream>
using namespace std;
void prCh (char ch, int rows);
int main ()
{
for (int i=0;i<5;i++)
{
prCh('A',i+1);
prCh('X',i);
cout<<endl;
}
cin.get ();
return 0;
}
void prCh (char ch, int rows)
{
for (int i=1; i<=rows; i++)
{
cout<<ch;
}
}
輸出:
A
AAX
AAAXX
AAAAXXX
AAAAAXXXX
第五題 (2)
#include <iostream>
using namespace std;
void prCh (char ch, int rows);
int main ()
{
for (int i=1;i<=4;i++)
{
prCh(' ',4-i);
prCh('$',i);
cout<<endl;
}
cin.get ();
return 0;
}
void prCh (char ch, int rows)
{
for (int i=1; i<=rows; i++)
{
cout<<ch;
}
}
輸出:
$
$$
$$$
$$$$
第六題
#include <stdio.h>
#include <stdlib.h>
int main ()
{
char x[11]="while-loop";
int i=0, n;
scanf ("%d",&n);
while (i<n)
{
printf ("%s",x);
i++;
}
system ("pause");
return 0;
}
第七題
#include <stdio.h>
#include <stdlib.h>
int main ()
{
int i,s;
for (i=3;i<=1002;i++)
s=s+i*(i+1);
printf("%d",s);
system ("pause");
return 0;
}
輸出:
336342002
第一題
#include<cstdlib>
#include<iostream>
using namespace std;
int main()
{
int x=5,y=3,z,w;
x-=2;
cout<<x++<<"\n";
z=++y;
cout<<z<<"\n";
cout<<y<<"\n";
w=z<<2;
cout<<z<<"\n";
cout<<w<<"\n";
for(x=4;x<10;x++)
{
if (x%2==0) continue;
cout<<x<<"\n";
if (x==7) break;
}
cout<<x<<"\n";
system("pause");
return 0;
}
輸出:
3
4
4
4
16
5
7
7
第二題
#include<stdio.h>
#include<stdlib.h>
int main()
{
int j=2,i=0xf;
const double PI=3.1415926536;
printf("[%3x]\n",i);
printf("[%3d]\n",i);
printf("[%3d]\n",j);
printf("[%f]\n",PI);
printf("[%-15.10f]\n",PI);
system("pause");
return 0;
}
輸出:
[ f]
[ 15]
[ 2]
[3.141593]
[3.1415926536 ]
第三題
#include<stdio.h>
#include<stdlib.h>
int main()
{
int i;
for(i=0;i<7;i++)
{
if (i==0)
printf("i=%d\n",i);
else if(i==1)
printf("i=%d\n",i);
else if(i==2)
printf("i=%d\n",i);
else
printf("這是期中考\n");
}
printf("i=%d\n",i++);
system("pause");
return 0;
}
輸出:
i=0
i=1
i=2
這是期中考
這是期中考
這是期中考
這是期中考
i=7
第五題
#include<iostream>
using namespace std;
void prCh(char ch,int rows);
int main()
{
for(int i=0;i<5;i++)
{
prCh('A',i+1);
prCh('X',i);
cout<<endl;
}
cin.get();
return 0;
}
void prCh(char ch,int rows)
{
for(int i=1;i<=rows;i++)
{
cout<<ch;
}
}
輸出:
A
AAX
AAAXX
AAAAXXX
AAAAAXXXX
改寫程式:
#include<iostream>
using namespace std;
void prCh(char ch,int rows);
int main()
{
for(int i=1;i<=4;i++)
{
prCh(' ',4-i);
prCh('$',i);
cout<<endl;
}
cin.get();
return 0;
}
void prCh(char ch,int rows)
{
for(int i=1;i<=rows;i++)
{
cout<<ch;
}
}
輸出:
$
$$
$$$
$$$$
第六題
#include<stdio.h>
#include<stdlib.h>
int main()
{
char x[11]="while-loop";
int i=0,n;
scanf("%d",&n);
while(i<n)
{
printf("%s",x);
i++;
}
system("pause");
return 0;
}
1.
#include <iostream>
#include <cstdio>
using namespace std;
int main()
{
int x=5,y=3,z,w;
x-=2;
cout<<x++<<"\n";
z=++y;
cout<<z<<"\n";
cout<<y<<"\n";
w=z<<2;
cout<<z<<"\n";
cout<<w<<"\n";
for(x=4;x<10;x++){
if (x%2==0) continue;
cout<<x<<"\n";
if(x==7) break;
};
cout<<x<<"\n";
system ("Pause");
return 0;
}
3
4
4
4
16
5
7
7
請按任意鍵繼續 . . .
------------------------------------------------------------------------------------
2.
#include <stdio.h>
#include <stdlib.h>
int main()
{
int j=2,i=0xf;
const double PI=3.1415926536;
printf("[%3x]\n",i);
printf("[%3d]\n",i);
printf("[%3d]\n",j);
printf("[%f]\n",PI);
printf("[%-15.10f]\n",PI);
system("Pause");
return 0;
}
[ f]
[ 15]
[ 2]
[3.141593]
[3.1415926536 ]
請按任意鍵繼續 . . .
----------------------------------------------------------------------------------------
3.
#include <stdio.h>
#include <stdlib.h>
int main(){
int i;
for(i=0;i<7;i++)
{
if(i==0){
printf("i=%d\n",i);}
else if(i==1){
printf("i=%d\n",i);}
else if(i==2){
printf("i=%d\n",i);}
else printf("這是期中考\n",i);}
printf("i=%d\n",i++);
system ("pause");
return 0;
}
i=0
i=1
i=2
這是期中考
這是期中考
這是期中考
這是期中考
i=7
請按任意鍵繼續 . . .
-----------------------------------------------------------------------------------
5.
#include <iostream>
using namespace std;
void prCh(char ch,int rows);
int main(){
for (int i=1;i<5;i++){
prCh (' ',4-i);
prCh ('$',i);
cout<<endl;}
cin.get();
return 0;
}
void prCh(char ch,int rows){
for(int i=1;i<=rows;i++){
cout<<ch;
}
}
$
$$
$$$
$$$$
---------------------------------------------------------------------------------------
6.
#include <stdio.h>
#include <stdlib.h>
int main()
{
char x[11]="while-loop";
int i=0, n;
scanf("%d",&n);
while(i<=0){
printf("%s",x);
i++;
}
system ("pause");
}
-----------------------------------------------------------------------------------------
7.
#include <stdio.h>
#include <stdlib.h>
int main()
{
int i=3,s;
for(i=3;i<=1002;i++)
s+=i*(i+1);
printf("%d\n",s);
system("Pause");
return 0;
}
336342049
請按任意鍵繼續 . . .
1.
#include <iostream>
#include <cstdio>
using namespace std;
int main()
{
int x=5,y=3,z,w;
x-=2;
cout<<x++<<"\n";
z=++y;
cout<<z<<"\n";
cout<<y<<"\n";
w=z<<2;
cout<<z<<"\n";
cout<<w<<"\n";
for(x=4;x<10;x++){
if (x%2==0) continue;
cout<<x<<"\n";
if(x==7) break;
};
cout<<x<<"\n";
system ("Pause");
return 0;
}
3
4
4
4
16
5
7
7
請按任意鍵繼續 . . .
------------------------------------------------------------------------------------
2.
#include <stdio.h>
#include <stdlib.h>
int main()
{
int j=2,i=0xf;
const double PI=3.1415926536;
printf("[%3x]\n",i);
printf("[%3d]\n",i);
printf("[%3d]\n",j);
printf("[%f]\n",PI);
printf("[%-15.10f]\n",PI);
system("Pause");
return 0;
}
[ f]
[ 15]
[ 2]
[3.141593]
[3.1415926536 ]
請按任意鍵繼續 . . .
----------------------------------------------------------------------------------------
3.
#include <stdio.h>
#include <stdlib.h>
int main(){
int i;
for(i=0;i<7;i++)
{
if(i==0){
printf("i=%d\n",i);}
else if(i==1){
printf("i=%d\n",i);}
else if(i==2){
printf("i=%d\n",i);}
else printf("這是期中考\n",i);}
printf("i=%d\n",i++);
system ("pause");
return 0;
}
i=0
i=1
i=2
這是期中考
這是期中考
這是期中考
這是期中考
i=7
請按任意鍵繼續 . . .
-----------------------------------------------------------------------------------
5.
#include <iostream>
using namespace std;
void prCh(char ch,int rows);
int main(){
for (int i=1;i<5;i++){
prCh (' ',4-i);
prCh ('$',i);
cout<<endl;}
cin.get();
return 0;
}
void prCh(char ch,int rows){
for(int i=1;i<=rows;i++){
cout<<ch;
}
}
$
$$
$$$
$$$$
---------------------------------------------------------------------------------------
6.
#include <stdio.h>
#include <stdlib.h>
int main()
{
char x[11]="while-loop";
int i=0, n;
scanf("%d",&n);
while(i<=0){
printf("%s",x);
i++;
}
system ("pause");
}
-----------------------------------------------------------------------------------------
7.
#include <stdio.h>
#include <stdlib.h>
int main()
{
int i=3,s;
for(i=3;i<=1002;i++)
s+=i*(i+1);
printf("%d\n",s);
system("Pause");
return 0;
}
336342049
請按任意鍵繼續 . . .
#include <iostream>
using namespace std;
void swap1(int x, int y){
int temp=x;
x=y;
y=temp;
}
void swap2(int *x, int *y){
int temp=*x;
*x=*y;
*y=temp;
}
void swap3(int & x, int &y){
int temp=x;
x=y;
y=temp;
}
int main(){
int x=3,y=7;
cout<<"x= "<<x<<"\t y= "<<y<<'\n';
swap1(x,y);
cout<<"After swap1(), x= "<<x<<"\t y= "<<y<<'\n';
cout<<"x= "<<x<<"\t y= "<<y<<'\n';
swap2(&x,&y);
cout<<"After swap2(), x= "<<x<<"\t y= "<<y<<'\n';
cout<<"x= "<<x<<"\t y= "<<y<<'\n';
swap3(x,y);
cout<<"After swap3(), x= "<<x<<"\t y= "<<y<<'\n';
cin.get();
return 0;
}
題目1
#include <cstdlib>
#include <iostream>
using namespace std;
int main(){
int x=5,y=3,z,w;
x-=2;
cout<<x++<<"\n";
z=++y;
cout<<z<<"\n";
cout<<y<<"\n";
w=z<<2;
cout<<z<<"\n";
cout<<w<<"\n";
for(x=4;x<10;x++){
if(x%2==0) continue;
cout<<x<<"\n";
if(x==7)break;
};
cout<<x<<"\n";
system("pause");
return 0;
}
輸出:
3
4
4
4
16
5
7
7
請按任意鍵繼續 . . .
題目2
#include<stdio.h>
#include<stdlib.h>
int main()
{
int j=2,i=0xf;
const double PI=3.1415926536;
printf("[%3x]\n",i);
printf("[%3d]\n",i);
printf("[%3d]\n",j);
printf("[%f]\n",PI);
printf("[%-15.10f]\n",PI);
system("pause");
return 0;
}
輸出:
[ f]
[ 15]
[ 2]
[3.141593]
[3.1415926536 ]
請按任意鍵繼續 . . .
題目3
#include<stdio.h>
#include<stdlib.h>
int main()
{
int i;
for(i=0;i<7;i++)
{
if(i==0)
{
printf("i=%d\n",i);
}
else if (i==1)
{
printf("i=%d\n",i);
}
else if (i==2)
{
printf("i=%d\n",i);
}
else
{
printf("這是期中考\n");
};
};
printf("i=%d\n",i++);
system("pause");
return 0;
}
輸出:
i=0
i=1
i=2
這是期中考
這是期中考
這是期中考
這是期中考
i=7
請按任意鍵繼續 . . .
題目5
#include <iostream>
using namespace std;
void prCh(char ch, int rows);
int main()
{
for(int i=4;i>=1;i--){
prCh(' ',i-1);
prCh('$',5-i);
cout<<endl;
}
cin.get();
return 0;
}
void prCh(char ch, int rows){
for(int i=1; i<=rows; i++){
cout<<ch;
}
}
輸出:
$
$$
$$$
$$$$
題目6
#include<stdio.h>
#include<stdlib.h>
int main()
{
char x[11]="while-loop";
int i=0,n;
scanf("%d",&n);
while(i<n){
printf("%s",x);
i++;
}
system("pause");
return 0;
}
輸出:
5
while-loopwhile-loopwhile-loopwhile-loopwhile-loop請按任意鍵繼續 . . .
題目7
#include<stdio.h>
#include<stdlib.h>
int main()
{
int i,s;
for(i=3;i<=1002;i++)
{
s+=i*(i+1);
}
printf("%d\n",s);
system(pause");
return0;
}
輸出:
336342049
請按任意鍵繼續 . . .
#include <iostream>
#include <cstdlib>
using namespace std;
void print_n_star(int n)
{
for (int i=1;i<=n;i++)
cout<<'*';
cout<<endl;
};
int main()
{
for (int i=1;i<=7;i++)
print_n_star(i);
system("PAUSE");
return 0;
};
1.
#include <cstdlib>
#include <iostream>
using namespace std;
int main()
{
int x=5,y=3,z,w;
x-=2;
cout<<x++<<"\n";
z=++y;
cout<<z<<"\n";
cout<<y<<"\n";
w=z<<2;
cout<<z<<"\n";
cout<<w<<"\n";
for(x=4;x<10;x++){
if (x%2==0) continue;
cout<<x<<"\n";
if (x==7) break;
};
cout<<x<<"\n";
system("pause");
return 0;
}
3
4
4
4
16
5
7
7
請按任意鍵繼續 . . .
2.
#include <stdio.h>
#include <stdlib.h>
int main()
{
int j=2, i=0xf;
const double PI=3.1415926536;
printf("[%3x]\n",i);
printf("[%3d]\n",i);
printf("[%3d]\n",j);
printf("[%f]\n",PI);
printf("[%-15.10f]\n",PI);
system("pause");
return 0;
}
[ f]
[ 15]
[ 2]
[3.141593]
[3.1415926536 ]
請按任意鍵繼續 . . .
3.
#include <stdio.h>
#include <stdlib.h>
int main()
{
int i;
for(i=0;i<7;i++)
{
if(i==0)
printf("i=%d\n",i);else
if(i==1)
printf("i=%d\n",i);else
if(i==2)
printf("i=%d\n",i);
else
printf("這是期中考\n");
};
printf("i=%d\n",i++);
system ("pause");
return 0;
}
i=0
i=1
i=2
這是期中考
這是期中考
這是期中考
這是期中考
i=7
請按任意鍵繼續 . . .
5-1
#include<iostream>
using namespace std;
void prCh(char ch,int rows);
int main()
{
for(int i=0;i<5;i++)
{
prCh('A',i+1);
prCh('X',i);
cout<<endl;
}
cin.get();
return 0;
}
void prCh(char ch,int rows)
{
for(int i=1;i<=rows;i++)
{
cout<<ch;
}
}
A
AAX
AAAXX
AAAAXXX
AAAAAXXXX
5-2
#include<iostream>
using namespace std;
void prCh(char ch,int rows);
int main()
{
for(int i=1;i<=4;i++)
{
prCh(' ',4-i);
prCh('$',i);
cout<<endl;
}
cin.get();
return 0;
}
void prCh(char ch,int rows)
{
for(int i=1;i<=rows;i++)
{
cout<<ch;
}
}
$
$$
$$$
$$$$
6.
#include<stdio.h>
#include<stdlib.h>
int main()
{
char x[11]="while-loop";
int i=0,n;
scanf("%d",&n);
while(i<n)
{
printf("%s",x);
i++;
}
system("pause");
return 0;
}
7.
#include<stdio.h>
#include<stdlib.h>
int main()
{
int s,i;
for(i=3;i<=1002;i++)
s=s+i*(i+1);
printf("%d",s);
system("pause");
return 0;
}
336342002請按任意鍵繼續 . . .
#include <iostream>
using namespace std;
int main()
{
int x=5,y=3,z,w;
x-=2;
cout<<x++<<"\n";
z=++y;
cout<<z<<"\n";
cout<<y<<"\n";
w=z++;
cout<<z<<"\n";
cout<<w<<"\n";
cout<<++x<<"\n";
for(x=4;x<10;x++)
{
if (x%2==0) continue;
cout<<x<<"\n";
if (x==7) break;
};
cout<<x<<"\n";
cin.get();
return 0;
}
1.
#include <cstdlib>
#include <iostream>
using namespace std;
int main()
{
int x=5,y=3,z,w;
x-=2;
cout<<x++<<"\n";
z=++y;
cout<<z<<"\n";
cout<<y<<"\n";
w=z<<2;
cout<<z<<"\n";
cout<<w<<"\n";
for(x=4;x<10;x++)
{
if (x%2==0) continue;
cout<<x<<"\n";
if(x==7)break;
};
cout<<x<<"\n";
system("pause");
return 0;
}
輸出3,4,4,4,16,5,7,7
2.
#include <stdio.h>
#include <stdlib.h>
int main()
{
int j=2,i=0xf;
const double PI=3.1415926536;
printf("[%3x]\n",i);
printf("[%3d]\n",i);
printf("[%3d]\n",j);
printf("[%f]\n",PI);
printf("[%-15.10f]\n",PI);
system("pause");
return 0;
}
輸出[ f],[ 15],[ 2],[3.141593],[3.1415926536 ]
3.
#include <stdio.h>
#include <stdlib.h>
int main()
{
int i;
for(i=0;i<7;i++)
{
if(i==0)
printf("i=%d\n",i);
else if(i==1)
printf("i=%d\n",i);
else if(i==2)
printf("i=%d\n",i);
else
printf("這是期中考\n");
};
printf("i=%d\n",i++);
system("pause");
return 0;
}
輸出
i=0
i=1
i=2
這是期中考
這是期中考
這是期中考
這是期中考
i=7
5.
#include <iostream>
using namespace std;
void prch(char ch,int rows);
int main()
{
for(int i=1;i<=4;i++)
{
prch(' ',4-i);
prch('$',i);
cout<<endl;
}
cin.get();
return 0;
}
void prch(char ch,int rows)
{
for(int i=1;i<=rows;i++)
{
cout<<ch;
}
}
輸出
A
AAX
AAAXX
AAAAXXX
AAAAAXXXX
6.
#include <stdio.h>
#include <stdlib.h>
int main()
{
char x[11]="while-loop";
int i=0, n;
scanf("%d",&n);
while(i<n)
{
printf("%s",x);
i++;
}
system("pause");
return 0;
}
第一題
#include <iostream>
#include <cstdlib>
using namespace std;
int main()
{
int x=5,y=3,z,w;
x-=2;
cout<<x++<<"\n";
z=++y;
cout<<z<<"\n";
cout<<y<<"\n";
w=z<<2;
cout<<z<<"\n";
cout<<w<<"\n";
for(x=4;x<10;x++){
if (x%2==0)continue;
cout<<x<<"\n";
if (x==7) break;
};
cout<<x<<"\n";
system("PAUSE");
return 0;
}
輸出為:
3
4
4
4
16
5
7
7
..........................................
第二題
#include <stdio.h>
#include <stdlib.h>
int main(){
int j=2;
int i=0xf;
const double PI=3.1415926536;
printf("[%3x]\n",i);
printf("[%3d]\n",i);
printf("[%3d]\n",j);
printf("[%f]\n",PI);
printf("[%-15.10f]\n",PI);
system("PAUSE");
return 0;
}
輸出為:
[ f]
[ 15]
[ 2]
[3.141593]
[3.1415926536 ]
----------------------------------------
第三題
#include <stdio.h>
#include <stdlib.h>
int main()
{
int i;
for (i=0;i<7;i++)
{
if(i==0)
{
printf("i=%d\n",i);
}
else if(i==1)
{
printf("i=%d\n",i);
}
else if(i==2)
{
printf("i=%d\n",i);
}
else
{
printf("這是期中考\n");
}
};
printf("i=%d\n",i++);
system("pause");
return 0;
}
輸出為:
i=0
i=1
i=2
這是期中考
這是期中考
這是期中考
這是期中考
i=7
第五題
(1)
#include<iostream>
using namespace std;
void prCh(char ch,int rows);
int main()
{
for(int i=0;i<=5;i++)
{
prCh('A',i+1);
prCh('X',i);
cout<<endl;
}
cin.get();
return 0;
}
void prCh(char ch,int rows)
{
for(int i=1;i<=rows;i++)
{
cout<<ch;
}
}
ans:
A
AAX
AAAXX
AAAAXXX
AAAAAXXXX
AAAAAAXXXXX
(2)
#include<iostream>
using namespace std;
void prCh(char ch,int rows);
int main()
{
for(int i=3;i>=0;i--)
{
prCh(' ',i);
prCh('$',4-i);
cout<<endl;
}
cin.get();
return 0;
}
void prCh(char ch,int rows)
{
for(int i=1;i<=rows;i++)
{
cout<<ch;
}
}
ans:
$
$$
$$$
$$$$
----------------------------------------------------------
第六題
#include <stdio.h>
#include <stdlib.h>
int main()
{
char x[11]="while-loop";
int i=0,n;
scanf("%d",&n);
while(i<n){
printf("%s",x);
i++;
}
system("PAUSE");
return 0;
}
------------------------------------------
第七題
#include <stdio.h>
#include <stdlib.h>
int main()
{
int i,s;
for(i=3;i<1003;i++)
s+=i*(i+1);
printf("%d",s);
system("pause");
return 0;
}
輸出為336342045
1.
#include <cstdlib>
#include <iostream>
using namespace std;
int main()
{
int x=5,y=3,z,w;
x-=2;
cout<<x++<<"\n";
z=++y;
cout<<z<<"\n";
cout<<y<<"\n";
w=z<<2;
cout<<z<<"\n";
cout<<w<<"\n";
for(x=4;x<10;x++){
if (x%2==0) continue;
cout<<x<<"\n";
if (x==7) break;
};
cout<<x<<"\n";
system("pause");
return 0;
}
ANS:
3
4
4
4
16
5
7
7
請按任意鍵繼續 . . .
2.
#include <stdio.h>
#include <stdlib.h>
int main()
{
int j=2, i=0xf;
const double PI=3.1415926536;
printf("[%3x]\n",i);
printf("[%3d]\n",i);
printf("[%3d]\n",j);
printf("[%f]\n",PI);
printf("[%-15.10f]\n",PI);
system("pause");
return 0;
}
ANS:
[ f]
[ 15]
[ 2]
[3.141593]
[3.1415926536 ]
請按任意鍵繼續 . . .
3.
#include <stdio.h>
#include <stdlib.h>
int main()
{
int i;
for(i=0;i<7;i++)
{
if(i==0)
printf("i=%d\n",i);else
if(i==1)
printf("i=%d\n",i);else
if(i==2)
printf("i=%d\n",i);
else
printf("這是期中考\n");
};
printf("i=%d\n",i++);
system ("pause");
return 0;
}
ANS:
i=0
i=1
i=2
這是期中考
這是期中考
這是期中考
這是期中考
i=7
請按任意鍵繼續 . . .
5-1
#include<iostream>
using namespace std;
void prCh(char ch,int rows);
int main()
{
for(int i=0;i<5;i++)
{
prCh('A',i+1);
prCh('X',i);
cout<<endl;
}
cin.get();
return 0;
}
void prCh(char ch,int rows)
{
for(int i=1;i<=rows;i++)
{
cout<<ch;
}
}
ANS:
A
AAX
AAAXX
AAAAXXX
AAAAAXXXX
5-2
#include<iostream>
using namespace std;
void prCh(char ch,int rows);
int main()
{
for(int i=1;i<=4;i++)
{
prCh(' ',4-i);
prCh('$',i);
cout<<endl;
}
cin.get();
return 0;
}
void prCh(char ch,int rows)
{
for(int i=1;i<=rows;i++)
{
cout<<ch;
}
}
ANS:
$
$$
$$$
$$$$
6.
#include<stdio.h>
#include<stdlib.h>
int main()
{
char x[11]="while-loop";
int i=0,n;
scanf("%d",&n);
while(i<n)
{
printf("%s",x);
i++;
}
system("pause");
return 0;
}
7.
#include<stdio.h>
#include<stdlib.h>
int main()
{
int s,i;
for(i=3;i<=1002;i++)
s=s+i*(i+1);
printf("%d",s);
system("pause");
return 0;
}
ANS:
336342002請按任意鍵繼續 . . .
題目1:
#include <cstdlib>
#include <iostream>
using namespace std;
int main()
{
int x=5,y=3,z,w;
x-=2;
cout<<x++<<"\n";
z=++y;
cout<<z<<"\n";
cout<<y<<"\n";
w=z<<2;
cout<<z<<"\n";
cout<<w<<"\n";
for(x=4;x<10;x++)
{
if (x%2==0) continue;
cout<<x<<"\n";
if (x==7) break;
};
cout<<x<<"\n";
system("pause");
return 0;
}
輸出:
3
4
4
4
16
5
7
7
請按任意鍵繼續 . . .
題目2:
#include <stdio.h>
#include <stdlib.h>
int main()
{
int j=2, i=0xf;
const double PI=3.1415926536;
printf("[%3x]\n",i);
printf("[%3d]\n",i);
printf("[%3d]\n",j);
printf("[%f]\n",PI);
printf("[%-15.10f]\n",PI);
system("pause");
return 0;
}
輸出:
3
4
4
4
16
5
7
7
請按任意鍵繼續 . . .
題目3:
#include <stdio.h>
#include <stdlib.h>
int main()
{
int i;
for(i=0;i<7;i++)
{
if(i==0)
printf("i=%d\n",i);
else if(i==1)
printf("i=%d\n",i);
else if(i==2)
printf("i=%d\n",i);
else
printf("這是期中考\n");
}
printf("i=%d\n",i++);
system("pause");
return 0;
}
輸出:
i=0
i=1
i=2
這是期中考
這是期中考
這是期中考
這是期中考
i=7
請按任意鍵繼續 . . .
題目5:
#include <cstdlib>
#include <iostream>
using namespace std;
void prCh(char ch, int rows);
int main()
{
for(int i=0;i<5;i++)
{
prCh('A',i+1);
prCh('x',i);
cout<<endl;
}
cin.get();
return 0;
}
void prCh(char ch, int rows){
for (int i=1; i<=rows; i++)
{
cout<<ch;
}
}
輸出:
A
AAX
AAAXX
AAAAXXX
AAAAAXXX
改寫:
#include <cstdlib>
#include <iostream>
using namespace std;
void prCh(char ch, int rows);
int main()
{
for(int i=3;i>=0;i--)
{
prCh(' ',i);
prCh('$',4-i);
cout<<endl;
}
cin.get();
return 0;
}
void prCh(char ch, int rows){
for (int i=1; i<=rows; i++)
{
cout<<ch;
}
}
輸出:
$
$$
$$$
$$$$
題目6:
#include <stdio.h>
#include <stdlib.h>
int main()
{
char x[11]="while-loop";
int i=0, n;
scanf("%d",&n);
while(i<n)
{
printf("%s",x);
i++;
}
system("pause");
return 0;
}
輸出:
1
while-loop請按任意鍵繼續 . . .
題目7:
#include <stdio.h>
#include <stdlib.h>
int main()
{
int i,s;
for(i=3;i<=1002;i++)
s=s+i*(i+1);
printf("%d",s);
system("pause");
return 0;
}
輸出:
336342049請按任意鍵繼續 . . .
1.
#include <iostream>
#include <cstdio>
using namespace std;
int main()
{
int x=5,y=3,z,w;
x-=2;
cout<<x++<<"\n";
z=++y;
cout<<z<<"\n";
cout<<y<<"\n";
w=z<<2;
cout<<z<<"\n";
cout<<w<<"\n";
for(x=4;x<10;x++){
if (x%2==0) continue;
cout<<x<<"\n";
if(x==7) break;
};
cout<<x<<"\n";
system ("Pause");
return 0;
}
3
4
4
4
16
5
7
7
請按任意鍵繼續 . . .
------------------------------------------------------------------------------------
2.
#include <stdio.h>
#include <stdlib.h>
int main()
{
int j=2,i=0xf;
const double PI=3.1415926536;
printf("[%3x]\n",i);
printf("[%3d]\n",i);
printf("[%3d]\n",j);
printf("[%f]\n",PI);
printf("[%-15.10f]\n",PI);
system("Pause");
return 0;
}
[ f]
[ 15]
[ 2]
[3.141593]
[3.1415926536 ]
請按任意鍵繼續 . . .
----------------------------------------------------------------------------------------
3.
#include <stdio.h>
#include <stdlib.h>
int main(){
int i;
for(i=0;i<7;i++)
{
if(i==0){
printf("i=%d\n",i);}
else if(i==1){
printf("i=%d\n",i);}
else if(i==2){
printf("i=%d\n",i);}
else printf("這是期中考\n",i);}
printf("i=%d\n",i++);
system ("pause");
return 0;
}
i=0
i=1
i=2
這是期中考
這是期中考
這是期中考
這是期中考
i=7
請按任意鍵繼續 . . .
-----------------------------------------------------------------------------------
5.
#include <iostream>
using namespace std;
void prCh(char ch,int rows);
int main(){
for (int i=1;i<5;i++){
prCh (' ',4-i);
prCh ('$',i);
cout<<endl;}
cin.get();
return 0;
}
void prCh(char ch,int rows){
for(int i=1;i<=rows;i++){
cout<<ch;
}
}
$
$$
$$$
$$$$
---------------------------------------------------------------------------------------
6.
#include <stdio.h>
#include <stdlib.h>
int main()
{
char x[11]="while-loop";
int i=0, n;
scanf("%d",&n);
while(i<=0){
printf("%s",x);
i++;
}
system ("pause");
}
-----------------------------------------------------------------------------------------
7.
#include <stdio.h>
#include <stdlib.h>
int main()
{
int i=3,s;
for(i=3;i<=1002;i++)
s+=i*(i+1);
printf("%d\n",s);
system("Pause");
return 0;
}
336342049
請按任意鍵繼續 . . .
1.
#include <cstdlib>
#include <iostream>
using namespace std;
int main ()
{
int x=5,y=3,z,w;
x-=2;
cout<<x++<<"\n";
z=++y;
cout<<z<<"\n";
cout<<y<<"\n";
w=z<<2;
cout<<z<<"\n";
cout<<w<<"\n";
for(x=4;x<10;x++)
{
if (x%2==0)
continue;
cout<<x<<"\n";
if (x==7)
break;
};
cout<<x<<"\n";
system ("pause");
return 0;
}
3.
#include <stdio.h>
#include <stdlib.h>
int main ()
{
int i;
for (i=0;i<7;i++)
{
if(i==0)
printf("i=%d\n",i);
else if (i==1)
printf("i=%d\n",i);
else if (i==2)
printf("i=%d\n",i);
else
printf ("這是期中考\n");
}
printf ("i=%d\n",i++);
system("pause");
return 0;
}
5.
#include <iostream>
using namespace std;
void prCh(char ch, int rows);
int main()
{
for(int i=3;i>=0;i--)
{
prCh(' ',i);
prCh('$',4-i);
cout<<endl;
}
cin.get();
return 0;
}
void prCh (char ch, int rows)
{
for (int i=1;i<=rows;i++)
{
cout<<ch;
}
}
6.
#include <stdio.h>
#include <stdlib.h>
int main ()
{
char x[11]="while-loop";
int i=0,n;
scanf("%d",&n);
while (i<n)
{
printf("%s",x);
i++;
}
system("pause");
return 0;
}
7.
#include <stdio.h>
#include <stdlib.h>
int main()
{
int i,s;
for (i=3;i<=1002;i++)
s=s+i*(i+1);
printf("%d\n",s);
system("pause");
return 0;
}
1.
#include <cstdlib>
#include <iostream>
using namespace std;
int main ()
{
int x=5,y=3,z,w;
x-=2;
cout<<x++<<"\n";
z=++y;
cout<<z<<"\n";
cout<<y<<"\n";
w=z<<2;
cout<<z<<"\n";
cout<<w<<"\n";
for(x=4;x<10;x++)
{
if (x%2==0)
continue;
cout<<x<<"\n";
if (x==7)
break;
};
cout<<x<<"\n";
system ("pause");
return 0;
}
2.
#include <stdio.h>
#include <stdlib.h>
int main(){
int j=2, i=0xf;
const double PT=3.1415926536;
printf("[%3x]\n",i);
printf("[%3d]\n",i);
printf("[%3d]\n",j);
printf("[%f]\n",PT);
printf("[%-15.10f]\n",PT);
system("PAUSE");
return 0;
}
3.
#include <stdio.h>
#include <stdlib.h>
int main ()
{
int i;
for (i=0;i<7;i++)
{
if(i==0)
printf("i=%d\n",i);
else if (i==1)
printf("i=%d\n",i);
else if (i==2)
printf("i=%d\n",i);
else
printf ("這是期中考\n");
}
printf ("i=%d\n",i++);
system("pause");
return 0;
}
5.
#include <iostream>
using namespace std;
void prCh(char ch, int rows);
int main()
{
for(int i=3;i>=0;i--)
{
prCh(' ',i);
prCh('$',4-i);
cout<<endl;
}
cin.get();
return 0;
}
void prCh (char ch, int rows)
{
for (int i=1;i<=rows;i++)
{
cout<<ch;
}
}
6.
#include <stdio.h>
#include <stdlib.h>
int main ()
{
char x[11]="while-loop";
int i=0,n;
scanf("%d",&n);
while (i<n)
{
printf("%s",x);
i++;
}
system("pause");
return 0;
}
張貼留言