作业
11.
#include"stdio.h"
void main()
{
int m,n;
int sum,i,j;
printf(“Please enter the range [m,n]:\n”);
scanf("%d%d",&m,&n);
printf("\n");
printf(“the Perfect number is :\n”);
for(i=m;i<=n;i++)
{
sum=0;
for(j=1;j<i;j++)
{
if(i%j0)
sum+=j;
}
if(isum)
printf("%d\t",i);
}
}
12.
#include <stdio.h>
#include <math.h>
int main()
{
int n;
int i,j,k;
int count=0,s;
printf(“请输入一个正整数N:\n”);
scanf("%d",&n);
for(i=2;i+2<=n;i++ )
{
s = 1;
k = sqrt(i);
for(j=2;j<=k;j++ )
{
if(i%j==0)
}
}
13.
#include <stdio.h>
main;
{
int cock,hen,chicken;
for(cock=0;cock<=20;cock++)
for(hen=0;hen<=33;hen++)
{
chicken=100-cock-hen;
if(5cock+3hen+chicken/3.0100)
printf(“cock=%2d,hen=%2d,chicken=%2d\n”,cock,hen,chicken);
}
}
14.
#include"stdio.h"
main()
{
int n;
int i,j,k;
int count=0;
while(scanf("%d",&n))
{
for(i=1;i<=n;++i)
for(j=i+1;j<=n;++j)
for(k=j+1;k<=n;++k)
if(ii+jjkk)
{
printf("[%d,%d,%d], “,i,j,k);
count++;
}
printf(“total number: %d\n”,count);
}
}
15.
#include"stdio.h”
main()
{
int a,i,b,n;
printf(“There are following friendly-numbers pair smaller than 3000:\n”);
{
for(b=0,i=1;i<=a/2;i++);
if(!(a%i))
b+=i;
for(n=0,i=1;i<=b/2;i++) ;
if((b%i))
n+=i;
if(n==a&&a<b)
printf("[%4d,%4d] “,a,b);
}
}
16.
#include"stdio.h”
main()
{
int a,b,c,min;
printf(“please input the a,b and c:\n”);
scanf("%d%d%d",&a,&b,&c);
if(a<b)
{
if(a<c)
min=a;
else
min=c;
}
else
{
if(b<c)
min=b;
else
min=c;
}
printf(“the min is %d\n”,min);
}
17.
#include"stdio.h"
main()
{
float tax,salary;
printf(“please input the salary:\n”);
scanf("%f",&salary);
if(salary>=4500)
tax=0.2(salary-1600);
else if(salary>3500)
tax=0.15*(salary-1600);
else if(salary>2500)
tax=0.10*(salary-1600);
else if(salary>1600)
tax=0.05*(salary-1600);
else
tax=0;
printf(“the tax is :%.2f\n”,tax);
}
18.
这题不会。
#include<stdio.h>
int main()
{
float I=0,money01, money02, money03, money04, money05;
float bonus=0; //奖金
money01 = 100000 * 0.1; //十万元奖金
money02 = money01 + 100000 * 0.075;//二十万元奖金
money03 = money02 + 200000 * 0.05;//四十万元奖金
money04 = money03 + 200000 * 0.03;//六十万元奖金
money05 = money04 + 400000 * 0.01;//一百万元奖金
printf(“请输入本月利润I:”);
scanf("%f", &I);
if (I<=100000)
bonus = I*0.1;
else if (I <= 200000)
bonus = money01 + (I - 100000)*0.075;
else if (I <= 400000)
bonus = money02 + (I - 200000)*0.05;
else if (I <= 600000)
bonus = money03 + (I - 400000)0.03;
else if (I <= 1000000)
bonus = money04 + (I - 600000)0.015;
else
bonus = money05+(I-1000000)0.01;
printf(“本月的奖金为%.2f”,bonus);
}
19.
#include"stdio.h"
#include"math.h"
void main()
{
int a,b,c;
float p,s,l;
printf(“please input a,b,c:\n”);
scanf("%d%d%d",&a,&b,&c);
if(a+b>c&&a+c>b&&b+c>a)
{
l=a+b+c;
p=l/2.0;
s=sqrt(p(p-a)(p-b)(p-c));
printf(“l=%.2f\ns=%.2f\n”,l,s);
}
else
printf(“These sides do not correspond to a valid triangle!!\n”);
}
20.
#include “stdio.h”
main()
{
int arr[7][7];
int i,j;
for(i=0;i<7;i++)
arr[i][0]=1;
for(i=0;i<7;i++)
arr[i][i]=1;
for(i=2;i<7;i++)
for(j=1;j<=i;j++)
arr[i][j]=arr[i-1][j-1]+arr[i-1][j];
printf(“the result is :\n”);
for(i=0;i<7;i++)
{
for(j=0;j<=i;j++)
printf("%5d",arr[i[j]);
printf("\n");
}
21.
#include"stdio.h"
void main()
{
int arr[5][6];
int i,j;
printf(“please input the arr:\n”);
for(i=0;i<5;i++)
for(j=0;j<5;j++)
scanf("%d",&arr[i][j]);
for(i=0;i<5;i++)
arr[i][5]=0;
for(i=0;i<5;i++)
{
for(j=0;j<5;j++)
printf("%5d",arr[i][j]);
printf("\n");
}
for(i=0;i<5;i++)
{
for(j=0;j<5;j++)
arr[i][5]+=arr[i][j];
arr[i][5]=arr[i][5]/5;
}
printf(“the result is :\n”);
for(i=0;i<5;i++)
{
for(j=0;j<6;j++)
printf("%5d",arr[i][j]);
printf("\n");
}