5:在包含10个数的一维整数数组a中查找给定的数据num。 如果找到则返回1,未找到返回 0 .
include <fstream.h>
#include <iostream.h>
int fun(int a[],int num)
{
/**********Program**********/
for(int i=0;i<10;i++)
{
if(a[i]==num)
return 1;
}
return 0;
/********** End **********/
}
void main()
{
int a[10]={54,256,563,754,34,56,345,543,45,65};
int num = 46;
if (fun(a,num)==1)
cout <<" 找到!" <<endl;
else
cout <<" 没有找到!" <<endl;
void wwjt();
wwjt();
}
void wwjt()
{
int a[10]={54,256,563,754,34,56,345,543,45,65};
fstream myfile;
myfile.open(" out.txt" ,ios::out);
myfile<<fun(a,46)<<endl;
myfile<<fun(a,345)<<endl;
myfile.close();
}
8:将数组S中所有小写字母改写成大写字母。
#include <iostream.h>
#include <fstream.h>
#include <string.h>
void fun(char s[])
{
/**********Program**********/
for(int i=0;i<80;i++)
{
if(s[i]>'Z')
s[i]=s[i]-32;
cout<<s[i];
}
/********** End **********/
}
void wwjt(char []);
void main()
{
char s[80] = " abdsaFDSAFdsafASFDSafghHFDHTjte" ;
fun(s);
wwjt(s);
}
void wwjt(char s[])
{
fstream myfile;
myfile.open(" out.dat" ,ios::out);
myfile<<s<<endl;
myfile.close();
}