C语言大一期末开卷考试 求经典题目很多的资料 能找到很多经典代码的 (不要知识点 就要编程题很多的)
发布网友
发布时间:2022-04-30 04:33
我来回答
共4个回答
热心网友
时间:2023-10-13 00:10
数组
#include <iostream.h>
void main()
{ int i;
int f[20]={1,1};
for(i=2;i<=19;i++)
f[i]=f[i-2]+f[i-1];
for(i=0;i<=19;i++)
{ if(i%5==0) cout<<endl;
cout<<f[i];
}
}
指针的地址传递
swap(int *p1, int *p2)
{ int p;
p=*p1;
*p1=*p2;
*p2=p;
}
void main()
{ int a,b;
int *pointer_1,*pointer_2;
cin>>a>>b;
pointer_1=&a; pointer_2=&b;
if(a<b) swap(pointer_1,pointer_2);
cout<<a<<b;
例2:输出已知一维数组中的5个整型数
(数组表示形式)
#include<iostream.h>
void main( )
{
int a[5]={1,2,3,4,5},i;
for (i=0;i<5;i++)
cout<<a[i];
设计一个函数可以计算一维数组中所有元素之和
#include <iostream.h>
int sum(int *p,int n)
{
int i,s=0;
for(i=0;i<n;i++,p++)
s+=*p;
return s;
}
void main()
{
int y,score[10]={90,82,88,78,100,95,87,72,91,85};
y=sum(score,10);
cout<<"总成绩为:"<<y<<endl;
}
#include <iostream.h> main ( ) { int grade; float score;
cout<<“请输入成绩:”;
cin>>score;
grade=(int)score/10;
switch(grade)
{ case 10:
case 9:cout<<“优”;break;
case 8: cout<<“良”;break;
case 7: cout<<“中”;break;
case 6: cout<<“及格”;break;
case 5:
case 4:
case 3:
case 2:
case 1:
case 0::cout<<“不及格”;break;
default: cout<<“输入错误!”;
}
}计算并输出1~10000这10000个数的平方
#include <iostream>
using namespace std;
int main()
{
int i=1;
while(i<=10000)
{
cout<<i*i;
}
return 0;
}
For yu ju
#include <iostream>
using namespace std;int main ( ){
int i,sum;
sum=0; for ( i=1; i<=10; i++) sum=sum+i; cout<<“1+2+3+…+10=”<<sum; return 0;
}
#include <iostream>
using namespace std;int main ( ){
int r=1;
float area;
while(1) { area=3.14159rr; if (area>100) break; cout<<"r=“<<r<<“, area=“<<area; r=r+1;
} return 0;
}
杨辉三角
#include <stdio.h>
void main(){
int a[7][7]={0},i,j;
for(i=0;i<7;i++){
for(j=0;j<7-i;j++)
printf(" ");
for(j=0;j<i+1;j++){
if(j==0||j==i) printf("%4d",1);
else {a[i][7-i]=a[i-1][7-i]+a[i-1][7-i+1]+2;
printf("%4d",a[i][7-i]);}
}
printf("\n");
}
}
汉诺塔
#include<iostream.h>
void hanoi(int n,char no1,char no2,char no3)
{
if (n==1)
cout<<no1<<"移动到"<<no3<<endl;
else
{
hanoi(n-1,no1,no3,no2);
cout<<no1<<"移动到"<<no3<<endl;
hanoi(n-1,no2,no1,no3);
}
}
void main()
{
int m;
cout<<"请输入A柱上的金盘子总数:";
cin>>m;
cout<<"当有"<<m<<"个金盘子时,移动步骤依次为:"<<endl;
hanoi(m,'A','B','C');
}
连乘
#include <iostream.h>
void main()
{
int i,n,t=1;
cin>>n;
if (n<0)
cout<<“输入有误!\n";
else
for(i=1;i<=n;i++)
t=t*i;
cout<<n<<“!=”<<t<<endl;
数组
#include <iostream.h>
void main ( )
{
int a[2][3]={{1,2,3},{4,5,6}},b[2][3] ={{7,8,9},{10,11,12}};
int c[2][3],i,j;
for (i=0;i<=1;i++)
for (j=0;j<=2;j++)
c[i][j]=b[i][j]+a[i][j];
cout<<"数组c:"<<endl;
for (i=0;i<=1;i++)
{
for (j=0;j<=2;j++)
cout<<" "<<c[i][j];
cout<<endl;
}
}
输出***1
#include <iostream>
using namespace std;
int main()
{
int i,j;
for(i=1;i<=5;i++)
{
for(j=1;j<=3;j++)
cout<< "*";
cout<<endl;
}
return 0;
}
*****2
#include <iostream>
using namespace std;
int main()
int i,j,k;
for(i=1;i<=5;i++)
{
for(j=1;j<=5-i;j++)
cout<<" ";
for(k=1;k<=2*i-1;k++)
cout<< "*";
cout<<endl;
}
return 0;
}
九九乘法表
#include <iostream.h>
void main()
{
int i,j;
for(i=1;i<=9;i++)
{
for(j=1;j<=i;j++)
cout<<i<<"x"<<j<<"="<<i*j<<" ";
cout<<endl;
斐波那契数列
1)#include <iostream>
using namespace std;
int main()
{
long int f1, f2,f3,f4,f5,f6,f7,f8,f9,f10;
f1=1; f2=1;
f3=f1+f2;
f4=f2+f3;
f5=f3+f4;
f6=f4+f5;
f7=f5+f6;
f8=f6+f7;
f9=f7+f8;
f10=f8+f9;
cout<<f1<<" "<<f2<<" "<<f3<<" "<<f4<<" "<<f5<<" "<<f6<<" "<<f7<<" "<<f8<<" "<<f9<<" "<<f10;
return 0;
2)#include <iostream>
using namespace std;
int main()
{
long int f1, f2;
int i;
f1=1; f2=1;
for (i=1; i<=5; i++)
{
cout<<" "<<f1<<" "<<f2;
f1=f1+f2;
f2=f2+f1;
}
return 0;
}
数组
#include <iostream.h>
void main()
{ int i;
int f[20]={1,1};
for(i=2;i<=19;i++)
f[i]=f[i-2]+f[i-1];
for(i=0;i<=19;i++)
{ if(i%5==0) cout<<endl;
cout<<f[i];
}
}
指针的地址传递
swap(int *p1, int *p2)
{ int p;
p=*p1;
*p1=*p2;
*p2=p;
}
void main()
{ int a,b;
int *pointer_1,*pointer_2;
cin>>a>>b;
pointer_1=&a; pointer_2=&b;
if(a<b) swap(pointer_1,pointer_2);
cout<<a<<b;
例2:输出已知一维数组中的5个整型数
(数组表示形式)
#include<iostream.h>
void main( )
{
int a[5]={1,2,3,4,5},i;
for (i=0;i<5;i++)
cout<<a[i];
设计一个函数可以计算一维数组中所有元素之和
#include <iostream.h>
int sum(int *p,int n)
{
int i,s=0;
for(i=0;i<n;i++,p++)
s+=*p;
return s;
}
void main()
{
int y,score[10]={90,82,88,78,100,95,87,72,91,85};
y=sum(score,10);
cout<<"总成绩为:"<<y<<endl;
}
#include <iostream.h> main ( ) { int grade; float score;
cout<<“请输入成绩:”;
cin>>score;
grade=(int)score/10;
switch(grade)
{ case 10:
case 9:cout<<“优”;break;
case 8: cout<<“良”;break;
case 7: cout<<“中”;break;
case 6: cout<<“及格”;break;
case 5:
case 4:
case 3:
case 2:
case 1:
case 0::cout<<“不及格”;break;
default: cout<<“输入错误!”;
}
}计算并输出1~10000这10000个数的平方
#include <iostream>
using namespace std;
int main()
{
int i=1;
while(i<=10000)
{
cout<<i*i;
}
return 0;
}
For yu ju
#include <iostream>
using namespace std;int main ( ){
int i,sum;
sum=0; for ( i=1; i<=10; i++) sum=sum+i; cout<<“1+2+3+…+10=”<<sum; return 0;
}
#include <iostream>
using namespace std;int main ( ){
int r=1;
float area;
while(1) { area=3.14159rr; if (area>100) break; cout<<"r=“<<r<<“, area=“<<area; r=r+1;
} return 0;
}
热心网友
时间:2023-10-13 00:11
《C程序设计》(第三版)谭浩强 著。清华大学出版社追问但是那很多都是概念 我要题目例题编程题较多的
追答这个里面有好多例题啊,而且挺经典的
热心网友
时间:2023-10-13 00:11
有个经典代码100条 你下载下看看 上面都是经典立体
热心网友
时间:2023-10-13 00:12
c编程大全追问书的题目叫这个? 作者是?
追答C语言范例开发大全
作 者:刘艳飞,迟剑,房健
热心网友
时间:2023-10-13 00:10
数组
#include <iostream.h>
void main()
{ int i;
int f[20]={1,1};
for(i=2;i<=19;i++)
f[i]=f[i-2]+f[i-1];
for(i=0;i<=19;i++)
{ if(i%5==0) cout<<endl;
cout<<f[i];
}
}
指针的地址传递
swap(int *p1, int *p2)
{ int p;
p=*p1;
*p1=*p2;
*p2=p;
}
void main()
{ int a,b;
int *pointer_1,*pointer_2;
cin>>a>>b;
pointer_1=&a; pointer_2=&b;
if(a<b) swap(pointer_1,pointer_2);
cout<<a<<b;
例2:输出已知一维数组中的5个整型数
(数组表示形式)
#include<iostream.h>
void main( )
{
int a[5]={1,2,3,4,5},i;
for (i=0;i<5;i++)
cout<<a[i];
设计一个函数可以计算一维数组中所有元素之和
#include <iostream.h>
int sum(int *p,int n)
{
int i,s=0;
for(i=0;i<n;i++,p++)
s+=*p;
return s;
}
void main()
{
int y,score[10]={90,82,88,78,100,95,87,72,91,85};
y=sum(score,10);
cout<<"总成绩为:"<<y<<endl;
}
#include <iostream.h> main ( ) { int grade; float score;
cout<<“请输入成绩:”;
cin>>score;
grade=(int)score/10;
switch(grade)
{ case 10:
case 9:cout<<“优”;break;
case 8: cout<<“良”;break;
case 7: cout<<“中”;break;
case 6: cout<<“及格”;break;
case 5:
case 4:
case 3:
case 2:
case 1:
case 0::cout<<“不及格”;break;
default: cout<<“输入错误!”;
}
}计算并输出1~10000这10000个数的平方
#include <iostream>
using namespace std;
int main()
{
int i=1;
while(i<=10000)
{
cout<<i*i;
}
return 0;
}
For yu ju
#include <iostream>
using namespace std;int main ( ){
int i,sum;
sum=0; for ( i=1; i<=10; i++) sum=sum+i; cout<<“1+2+3+…+10=”<<sum; return 0;
}
#include <iostream>
using namespace std;int main ( ){
int r=1;
float area;
while(1) { area=3.14159rr; if (area>100) break; cout<<"r=“<<r<<“, area=“<<area; r=r+1;
} return 0;
}
杨辉三角
#include <stdio.h>
void main(){
int a[7][7]={0},i,j;
for(i=0;i<7;i++){
for(j=0;j<7-i;j++)
printf(" ");
for(j=0;j<i+1;j++){
if(j==0||j==i) printf("%4d",1);
else {a[i][7-i]=a[i-1][7-i]+a[i-1][7-i+1]+2;
printf("%4d",a[i][7-i]);}
}
printf("\n");
}
}
汉诺塔
#include<iostream.h>
void hanoi(int n,char no1,char no2,char no3)
{
if (n==1)
cout<<no1<<"移动到"<<no3<<endl;
else
{
hanoi(n-1,no1,no3,no2);
cout<<no1<<"移动到"<<no3<<endl;
hanoi(n-1,no2,no1,no3);
}
}
void main()
{
int m;
cout<<"请输入A柱上的金盘子总数:";
cin>>m;
cout<<"当有"<<m<<"个金盘子时,移动步骤依次为:"<<endl;
hanoi(m,'A','B','C');
}
连乘
#include <iostream.h>
void main()
{
int i,n,t=1;
cin>>n;
if (n<0)
cout<<“输入有误!\n";
else
for(i=1;i<=n;i++)
t=t*i;
cout<<n<<“!=”<<t<<endl;
数组
#include <iostream.h>
void main ( )
{
int a[2][3]={{1,2,3},{4,5,6}},b[2][3] ={{7,8,9},{10,11,12}};
int c[2][3],i,j;
for (i=0;i<=1;i++)
for (j=0;j<=2;j++)
c[i][j]=b[i][j]+a[i][j];
cout<<"数组c:"<<endl;
for (i=0;i<=1;i++)
{
for (j=0;j<=2;j++)
cout<<" "<<c[i][j];
cout<<endl;
}
}
输出***1
#include <iostream>
using namespace std;
int main()
{
int i,j;
for(i=1;i<=5;i++)
{
for(j=1;j<=3;j++)
cout<< "*";
cout<<endl;
}
return 0;
}
*****2
#include <iostream>
using namespace std;
int main()
int i,j,k;
for(i=1;i<=5;i++)
{
for(j=1;j<=5-i;j++)
cout<<" ";
for(k=1;k<=2*i-1;k++)
cout<< "*";
cout<<endl;
}
return 0;
}
九九乘法表
#include <iostream.h>
void main()
{
int i,j;
for(i=1;i<=9;i++)
{
for(j=1;j<=i;j++)
cout<<i<<"x"<<j<<"="<<i*j<<" ";
cout<<endl;
斐波那契数列
1)#include <iostream>
using namespace std;
int main()
{
long int f1, f2,f3,f4,f5,f6,f7,f8,f9,f10;
f1=1; f2=1;
f3=f1+f2;
f4=f2+f3;
f5=f3+f4;
f6=f4+f5;
f7=f5+f6;
f8=f6+f7;
f9=f7+f8;
f10=f8+f9;
cout<<f1<<" "<<f2<<" "<<f3<<" "<<f4<<" "<<f5<<" "<<f6<<" "<<f7<<" "<<f8<<" "<<f9<<" "<<f10;
return 0;
2)#include <iostream>
using namespace std;
int main()
{
long int f1, f2;
int i;
f1=1; f2=1;
for (i=1; i<=5; i++)
{
cout<<" "<<f1<<" "<<f2;
f1=f1+f2;
f2=f2+f1;
}
return 0;
}
数组
#include <iostream.h>
void main()
{ int i;
int f[20]={1,1};
for(i=2;i<=19;i++)
f[i]=f[i-2]+f[i-1];
for(i=0;i<=19;i++)
{ if(i%5==0) cout<<endl;
cout<<f[i];
}
}
指针的地址传递
swap(int *p1, int *p2)
{ int p;
p=*p1;
*p1=*p2;
*p2=p;
}
void main()
{ int a,b;
int *pointer_1,*pointer_2;
cin>>a>>b;
pointer_1=&a; pointer_2=&b;
if(a<b) swap(pointer_1,pointer_2);
cout<<a<<b;
例2:输出已知一维数组中的5个整型数
(数组表示形式)
#include<iostream.h>
void main( )
{
int a[5]={1,2,3,4,5},i;
for (i=0;i<5;i++)
cout<<a[i];
设计一个函数可以计算一维数组中所有元素之和
#include <iostream.h>
int sum(int *p,int n)
{
int i,s=0;
for(i=0;i<n;i++,p++)
s+=*p;
return s;
}
void main()
{
int y,score[10]={90,82,88,78,100,95,87,72,91,85};
y=sum(score,10);
cout<<"总成绩为:"<<y<<endl;
}
#include <iostream.h> main ( ) { int grade; float score;
cout<<“请输入成绩:”;
cin>>score;
grade=(int)score/10;
switch(grade)
{ case 10:
case 9:cout<<“优”;break;
case 8: cout<<“良”;break;
case 7: cout<<“中”;break;
case 6: cout<<“及格”;break;
case 5:
case 4:
case 3:
case 2:
case 1:
case 0::cout<<“不及格”;break;
default: cout<<“输入错误!”;
}
}计算并输出1~10000这10000个数的平方
#include <iostream>
using namespace std;
int main()
{
int i=1;
while(i<=10000)
{
cout<<i*i;
}
return 0;
}
For yu ju
#include <iostream>
using namespace std;int main ( ){
int i,sum;
sum=0; for ( i=1; i<=10; i++) sum=sum+i; cout<<“1+2+3+…+10=”<<sum; return 0;
}
#include <iostream>
using namespace std;int main ( ){
int r=1;
float area;
while(1) { area=3.14159rr; if (area>100) break; cout<<"r=“<<r<<“, area=“<<area; r=r+1;
} return 0;
}
热心网友
时间:2023-10-13 00:11
《C程序设计》(第三版)谭浩强 著。清华大学出版社追问但是那很多都是概念 我要题目例题编程题较多的
追答这个里面有好多例题啊,而且挺经典的
热心网友
时间:2023-10-13 00:11
有个经典代码100条 你下载下看看 上面都是经典立体
热心网友
时间:2023-10-13 00:12
c编程大全追问书的题目叫这个? 作者是?
追答C语言范例开发大全
作 者:刘艳飞,迟剑,房健