Ⅰ c語言題庫
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Dome2
{
class Student
{
public string name;
public float[] score=new float[3];
public float sum, avg;
public void InitScore()
{
this.sum = 0;
this.avg = 0;
}
public void GetScore()
{
Console.WriteLine("學員姓名:");
this.name = Console.ReadLine();
for (int i = 0; i < score.Length; i++)
{
Console.WriteLine("第{0}門的成績是:",i+1);
this.score[i] = float.Parse(Console.ReadLine());
}
Console.WriteLine();
}
public void GetSum()
{
for (int i = 0; i < score.Length; i++)
{
this.sum+=this.score[i];
}
this.avg = this.sum / 3;
}
public void DisplayScore()
{
Console.WriteLine("學員姓名:{0}", this.name);
for (int j = 0; j < 3; j++)
{
Console.WriteLine("第{0}門課程考試成績是{1}", j + 1, this.score[j]);
} Console.WriteLine("三門課程的總成績是{0},平均成績是{1}",this.sum, this.avg.ToString("0.00"));
Console.WriteLine();
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Dome2
{
class Program
{
static void Main(string[] args)
{
Student[] student = new Student[5];
float max = 0,average = 0;
int i;
int counter = 0;
for (i = 0; i < student.Length; i++)
{
student[i] = new Student();
student[i].GetScore();
student[i].GetSum();
}
for (i = 0; i < student.Length; i++)
{
student[i].DisplayScore();
}
Console.WriteLine("");
Console.WriteLine("");
Console.WriteLine("");
Console.WriteLine("");
Console.WriteLine("========================================================");
for (i = 0; i < student.Length;i++ )
{
counter++;
max = student[i].sum + max;
average = student[i].avg + average;
}
Console.WriteLine("班級參加考試人數:{0} 最高分:{1} 平均分:{2}", counter, max, average);
}
}
}
Ⅱ c語言哪個搜題軟體好用
大學c語言搜題app。大學c語言搜題app原名叫做菜鳥學C語言是一款非常好用的學習c語言的手機軟體
軟體功能
1、選擇題:按照考點分類的選擇題習題,並有答案解析。
2、錯題庫:可自動加練習過程中錯題加入收藏,以便反復練習。
3、上機操作題:300道上機操作題,程序填空題、程序修改題、程序設計題。
軟體優勢
1、選擇題:按照考點分類的選擇題習題,並有答案解析。
2、上級操作題:300道上機操作題,程序填空題、程序修改題、程序設計題。
3、最新押題:最新考試押題3套。
4、考點匯總:包含復習的考點。
5、錯題庫:可自動加練習過程中錯題加入收藏,以便反復練習。
6、收藏夾:可在練習過程中自行收錄題目到收藏夾,形成自己的小題庫,針對性練習,提高通過率。
軟體特色
1、隨時隨地都能夠學習,而且還支持下載保存你學習內容離線繼續學習。
2、同學們能夠直接通過搜索引擎來查詢尋找你感興趣對你內容。
3、解答問題的辦法非常多,可以選擇通過拍照來答題,也可以選擇輸入題目來解答。
Ⅲ 幾道C語言的題
第一題(1):(後面的題庫函數引用就省略了)
#include <stdio.h>
void main()
{ float a,b; int c,d;
printf("Please enter a b c and d:");
scanf("%f %f %d %d",&a,&b,&c,&d);
if(a>b) printf("%lu\n",&a); else printf("%lu\n",&b);
if(c>d) printf("%lu\n",&c); else printf("%lu\n",&d); }
第一題(2):
int houzi(int n)
{ if(n==1) return 1;
return 2*(houzi(n-1)-1); }
void main()
{ printf("%d\n",houzi(10)); }
第一題(3):
#include <math.h>
float fun(float x)
{ return x*x-5*x+4; }
void main()
{ float x1=2,x2,x3;
printf("Please enter the number of x2 and x3:");
scanf("%f %f",&x2,&x3);
x2+=15;x3=sin(x3);
printf("y1=%6.2f\n",fun(x1));
printf("y2=%6.2f\n",fun(x2));
printf("y3=%6.2f\n",fun(x3)); }
第一題(4):
#include <stdio.h>
void main()
{
int a[30],i,highest=0,lowest=0;double aver=0.0;
for(i=0;i<30;i++) scanf("%d",&a[i]); highest=a[0];lowest=a[0];aver=a[0]/30.0;
for(i=1;i<30;i++)
{ if(a[i]>highest) highest=a[i];
if(a[i]<lowest) lowest=a[i];
aver+=a[i]/30.0; }
printf("Highest score is:%d\n",highest);
printf("Lowest score is:%d\n",lowest);
printf("Average score is:%6.2f\n",aver); }
第一題(5)<1>:
#include <stdio.h>
#includes<math.h>
void main()
{ int sum=0,i=1,n=1;
while(fabs(i)<=101)
{ sum+=i;
if(i>0) {i+=2;i=-i;} else {i-=2;i=-i;} }
printf("sum=%d\n",sum); }
第一題(5)<2>:
#include <stdio.h>
#include <math.h>
void main()
{ double pai=0.0,n=1.0;
for(;fabs(1/n)>=1e-6;)
{ pai+=1.0/n; if(n>0) {n=n+2.0;n=-n;} else if(n<0) {n=n-2.0;n=-n;} }
pai*=4;
printf("pai=%8.6f\n",pai); }
程序打不下了,在補充回答里繼續把答案打完……
Ⅳ 誰給我提供一套C語言編程題庫
題目:列印出楊輝三角形(要求列印出10行如下圖)
1.程序分析:
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
1 5 10 10 5 1
2.程序源代碼:
main()
{int i,j;
int a[10][10];
printf("\n");
for(i=0;i<10;i++)
{a[i][0]=1;
a[i][i]=1;}
for(i=2;i<10;i++)
for(j=1;j a[i][j]=a[i-1][j-1]+a[i-1][j];
for(i=0;i<10;i++)
{for(j=0;j<=i;j++)
printf("]",a[i][j]);
printf("\n");
}
}
==============================================================
【程序62】
題目:學習putpixel畫點。
1.程序分析:
2.程序源代碼:
#include "stdio.h"
#include "graphics.h"
main()
{
int i,j,driver=VGA,mode=VGAHI;
initgraph(&driver,&mode,"");
setbkcolor(YELLOW);
for(i=50;i<=230;i+=20)
for(j=50;j<=230;j++)
putpixel(i,j,1);
for(j=50;j<=230;j+=20)
for(i=50;i<=230;i++)
putpixel(i,j,1);
}
==============================================================
【程序63】
題目:畫橢圓ellipse
1.程序分析:
2.程序源代碼:
#include "stdio.h"
#include "graphics.h"
#include "conio.h"
main()
{
int x=360,y=160,driver=VGA,mode=VGAHI;
int num=20,i;
int top,bottom;
initgraph(&driver,&mode,"");
top=y-30;
bottom=y-30;
for(i=0;i{
ellipse(250,250,0,360,top,bottom);
top-=5;
bottom+=5;
}
getch();
}
==============================================================
【程序64】
題目:利用ellipse and rectangle 畫圖。
1.程序分析:
2.程序源代碼:
#include "stdio.h"
#include "graphics.h"
#include "conio.h"
main()
{
int driver=VGA,mode=VGAHI;
int i,num=15,top=50;
int left=20,right=50;
initgraph(&driver,&mode,"");
for(i=0;i{
ellipse(250,250,0,360,right,left);
ellipse(250,250,0,360,20,top);
rectangle(20-2*i,20-2*i,10*(i+2),10*(i+2));
right+=5;
left+=5;
top+=10;
}
getch();
}
==============================================================
【程序65】
題目:一個最優美的圖案。
1.程序分析:
2.程序源代碼:
#include "graphics.h"
#include "math.h"
#include "dos.h"
#include "conio.h"
#include "stdlib.h"
#include "stdio.h"
#include "stdarg.h"
#define MAXPTS 15
#define PI 3.1415926
struct PTS {
int x,y;
};
double AspectRatio=0.85;
void LineToDemo(void)
{
struct viewporttype vp;
struct PTS points[MAXPTS];
int i, j, h, w, xcenter, ycenter;
int radius, angle, step;
double rads;
printf(" MoveTo / LineTo Demonstration" );
getviewsettings( &vp );
h = vp.bottom - vp.top;
w = vp.right - vp.left;
xcenter = w / 2; /* Determine the center of circle */
ycenter = h / 2;
radius = (h - 30) / (AspectRatio * 2);
step = 360 / MAXPTS; /* Determine # of increments */
angle = 0; /* Begin at zero degrees */
for( i=0 ; irads = (double)angle * PI / 180.0; /* Convert angle to radians */
points[i].x = xcenter + (int)( cos(rads) * radius );
points[i].y = ycenter - (int)( sin(rads) * radius * AspectRatio );
angle += step; /* Move to next increment */
}
circle( xcenter, ycenter, radius ); /* Draw bounding circle */
for( i=0 ; ifor( j=i ; jmoveto(points[i].x, points[i].y); /* Move to beginning of cord */
lineto(points[j].x, points[j].y); /* Draw the cord */
} } }
main()
{int driver,mode;
driver=CGA;mode=CGAC0;
initgraph(&driver,&mode,"");
setcolor(3);
setbkcolor(GREEN);
LineToDemo();}
==============================================================
【程序66】
題目:輸入3個數a,b,c,按大小順序輸出。
1.程序分析:利用指針方法。
2.程序源代碼:
/*pointer*/
main()
{
int n1,n2,n3;
int *pointer1,*pointer2,*pointer3;
printf("please input 3 number:n1,n2,n3:");
scanf("%d,%d,%d",&n1,&n2,&n3);
pointer1=&n1;
pointer2=&n2;
pointer3=&n3;
if(n1>n2) swap(pointer1,pointer2);
if(n1>n3) swap(pointer1,pointer3);
if(n2>n3) swap(pointer2,pointer3);
printf("the sorted numbers are:%d,%d,%d\n",n1,n2,n3);
}
swap(p1,p2)
int *p1,*p2;
{int p;
p=*p1;*p1=*p2;*p2=p;
}
==============================================================
【程序67】
題目:輸入數組,最大的與第一個元素交換,最小的與最後一個元素交換,輸出數組。
1.程序分析:譚浩強的書中答案有問題。
2.程序源代碼:
main()
{
int number[10];
input(number);
max_min(number);
output(number);
}
input(number)
int number[10];
{int i;
for(i=0;i<9;i++)
scanf("%d,",&number[i]);
scanf("%d",&number[9]);
}
max_min(array)
int array[10];
{int *max,*min,k,l;
int *p,*arr_end;
arr_end=array+10;
max=min=array;
for(p=array+1;p if(*p>*max) max=p;
else if(*p<*min) min=p;
k=*max;
l=*min;
*p=array[0];array[0]=l;l=*p;
*p=array[9];array[9]=k;k=*p;
return;
}
output(array)
int array[10];
{ int *p;
for(p=array;p printf("%d,",*p);
printf("%d\n",array[9]);
}
==============================================================
【程序68】
題目:有n個整數,使其前面各數順序向後移m個位置,最後m個數變成最前面的m個數
1.程序分析:
2.程序源代碼:
main()
{
int number[20],n,m,i;
printf("the total numbers is:");
scanf("%d",&n);
printf("back m:");
scanf("%d",&m);
for(i=0;i scanf("%d,",&number[i]);
scanf("%d",&number[n-1]);
move(number,n,m);
for(i=0;i printf("%d,",number[i]);
printf("%d",number[n-1]);
}
move(array,n,m)
int n,m,array[20];
{
int *p,array_end;
array_end=*(array+n-1);
for(p=array+n-1;p>array;p--)
*p=*(p-1);
*array=array_end;
m--;
if(m>0) move(array,n,m);
}
==============================================================
【程序69】
題目:有n個人圍成一圈,順序排號。從第一個人開始報數(從1到3報數),凡報到3的人退出
圈子,問最後留下的是原來第幾號的那位。
1. 程序分析:
2.程序源代碼:
#define nmax 50
main()
{
int i,k,m,n,num[nmax],*p;
printf("please input the total of numbers:");
scanf("%d",&n);
p=num;
for(i=0;i *(p+i)=i+1;
i=0;
k=0;
m=0;
while(m {
if(*(p+i)!=0) k++;
if(k==3)
{ *(p+i)=0;
k=0;
m++;
}
i++;
if(i==n) i=0;
}
while(*p==0) p++;
printf("%d is left\n",*p);
}
==============================================================
【程序70】
題目:寫一個函數,求一個字元串的長度,在main函數中輸入字元串,並輸出其長度。
1.程序分析:
2.程序源代碼:
main()
{
int len;
char *str[20];
printf("please input a string:\n");
scanf("%s",str);
len=length(str);
printf("the string has %d characters.",len);
}
length(p)
char *p;
{
int n;
n=0;
while(*p!='\0')
{
n++;
p++;
}
return n;
}
【程序71】
題目:編寫input()和output()函數輸入,輸出5個學生的數據記錄。
1.程序分析:
2.程序源代碼:
#define N 5
struct student
{ char num[6];
char name[8];
int score[4];
} stu[N];
input(stu)
struct student stu[];
{ int i,j;
for(i=0;i { printf("\n please input %d of %d\n",i+1,N);
printf("num: ");
scanf("%s",stu[i].num);
printf("name: ");
scanf("%s",stu[i].name);
for(j=0;j<3;j++)
{ printf("score %d.",j+1);
scanf("%d",&stu[i].score[j]);
}
printf("\n");
}
}
print(stu)
struct student stu[];
{ int i,j;
printf("\nNo. Name Sco1 Sco2 Sco3\n");
for(i=0;i{ printf("%-6s%-10s",stu[i].num,stu[i].name);
for(j=0;j<3;j++)
printf("%-8d",stu[i].score[j]);
printf("\n");
}
}
main()
{
input();
print();
}
==============================================================
【程序72】
題目:創建一個鏈表。
1.程序分析:
2.程序源代碼:
/*creat a list*/
#include "stdlib.h"
#include "stdio.h"
struct list
{ int data;
struct list *next;
};
typedef struct list node;
typedef node *link;
void main()
{ link ptr,head;
int num,i;
ptr=(link)malloc(sizeof(node));
ptr=head;
printf("please input 5 numbers==>\n");
for(i=0;i<=4;i++)
{
scanf("%d",&num);
ptr->data=num;
ptr->next=(link)malloc(sizeof(node));
if(i==4) ptr->next=NULL;
else ptr=ptr->next;
}
ptr=head;
while(ptr!=NULL)
{ printf("The value is ==>%d\n",ptr->data);
ptr=ptr->next;
}
}
==============================================================
【程序73】
題目:反向輸出一個鏈表。
1.程序分析:
2.程序源代碼:
/*reverse output a list*/
#include "stdlib.h"
#include "stdio.h"
struct list
{ int data;
struct list *next;
};
typedef struct list node;
typedef node *link;
void main()
{ link ptr,head,tail;
int num,i;
tail=(link)malloc(sizeof(node));
tail->next=NULL;
ptr=tail;
printf("\nplease input 5 data==>\n");
for(i=0;i<=4;i++)
{
scanf("%d",&num);
ptr->data=num;
head=(link)malloc(sizeof(node));
head->next=ptr;
ptr=head;
}
ptr=ptr->next;
while(ptr!=NULL)
{ printf("The value is ==>%d\n",ptr->data);
ptr=ptr->next;
}}
==============================================================
【程序74】
題目:連接兩個鏈表。
1.程序分析:
2.程序源代碼:
#include "stdlib.h"
#include "stdio.h"
struct list
{ int data;
struct list *next;
};
typedef struct list node;
typedef node *link;
link delete_node(link pointer,link tmp)
{if (tmp==NULL) /*delete first node*/
return pointer->next;
else
{ if(tmp->next->next==NULL)/*delete last node*/
tmp->next=NULL;
else /*delete the other node*/
tmp->next=tmp->next->next;
return pointer;
}
}
void selection_sort(link pointer,int num)
{ link tmp,btmp;
int i,min;
for(i=0;i {
tmp=pointer;
min=tmp->data;
btmp=NULL;
while(tmp->next)
{ if(min>tmp->next->data)
{min=tmp->next->data;
btmp=tmp;
}
tmp=tmp->next;
}
printf("\40: %d\n",min);
pointer=delete_node(pointer,btmp);
}
}
link create_list(int array[],int num)
{ link tmp1,tmp2,pointer;
int i;
pointer=(link)malloc(sizeof(node));
pointer->data=array[0];
tmp1=pointer;
for(i=1;i{ tmp2=(link)malloc(sizeof(node));
tmp2->next=NULL;
tmp2->data=array[i];
tmp1->next=tmp2;
tmp1=tmp1->next;
}
return pointer;
}
link concatenate(link pointer1,link pointer2)
{ link tmp;
tmp=pointer1;
while(tmp->next)
tmp=tmp->next;
tmp->next=pointer2;
return pointer1;
}
void main(void)
{ int arr1[]={3,12,8,9,11};
link ptr;
ptr=create_list(arr1,5);
selection_sort(ptr,5);
}
==============================================================
【程序75】
題目:放鬆一下,算一道簡單的題目。
1.程序分析:
2.程序源代碼:
main()
{
int i,n;
for(i=1;i<5;i++)
{ n=0;
if(i!=1)
n=n+1;
if(i==3)
n=n+1;
if(i==4)
n=n+1;
if(i!=4)
n=n+1;
if(n==3)
printf("zhu hao shi de shi:%c",64+i);
}
}
==============================================================
【程序76】
題目:編寫一個函數,輸入n為偶數時,調用函數求1/2+1/4+...+1/n,當輸入n為奇數時,調用函數
1/1+1/3+...+1/n(利用指針函數)
1.程序分析:
2.程序源代碼:
main()
#include "stdio.h"
main()
{
float peven(),podd(),dcall();
float sum;
int n;
while (1)
{
scanf("%d",&n);
if(n>1)
break;
}
if(n%2==0)
{
printf("Even=");
sum=dcall(peven,n);
}
else
{
printf("Odd=");
sum=dcall(podd,n);
}
printf("%f",sum);
}
float peven(int n)
{
float s;
int i;
s=1;
for(i=2;i<=n;i+=2)
s+=1/(float)i;
return(s);
}
float podd(n)
int n;
{
float s;
int i;
s=0;
for(i=1;i<=n;i+=2)
s+=1/(float)i;
return(s);
}
float dcall(fp,n)
float (*fp)();
int n;
{
float s;
s=(*fp)(n);
return(s);
}
==============================================================
【程序77】
題目:填空練習(指向指針的指針)
1.程序分析:
2.程序源代碼:
main()
{ char *s[]={"man","woman","girl","boy","sister"};
char **q;
int k;
for(k=0;k<5;k++)
{ ;/*這里填寫什麼語句*/
printf("%s\n",*q);
}
}
==============================================================
【程序78】
題目:找到年齡最大的人,並輸出。請找出程序中有什麼問題。
1.程序分析:
2.程序源代碼:
#define N 4
#include "stdio.h"
static struct man
{ char name[20];
int age;
} person[N]={"li",18,"wang",19,"zhang",20,"sun",22};
main()
{struct man *q,*p;
int i,m=0;
p=person;
for (i=0;i{if(mage)
q=p++;
m=q->age;}
printf("%s,%d",(*q).name,(*q).age);
}
==============================================================
【程序79】
題目:字元串排序。
1.程序分析:
2.程序源代碼:
main()
{
char *str1[20],*str2[20],*str3[20];
char swap();
printf("please input three strings\n");
scanf("%s",str1);
scanf("%s",str2);
scanf("%s",str3);
if(strcmp(str1,str2)>0) swap(str1,str2);
if(strcmp(str1,str3)>0) swap(str1,str3);
if(strcmp(str2,str3)>0) swap(str2,str3);
printf("after being sorted\n");
printf("%s\n%s\n%s\n",str1,str2,str3);
}
char swap(p1,p2)
char *p1,*p2;
{
char *p[20];
strcpy(p,p1);strcpy(p1,p2);strcpy(p2,p);
}
==============================================================
【程序80】
題目:海灘上有一堆桃子,五隻猴子來分。第一隻猴子把這堆桃子憑據分為五份,多了一個,這只
猴子把多的一個扔入海中,拿走了一份。第二隻猴子把剩下的桃子又平均分成五份,又多了
一個,它同樣把多的一個扔入海中,拿走了一份,第三、第四、第五隻猴子都是這樣做的,
問海灘上原來最少有多少個桃子?
1.程序分析:
2.程序源代碼:
main()
{int i,m,j,k,count;
for(i=4;i<10000;i+=4)
{ count=0;
m=i;
for(k=0;k<5;k++)
{
j=i/4*5+1;
i=j;
if(j%4==0)
count++;
else
break;
}
i=m;
if(count==4)
{printf("%d\n",count);
break;}
}
}
【程序81】
題目:809*??=800*??+9*??+1 其中??代表的兩位數,8*??的結果為兩位數,9*??的結果為3位數。求??代表的兩位數,及809*??後的結果。
1.程序分析:
2.程序源代碼:
output(long b,long i)
{ printf("\n%ld/%ld=809*%ld+%ld",b,i,i,b%i);
}
main()
{long int a,b,i;
a=809;
for(i=10;i<100;i++)
{b=i*a+1;
if(b>=1000&&b<=10000&&8*i<100&&9*i>=100)
output(b,i); }
}
==============================================================
【程序82】
題目:八進制轉換為十進制
1.程序分析:
2.程序源代碼:
main()
{ char *p,s[6];int n;
p=s;
gets(p);
n=0;
while(*(p)!='\0')
{n=n*8+*p-'0';
p++;}
printf("%d",n);
}
==============================================================
【程序83】
題目:求0—7所能組成的奇數個數。
1.程序分析:
2.程序源代碼:
main()
{
long sum=4,s=4;
int j;
for(j=2;j<=8;j++)/*j is place of number*/
{ printf("\n%ld",sum);
if(j<=2)
s*=7;
else
s*=8;
sum+=s;}
printf("\nsum=%ld",sum);
}
==============================================================
【程序84】
題目:一個偶數總能表示為兩個素數之和。
1.程序分析:
2.程序源代碼:
#include "stdio.h"
#include "math.h"
main()
{ int a,b,c,d;
scanf("%d",&a);
for(b=3;b<=a/2;b+=2)
{ for(c=2;c<=sqrt(b);c++)
if(b%c==0) break;
if(c>sqrt(b))
d=a-b;
else
break;
for(c=2;c<=sqrt(d);c++)
if(d%c==0) break;
if(c>sqrt(d))
printf("%d=%d+%d\n",a,b,d);
}
}
==============================================================
【程序85】
題目:判斷一個素數能被幾個9整除
1.程序分析:
2.程序源代碼:
main()
{ long int m9=9,sum=9;
int zi,n1=1,c9=1;
scanf("%d",&zi);
while(n1!=0)
{ if(!(sum%zi))
n1=0;
else
{m9=m9*10;
sum=sum+m9;
c9++;
}
}
printf("%ld,can be divided by %d \"9\"",sum,c9);
}
==============================================================
【程序86】
題目:兩個字元串連接程序
1.程序分析:
2.程序源代碼:
#include "stdio.h"
main()
{char a[]="acegikm";
char b[]="bdfhjlnpq";
char c[80],*p;
int i=0,j=0,k=0;
while(a[i]!='\0'&&b[j]!='\0')
{if (a[i] { c[k]=a[i];i++;}
else
c[k]=b[j++];
k++;
}
c[k]='\0';
if(a[i]=='\0')
p=b+j;
else
p=a+i;
strcat(c,p);
puts(c);
}
==============================================================
【程序87】
題目:回答結果(結構體變數傳遞)
1.程序分析:
2.程序源代碼:
#include "stdio.h"
struct student
{ int x;
char c;
} a;
main()
{a.x=3;
a.c='a';
f(a);
printf("%d,%c",a.x,a.c);
}
f(struct student b)
{
b.x=20;
b.c='y';
}
==============================================================
【程序88】
題目:讀取7個數(1—50)的整數值,每讀取一個值,程序列印出該值個數的*。
1.程序分析:
2.程序源代碼:
main()
{int i,a,n=1;
while(n<=7)
{ do {
scanf("%d",&a);
}while(a<1||a>50);
for(i=1;i<=a;i++)
printf("*");
printf("\n");
n++;}
getch();
}
==============================================================
【程序89】
題目:某個公司採用公用電話傳遞數據,數據是四位的整數,在傳遞過程中是加密的,加密規則如下:
每位數字都加上5,然後用和除以10的余數代替該數字,再將第一位和第四位交換,第二位和第三位交換。
1.程序分析:
2.程序源代碼:
main()
{int a,i,aa[4],t;
scanf("%d",&a);
aa[0]=a;
aa[1]=a0/10;
aa[2]=a00/100;
aa[3]=a/1000;
for(i=0;i<=3;i++)
{aa[i]+=5;
aa[i]%=10;
}
for(i=0;i<=3/2;i++)
{t=aa[i];
aa[i]=aa[3-i];
aa[3-i]=t;
}
for(i=3;i>=0;i--)
printf("%d",aa[i]);
}
==============================================================
【程序90】
題目:專升本一題,讀結果。
1.程序分析:
2.程序源代碼:
#include "stdio.h"
#define M 5
main()
{int a[M]={1,2,3,4,5};
int i,j,t;
i=0;j=M-1;
while(i {t=*(a+i);
*(a+i)=*(a+j);
*(a+j)=t;
i++;j--;
}
for(i=0;i printf("%d",*(a+i));
}
【程序91】
題目:時間函數舉例1
1.程序分析:
2.程序源代碼:
#include "stdio.h"
#include "time.h"
void main()
{ time_t lt; /*define a longint time varible*/
lt=time(NULL);/*system time and date*/
printf(ctime(<)); /*english format output*/
printf(asctime(localtime(<)));/*tranfer to tm*/
printf(asctime(gmtime(<))); /*tranfer to Greenwich time*/
}
==============================================================
【程序92】
題目:時間函數舉例2
1.程序分析:
2.程序源代碼:
/*calculate time*/
#include "time.h"
#include "stdio.h"
main()
{ time_t start,end;
int i;
start=time(NULL);
for(i=0;i<3000;i++)
{ printf("\1\1\1\1\1\1\1\1\1\1\n");}
end=time(NULL);
printf("\1: The different is %6.3f\n",difftime(end,start));
}
==============================================================
【程序93】
題目:時間函數舉例3
1.程序分析:
2.程序源代碼:
/*calculate time*/
#include "time.h"
#include "stdio.h"
main()
{ clock_t start,end;
int i;
double var;
start=clock();
for(i=0;i<10000;i++)
{ printf("\1\1\1\1\1\1\1\1\1\1\n");}
end=clock();
printf("\1: The different is %6.3f\n",(double)(end-start));
}
==============================================================
【程序94】
題目:時間函數舉例4,一個猜數游戲,判斷一個人反應快慢。(版主初學時編的)
1.程序分析:
2.程序源代碼:
#include "time.h"
#include "stdlib.h"
#include "stdio.h"
main()
{char c;
clock_t start,end;
time_t a,b;
double var;
int i,guess;
srand(time(NULL));
printf("do you want to play it.('y' or 'n') \n");
loop:
while((c=getchar())=='y')
{
i=rand()0;
printf("\nplease input number you guess:\n");
start=clock();
a=time(NULL);
scanf("%d",&guess);
while(guess!=i)
{if(guess>i)
{printf("please input a little smaller.\n");
scanf("%d",&guess);}
else
{printf("please input a little bigger.\n");
scanf("%d",&guess);}
}
end=clock();
b=time(NULL);
printf("\1: It took you %6.3f seconds\n",var=(double)(end-start)/18.2);
printf("\1: it took you %6.3f seconds\n\n",difftime(b,a));
if(var<15)
printf("\1\1 You are very clever! \1\1\n\n");
else if(var<25)
printf("\1\1 you are normal! \1\1\n\n");
else
printf("\1\1 you are stupid! \1\1\n\n");
printf("\1\1 Congralations \1\1\n\n");
printf("The number you guess is %d",i);
}
printf("\ndo you want to try it again?(\"yy\".or.\"n\")\n");
if((c=getch())=='y')
goto loop;
}
==============================================================
Ⅳ C語言練習題----求答案解
我回答了
二、單項選擇題(每小題2分,共40分)
1、表達式2,4,6,8的值為(D )
A.2 B.4 C.6 D.8
2、設有int i;則表達式(i=1,i=10)?i++||++i:++i的值為 (A ) A.1 B.2 C.3 D.10
3、設有int a[ ]={10,11,12},*p=&a[0];則執行完*p++;*p+=1;後a[0],a[1],a[2]的值依次是 ( B) A.10,11,12 B.11,12,12 C.10,12,12 D.11,11,12
4、在C語言程序中,下面哪一個是正確的? (B )
A 函數的定義可以嵌套,但函數的調用不可以嵌套。
B 函數的定義不可以嵌套,但函數的調用可以嵌套。
C 函數的定義可以嵌套,函數的調用也可以嵌套。
D 函數的定義和函數的調用都不可以嵌套。
5、設有說明int s[2]={0,1},*p=s; 則下列錯誤的C語句是 (A ) A.s+=1; B.p+=1; C.*p++; D.(*P)++;
6、若有以下說明和語句,則輸出結果是 (C)
char str[]=」\」d:\\file.dat\」」;
printf(「%s」,str);
A 字元串中有非法字元 B \」d:\\file.dat\」
C 「d:\file.dat」 D 「d:\\file.dat」
7、程序要正確的運行,必須要有 (C )
A printf 函數 B 自定義函數 C main函數 D 不需要函數
8、已知整型變數a=6,字元型變數ch=』A』,(大寫字母A的ASCII碼為65),則表達式 ch+a的值是 (B)
A 69 B 71 C 4 D 出錯
9、下面程序運行後,屏幕上顯示 (D )
void main()
{
int a=4;float b=9.5;
printf(「a=%d,b=%6.4f」,a,b);
}
A a=%d,b=%f\n B a=%d,b=%f C a=4,b= 9.50 D a=4,b=9.5000
10、若i=2,則語句printf(「%d,%d」,i, ++i);的輸出結果是 (C)
A 2,2 B 3,3 C 2,3 D 3,2
11、int a=2,b=8;則在表達式a<b&&b=20後a,b的值分別為:(C )
A 2,8 B 2,10 C 2,20 D 2,6
12、若x=3,則語句:while(x){x--;continue;}的循環次數為 (D )
A 0 B 1 C 2 D 3
13、如果要把常量300存入變數a中,a不可以定義成哪個類型?( B)
A int B char C long D float
14、有輸入語句scanf(「a:%d,b:%d」,&a,&b);輸入數據時應怎樣輸入。(D )
A 4 5 B 4,5 C a=4,b=5 D a:4,b:5
15、設a為整形變數,不能正確表達數學關系:10<a<15 的C語言表達式是(A )
A) 10<a<15 B) a==11||a==12||a==13||a==14
C) a>10&&a<15 D) !(a<=10)&&!(a>=15)
16、下列變數中,哪個屬於構造類型的變數。(D )
A 整型變數 B 實型變數 C 字元型變數 D 結構體類型變數
17、下面的命令中哪一個不屬於預處理命令。(B )
A #define max 20 B #include <stdio.h>
C #ifdef MM D typedef a int;
18、C程序的結構有哪些類。(多選)( ABD)
A 選擇結構 B 循環結構 C 程序結構 D 順序結構
19、循環結構有哪些類。(多選) ( ACD)
A for結構 B if結構 C while結構 D do…while結構
20、若x=4,y=2,a=3,則表達式x=(y==a)執行完後,x的值是 (A )
A 0 B 1 C 3 D 4
Ⅵ 誰有大一C語言考試題快考試了,跪求題庫··
單項選擇題(每小題2分,共50分)
1、一個C程序的執行是從___A__。
A、本程序的main函數開始,到main函數結束
B、本程序的main函數開始,到本程序文件的最後一個函數結束
C、本程序文件的第一個函數開始,到本程序文件的最後一個函數結束
D、本程序文件的第一個函數開始,到本程序main函數結束
2、C語言程序的基本單位是___C___。
A、程序行 B、語句
C、函數 D、字元
3、請選出可用作C語言用戶標識符的一組標識符___B___。
A、void B、a3_b3 C、For D、2a
define _123 -abc DO
WORD IF ase sizeof
主要特點
C語言是一種結構化語言,它有著清晰的層次,可按照模塊的方式對程序進行編寫,十分有利於程序的調試,且c語言的處理和表現能力都非常的強大,依靠非常全面的運算符和多樣的數據類型,可以輕易完成各種數據結構的構建,通過指針類型更可對內存直接定址以及對硬體進行直接操作,因此既能夠用於開發系統程序,也可用於開發應用軟體。
以上內容參考:網路-c語言
Ⅶ 求C語言上機題庫 2010年的
2: 第2題 請編寫函數fun,它的功能是:求出1到100之內能北7或者11整除,但不能同時北7和11整除的所有證書,並將他們放在a所指的數組中,通過n返回這些數的個數。
答案:
void fun(int *a, int *n)
{
int i,j=0;
for(i=2;i<1000;i++)
if ((i%7==0 || i%11==0) && i%77!=0)
a[j++]=i;
*n=j;
}
9: 第9題 編寫一個函數fun,它的功能是:根據以下公式求p的值,結果由函數值帶回。M與n為兩個正整數,且要求m>n。 p=m!/n!(m-n)!
答案:
float fun(int m, int n)
{
float p,t=1.0;
int I;
for (i=1;i<=m;i++)
t=t*I;
p=t;
for(t=1.0,i=1;i<=n;i++)
t=t*I;
p=p/t;
for(t=1.0,i=1;i<=m-n;i++)
t=t*I;
p=p/t;
return p;
}
10: 第10題 編寫函數fun,它的功能是:利用以下的簡單迭代方法求方程cos(x)-x=0的一個實根。
迭代步驟如下:(1)取x1初值為0.0; (2)x0=x1,把x1的值賦各x0;
(3)x1=cos(x0),求出一個新的x1;
(4)若x0-x1的絕對值小於0.000001,則執行步驟(5),否則執行步驟(2);
(5)所求x1就是方程cos(x)-x=0的一個實根,作為函數值返回。
程序將輸出root=0.739085。
答案:
float fun()
{
float x1=0.0,x0;
do
{
x0=x1;
x1=cos(x0);
}
while(fabs(x0-x1)>1e-6);
return x1;
}
19: 第19題 編寫函數fun,該函數的功能是:從字元中刪除指定的字元,同一字母的大、小寫按不同字元處理。
答案:
void fun(char s[],int c)
{
int i=0;
char *p;
p=s;
while(*p)
{
if(*p!=c)
{
s[i]=*p;
i++;
}
p++;
}
s[i]='\0';
}
23: 第23題 請編寫函數fun,該函數的功能是:判斷字元串是否為迴文?若是則函數返回1,主函數中輸出yes,否則返回0,主函數中輸出no。迴文是指順讀和倒讀都是一樣的字元串。
答案:
int fun(char *str)
{
int I,n=0;fg=1;
char *p=str;
while (*p)
{
n++;
p++;
}
for(i=0;i<n/2;i++)
if (str[i]==str[n-1-i]);
else
{
fg=0;
break;
}
return fg;
}
24: 第24題 請編寫一個函數fun,它的功能是:將一個字元串轉換為一個整數(不得調用c語言提供的將字元串轉換為整數的函數)。
答案:
long fun (char *p)
{
long s=0,t;
int i=0,j,n=strlen(p),k,s1;
if(p[0]=='-')
i++;
for(j=I;j<=n-1;j++)
{
t=p[j]-'0';
s1=10;
for(k=j;k<n-1;k++)
t*=s1;
s+=t;
}
if(p[0]=='-')
return –s;
else
return s;
}
25: 第25題 請編寫一個函數fun,它的功能是:比較兩個字元串的長度,(不得調用c語言提供的求字元串長度的函數),函數返回較長的字元串。若兩個字元串長度相同,則返回第一個字元串。
答案:
char *fun(char *s,char *t)
{
char *p,*t1=t,*s1=s;
int n=0;m=0;
while (*s1)
{
n++;
s1++;
}
while(*t1)
{
m++;
t1++;
}
if(n>=m)
p=s;
else
p=t;
return p;
}
27: 第27題 請編寫一個函數fun,它的功能是:求除1到m之內(含m)能北7或11整除的所有整數放在數組a中,通過n返回這些數的個數。
答案:
void fun(int m, int *a, int *n)
{
int I,j=0; *n=0;
for(i=1;i<=m;i++)
if (i%7==0 || i%11 ==0)
{
a[j]=I;
j++;
}
*n=j;
}
29: 第29題 請編寫一個函數fun,它的功能是:將ss所指字元串中所有下標為奇數位置上的字母轉換為大寫(若該位置上不是字母,則不轉換)。
答案:
void fun(char *ss)
{
int I,n;
n=strlen(ss);
for(i=1;i<n;i+=2)
if(ss[i]>='a'&& ss[i]<='z')
ss[i]=ss[i]-32;
}
31: 第31題 請編寫函數fun,其功能是:將s所指字元串中除了下標為偶數、同時ascii值也為偶數的字元外,其餘的全都刪除;串中剩餘字元所形成的一個新串放在t所指的一個數組中。
答案:
void fun(char *s,char t[])
{
int I,j=0,n;
n=strlen(s);
for(i=0;I,n;i++)
if(i%2==0&&s[i]%2==0)
{
t[j]=s[i];
j++;
}
t[j]='\0';
}
32: 第32題 請編寫函數fun,其功能是:將s所指字元串中除了下標為奇數、同時ascii值也為奇數的字元之外,其餘的所有字元都刪除,串中剩餘字元所形成的一個新串放在t所指的一個數組中。
答案:
void fun(char *s,char t[])
{
int I,j=0,n;
n=strlen(s);
for(i=0;I,n;i++)
if(i%2!=0&&s[i]%2!=0)
{
t[j]=s[i];
j++;
}
t[j]='\0';
}
38: 第38題 請編寫函數fun,它的功能是:求出ss所指字元串中指定字元的個數,並返回此值。
答案:
int fun(char *ss, char c)
{
int n=0;
while (*ss)
{
if(*ss==c)
n++;
ss++;
}
return n;
}
48: 第48題 請編寫函數fun,其功能是:將兩個兩位數的正整數a,b合並成一個整數放在c中。合並的方式是:將a數的十位和個位依次放在c數的千位和十位上,b數的十位和個位數依次放在c數的百位和個位上。
答案:
void fun(int a,int b,long *c)
{*c=(a/10)*1000+(b/10)*100+(a%10)*10+b%10;}
49: 第49題 請編寫函數fun,其功能是:將s所指字元串中下標位偶數同時ascii值為奇數的字元刪除,s中剩餘的字元形成的新串放在t所指的數組中。
答案:
void fun(char *s,char t[])
{int i,j=0,n=strlen(s);
for(i=0;i<n;i++)
if(i%2==0&s%2!=0)
else
{f[j]=s;
j++;}
t[j]='\0';}
51: 第51題 請編寫函數fun,其功能是:將所有大於1小於整數m的非素數存入xx所指的數組中,非素數的個數通過k傳回。
答案:
void fun(int m,int *k,int xx[])
{int i,j;
int t=0;
for(i=2;i<m;i++)
{j=2;
while(j,<i)
{if(i%j==0)
{xx[t]=i;
t++;
break;}
j++;}
*k=t;}}
52: 第52題 編寫一個函數fun,它的功能是:實現兩個字元串的連接(不使用庫函數strcat),即把p2所指的字元串連接到p1所指的字元串後。
答案:
void fun(char p1[],char p2[])
{int i=0,n=0;
char *p=p1,*q=p2;
while (*p)
{p++;
n++;}
i=n;
while(*p)
{p1=*q;
q++;
i++;}
p1='\0';}
53: 第53題 請編寫函數fun,該函數的功能是:實現b=a+a,即把矩陣a加上a的轉置,存放在矩陣b中。計算結果在main函數中輸出。
答案:
void fun(int a[3][3],int b[3][3])
{int i,j,at[3][3];
for(i=0;i<=2;i++)
for(j=0;j<=2;j++)
at[j]=a[j];
for(i=0;i<3;i++)
for(j=0;j<3;j++)
b[j]=a[j]+at[j];}
58: 第58題 編寫函數藏服那,它的功能是:求n以內(不包括n)同時能被3與7整除的所有自然數之和的平方根s,並作為函數值返回。
答案:
double fun(int n)
{double s=0.0;
int i;
for(i=1;i<n;i++)
if(i%3==0&i%7==0)
s=s+i;
s=sqrt(s);
return s;}
59: 第59題 請別寫函數fun,該函數的功能是:將放在字元串數組中的m個字元串(每串的長度不超過n),按順序合並組成一個新的字元串。
答案:
void fun(char a[m][n],char *b)
{int i,j,k=0;
for(i=0;i<m;i++)
{for(j=0;j<n;j++)
if(*(*(a+i)+j))
{b[k]=*(*(a+i)+j)
k++;}
else
break;
b[k]='\0';}}
61: 第61題 第請編寫函數fun,該函數的功能使:統計各年齡段的人數。N個年齡通過調用隨機函數獲得,並放在主函數的age數組中;要求函數把0至9歲年齡段的人數放在d[0]中,把10至19歲年齡段的人數放在d[1]中,把20至29歲的人數放在d[2]中,其餘以此類推,把100歲(含100以上年齡的人數都放在d[10]中。結果在主函數中輸出。
答案:
void fun(int *a,int *b)
{int i,j;
for(j=0;i<m;j++)
b[j]=0;
for(i=0;i<n;i++)
if(a>=0&a<=9)
b[0]+=1;
else if(a>=10&a<=19)
b[1]+=1;
else if(a>=20&a<=29)
b[2]+=1;
else if(a>=30&a<=39)
b[3]+=1;
else if(a>=40&a<=49)
b[4]+=1;
else if(a>=50&a<=59)
b[5]+=1;
else if(a>=60&a<=69)
b[6]+=1;
else if(a>=70&a<=79)
b[7]+=1;
else if(a>=80&a<=89)
b[8]+=1;
else if(a>=90&a<=99)
b[9]+=1;
else
b[10]+=1;}
84: 第84題 請編寫函數fun,其功能是:將兩個兩位數的正整數a b合並形成一個整數放在c中,合並的方式是:將a數的十位和個位數依次放在c的個位和百位上,b數的十位和個位數依次放在c數的千位和十位上。
答案:
void fun(int a,int b,long *c)
{c=(b/10)*1000+(a%10)*100+(b%10)*10+a/10;}
87: 第87題 請編寫函數fun,其功能是:將兩個兩位數的正整數a b合並形成一個整數放在c 中。合並的方式是:將a數的十位和個位數依次放在c數的千位和十位上,b數的十位和個位數依次放在c數的個位和百位上。
答案:
void fun(int a,int b,long *c)
{*c=(a/10)*1000+(a%10)*10+(b%10)*100+b/10;}
91: 第91題 請編寫函數fun,其功能是:將兩個兩位數的正整數a b合並形成一個整數放在c中。合並的方式是:將a數的十位和個位數依次放在c的十位和千位上,b數的十位和個位數依次放在c數的個位和百位上。
答案:
void fun(int a, int b, long *c)
{
*c=(a%10)*1000+(b%10)*100+(a/10)*10+b/10;
}
81: 第81題 請編寫函數fun,其功能使:將兩個兩位正整數a b合並形成一個整數放在c中。合並的方式使:將a數的十位和個位數依次放在c數的百位和個位上,b數的十位和個位數依次放在c數的千位和十位上。
答案:
void fun(int a,int b,long *c)
{*c=(b/10)*1000+(a/10)*100+(b%10)*10+a%10;}
78: 第78題 請編寫函數fun,其功能是:將s所指字元串中ascii值為偶數的字元刪除,串中剩餘字元形成一個新串放在t所指的數組中。
答案:
void fun(char *s,char t[])
{int i,j=0,n=strlen(s);
for(i=0;i<n;i++)
if (s%2!=0)
{t[j]=s;
j++;}
t[j]='\0';}
77: 第77題 請編寫一個函數fun,其功能是:將兩個兩位數的正整數ab合並形成一個整數放在c中。合並方式是:將a數的十位和個位數依次放在c數的個位和百位上,b數的十位和個位數依次放在c數的十位和千位上。
答案:
void fun(int a,int b,long *c)
{*c=(b%10)*1000+(a%10)*100+(b/10)*10+a/10;}
71: 第71題 請編寫函數fun,其功能時:將兩個兩位數的正整數a、b合並形成一個整數放在c中,合並的方式是:將a數的十位和個位數依次放在c數的十位和千位上,b的十位和個位整數依次放在c數的百位和個位上。
答案:
void fun(int a,int b,long *c)
{*c=(a%10)*1000+(b/10)*100+(a/10)*10+b%10;}
72: 第72題 請編寫函數fun,其功能是:將s所指字元串中下標為偶數的字元刪除,串中剩餘字元形成新串放在t所指數組中。
答案:
void fun(char *s,char t[])
{int i,j=0,n=strlen(s);
for(i=0;i<n;i++)
if(i%2!=0)
{t[j]=s;
j++;}
t[j]='\0';}
65: 第65題 請編寫函數fun,其功能是:將兩位數的正整數a、b合並成一個整數放在c中。合並的方式是:將a數的十位和個位數依次放在c數的百位和個位上,b數的十位和個位數依次放在c數的十位和千位上。
答案:
void fun(int a,int b,long *c)
{*c=(b%10)*1000+(a/10)*100+(b/10)*10+a%10;}
40: 第40題 請編寫函數fun,該函數的功能是移動字元串中內容,移動的規則如下:把第1到第m個字元,平移到字元串的最後,把第m+1到最後的字元移到字元串的前部。
答案:
void fun(char *w,int m)
{
char b[N];
int I,j=0;
for(i=0;i<m;i++)
{
b[j]=w[i];
j++;
}
for (i=0;i<strlen(w)-m;i++)
w[i]=w[i+m];
for(j=0;j<m;j++)
{
w[i]=b[j];
i++;
}
w[i]='\0';
64: 第64題 請編寫函數fun,其功能是:將s所指字元串中ascii值為奇數的字元刪除,串中剩餘字元形成一個新串放在t所指的數組中。
答案:
void fun(char *s,char t[])
{int i,j=0,n;
n=strlen(s);
for(i=0;i<n;i++)
if(s%2==0)
{t[j]=s;
j++;}
t[j]='\0';}
62: 第62題 請編寫函數fun,該函數的功能是:統一一含字元串中單詞的個數,作為函數值返回。一行字元串在主函數中輸入,規定所有單詞由小寫字母組成,單詞之間由若干個空格格開,一行的開始沒有空格。
答案:
int fun (char *s)
{int i,n=0;
for(i=0;i<strlen(s);i++)
{if(s='a'&s<='z'&s[i+1]==''
‖s[i+1]=='\0')
n++;}
return n;}
這是原題題庫