给同学做的作业

 1 9.2
 2 #include<iostream>
 3 using namespace std;
 4 int fun(int* a)
 5 {
 6 
 7     for(int i=0;i<8;i++)
 8         for(int j=0;j<8-i;j++)
 9         {
10                 int temp=0;
11             if(a[j]<a[j+1])
12             {
13             
14                 temp=a[j];
15                 a[j]=a[j+1];
16                 a[j+1]=temp;
17             }
18         }
19         return a[1];
20 }
21 int main()
22 {
23     int a[]={45,58,33,24,40,20,30,28,31};
24     cout<<fun(a)<<endl;
25 }

 

 1 7.4
 2 #include<iostream>
 3 using namespace std;
 4 int main()
 5 {
 6     int a[]={5,10,15,27,46},b[]={50,45,42,29,15,8,5,2},*c=new int[13];
 7     for(int i=0;i<5;i++)
 8         c[i]=a[i];
 9     for(int j=0;j<8;j++)
10         c[j+5]=b[j];
11     for(int i=0;i<12;i++)
12         for(int j=0;j<12-i;j++)
13         {
14             int temp=0;
15             if(c[j]<c[j+1])
16             {
17                 temp=c[j];
18                 c[j]=c[j+1];
19                 c[j+1]=temp;
20             }
21         }
22         for(int k=0;k<13;k++)
23             cout<<c[k]<<" ";
24 }

 

 1 #include <iostream>
 2 #include <iomanip>
 3 using namespace std;
 4 
 5 int main()
 6 {
 7     double a;
 8     cin>>a;
 9     cout<<setiosflags(ios::fixed)<<setprecision(2)<<a<<endl;//fixed为实数输出,若改为scientifitic则是科学技术法输出;setprecision(2)此处表示设置精度为2
10     return 0;
11 }

 

 1 //7.2
 2 #include <iostream>
 3 #include<iomanip>
 4 #include <cmath>
 5 using namespace std;
 6 double setp(double x)
 7 {
 8     cout<<setiosflags(ios::fixed)<<setprecision(2)<<x<<endl;
 9     return x;
10 }
11 void fun(int arr[],double x,int y)
12 {
13     double m=(y+2)*pow(x,y);
14     arr[0]=(int)m;
15     arr[1]=double(m-arr[0]);
16 }
17 void main()
18 {
19    int y;
20    double x;
21    int arra[2];
22    printf("Please enter x(1<x<2),y(0<y<=6):\n");
23    scanf("%lf%d",&x,&y);
24    if((x>1.0 &&x<2.0)&&(y>0 && y<=6))
25    {
26      fun(arra,x,y);
27      printf("\npart1=%d,part2=%f\n",arra[0],arra[1]);
28    }
29    else
30      printf("x or y is out of range!");
31    getchar();
32 }

 

//--------------------------1
//&可以理解为输入的数据实际上都是要放在计算机内存中的,内存是用地址来标识的
#include<stdio.h>
void main()
{
    int a;//%d
    float y;//%f
    double x;//%lf
    printf("Enter:a,y,x");
    scanf("%d%f%lf",&a,&y,&x);
    printf("a=%d y=%f x=%f\n",a,y,x);
}
//--------------------------2
//%d输出整数,%ld输出长整数,%x输出无符号的十六进制整数,%c输出单字符,%f输出实数,%lf输出双精度数
//%e以指数形式输出实数,相反也可以同样输入
#include<iostream>
void main()
{
    char c;
    c='e'-32;
    printf("%c\n",c);
}
//--------------------------------3
//使用getchar()函数来完成单个字符的输入,用putchar()函数来完成单个字符的输出
#include<stdio.h>
void main()
{
    char c;
    printf("Enter char:c\n");
    scanf("%c",&c);
    c=c-32;
    printf("%c\n",c);
}
//-------------------4
//scanf("%c",&c);替换为c=getchar();
//printf("%c",&c);替换为putchar(c);
#include<iostream>
void main()
{
    char c;
    printf("Enter char:c\n");
    c=getchar();
    c=c-32;
    putchar(c);
    printf("\n");
}
//---------------------5
//不能缺少#include<math.h>语句,因为sin函数在该头函数中定义,
//printf("%.2f\n",y);中的格式描述符,说明保留小数点后2位
//如果用%f,则保留小数点后6位
#include<stdio.h>
#include<math.h>
void main()
{
    float y;
    y=sin(30*3.14/180);
    printf("%.2f\n",y);
}
/*#include<stdio.h>//我终于知道"%.2f\n"的妙用了
#include<math.h>
void main()
{
    float y;
    y=3;
    printf("%.2f\n",y);
}*/
//--------------------6-------------函数类型--------------参数类型-
//sin(x) 返回x的正弦值; -----------double----------------double,x为弧度
//cos(x) 返回x的余弦值; -----------double----------------double,x为弧度
//tan(x) 返回x的正切值; -----------double----------------double,x为弧度
//exp(x) 返回指数函数e的x的次方值---double----------------double
//log(x) 返回log(x)的值;-----------double----------------double
//log10(x) 返回log10(x)的值; ------double----------------double
//sqrt(x) 返回根号下x的值; --------double----------------double
//abs(i) 返回i的绝对值--------------int-------------------int
//labs(n) 返回n的绝对值-------------long int--------------long int
//fabs(x) 返回x的绝对值-------------double----------------double
//pow(x,y) 返回指数函数x的y次方值---double----------------double
#include<stdio.h>
void main()
{
    float t;
    float y;
    printf("Enter:t\n");
    scanf("%f",&t);
    if(t<=2)
    {
        y=t*1.5;
    }
    else
    {
        y=(t-2)*1.8+2*1.5;
    }
    printf("y=%f\n",y);
}
//------------------------------------7
#include<stdio.h>
void main()
{
    int a,b,c,max;
    printf("Enter integers: a,b,c");
    scanf("%d%d%d",&a,&b,&c);
    max=a;
    if(max<b)
    {max=b;}
    if(max<c)
    {max=c;}
    printf("max=%d\n",max);
}
//----------------------------8
#include<stdio.h>
void main()
{
    int x;
    float y;
    printf("Enter integer:x");
    scanf("%d",&x);
    if(x<10)
    {y=x*2.0;}
    else
    {y=x*2.5;}
    printf("y=%f\n",y);
}
//--------------------------9
#include<stdio.h>
void main()
{
    int x;
    printf("输入成绩:x\n");
    scanf("%d",&x);
    if(x<60)
        printf("成绩不及格\n");
    else
        printf("成绩及格\n");
}
//-------------------------------10
#include<stdio.h>
void main()
{
    int a,b,c;
    printf("输入三个正整数 a,b,c\n");
    scanf("%d%d%d",&a,&b,&c);
    if(a>b)
    {
        if(a>c)
            if(b>c)
                printf("%d%d%d\n",a,b,c);
            else
                printf("%d%d%d\n",a,c,b);
        else
            printf("%d%d%d\n",c,a,b);
    }
    else
    {
        if(b>c)
            if(a>c)
                printf("%d%d%d\n",b,a,c);
            else
                printf("%d%d%d\n",b,c,a);
        else
            printf("%d%d%d\n",c,b,a);
    }
}
//--------------------------11

 

posted @ 2013-06-06 20:04  herizai  阅读(246)  评论(0编辑  收藏  举报