更多"对数组中的元素值进行排序。请填空。 # include<stdio."的相关试题:
[填空题]下面程序的功能是输出数组s中最大元素的下标,请填空。
#include <stdio.h>
main( )
int k, p,s[]=1, -9,7,2, -10,3;
for(p =0,k =p; p<6; p++)
if(s[p]>s[k])
printf("%d//n", k);
[简答题]从键盘上输入20个元素的值存入一维数组a中,然后将下标为(1、3、5、7、9……)的元素值赋值给数组b,输出数组b的内容。
[简答题]写出模板函数实现数值型数组元素值按从小到大排序的程序。
#include<iostream>
using namespace std;
______
void sort(T b[],int n)
T temp;
int i,j;
T*a=new T[n];
for(i=0;i<n;i++)
a[i]=b[i];
for(i=0;i<n-1;i++)
for(j=i+1;j<n;j++)
if(a[i]>a[j])
temp=a[i];
a[i]=a[j];
a[j]=temp;
for(i=0;i<n;i++)
cout<<a[i]<<" ";
cout<<endl;
delete a;
void main( )
int i,n=6;
int a[]=5,1,9,10,3,8;
sort______;
for(i=0;i<n;i++)
cout<<a[i]<<" ";
cout<<endl;
[填空题]
以下程序用以删除字符串所有的空格,请填空。
#include
main( )
{ char s[100]={"Our teacher teach C language!"};int i,j;
for(i=j=0;s[i]!=’/0’;i++)
if(s[i]!= ’ ’) {s[j]=s[i];j++;}
s[j]= ()
printf(“%s/n”,s);
}
[填空题]以下程序用来判断指定文件是否能正常打开,请填空。
#include <stdio.h>
main( )
FILE *fp;
if(((fp=fbpen("test.txt","r"))==______))
printf("未能打开文件!/n");
else
printf("文件打开成功!/n");
[填空题]以下程序的功能是计算字符串的长度。请填空。
#include<stdio.h>
main( )
{char str[100],*sp=str;
int nlen=0;
scanf("%s",str);
for(;*sp!=’/0’;sp++)______;
printf("%d",nlen);
}
[填空题]以下程序用来统计文件中字符个数。请填空。
#include "stdio. h"
main( )
FILE *fp;long num=OL;
if((fp=fopen("fname.dat","r")==NULL)
Pirntf("Open error/n"); exit(0);
while( 【16】 )
fgetc(fp);num++;
printf("num=%1d/n",num-1);
fclose(fp);
[填空题]下面的程序用来统计文件中字符的个数。请填空。
# include<stdio.h>
main( )
FILE *fP;
long num=0;
if( (fp=fopen("fname.dat","r"))==NULL)
printf("Can’t open file! /n");sxit(0);
while 【20】
fgetc(fp);num++;
printr("num=%d/n",num);
fclose (fp);
[填空题]下列程序用来判断指定文件是否能正常打开,请填空。
#include<stdio.h>
main( )
(FILE *fp;
if(((fp=fopen("test.txt","r")!=______))
printf("文件打开成功!/n");
else
printf("未能打开文件!/n");
[填空题]下列程序的输出结果是16.00,请填空。
#include <stdio.h>
main( )
int a=9, b=2;
float x= 【12】 ,y=1.1,z;
z=a/2+b*x/y+1/2;
printf("%5.2f/n",z);
[填空题]以下程序用来统计文件中字符的个数。请填空。
#include“stadio.h”
main( )
FILE *fp;long num=0L;
if((fp=fopen(“fname.dat”,“r”))==NULL);
printf(“0pen error/n”);exit(0);
while( 【16】 )
fsetc(fp);num++;
printf(“num=%1d/n”,num-1);
fclose(fp);
[填空题]下面程序的功能是用来统计文件中字符个数。请填空。
#include"stdio.h"
main( )
long count=OL;
FILE*fp= 【16】 ("text.dat","r");
if(fp==0)
printf("Open error/n");
exit(0);
while( 【17】 )
fgetc(fp);
count++;
fclise(fp);
printf("%1d/n",count);
[填空题]以下程序用以删除字符串所有的空格,请填空。
#include <stdio.h>
main( )
char s[100]= "Our teacher teach C language!");int i,j;
for(i=j=0;s[i]!=’/0’;i++)
if(s[i]!=’’)s[j]=s[i];j++;
s[j]=______;
printf("%s/n",s);
[填空题]以下程序用以删除字符串中所有的空格,请填空。
#include <stdio.h>
main( )
char s[100]="our teacher teach c language!”;int i,j;
for(i=j=0;s[i]!=’/0’;i++)
if(s[i]!=’’) s[j]=s[i];j++;
s[j]=______;
printf("%s/n",s);