第一部分:
#include
main()
{
int s,i;
s=0;
for(i=0;5*i+4<=1001;i++)
{
s+=5*i+4;
}
printf("%d\n",s);
}
第二部分:
#include
main()
{
int n,i,j;
printf("Input n:");
scanf("%d",&n);
for(i=n;i>0;i--)
{
for(j=0;j printf("*");
printf("\n");
}
}
第三部分:
#include
main()
{
int n,s,i,t;
printf("Input n:");
scanf("%d",&n);
t=1;
s=0;
for(i=1;i<=n;i++)
{
t*=i;
s+=t;
}
printf("s=%d\n",s);
}
第四部分:
#include
#include
main()
{
int option=0; /*选择用变量,use to record user's press*/
float celsius; /*摄氏温度,she shi wen du*/
float fahrenheit; /*华氏温度,hua shi wen du*/
while(option!=3)
{
printf("1 for Fahrenheit to Celsius;\n");
printf("2 for Celsius to Fahrenheit;\n");
printf("3 to quit.\n");
printf("Please to choose: ");
scanf("%d",&option);
printf("\n");
if(option==1)
{
scanf("%f",&fahrenheit);
celsius=(fahrenheit-32)*5/9;
printf("The Fahrenheit %f in Celsius is %f\n",fahrenheit,celsius);
}
if(option==2)
{
scanf("%f",&celsius);
fahrenheit=(celsius*9/5)+32;
printf("The Celsius %f in Fahrenheit is %f\n",celsius,fahrenheit);
}
printf("Press any key to continue...\n");
getch(); /*pause for screen, press any key to continue*/
clrscr();
}/*end While*/
}/*end main*/
参考下吧
第一部分:
#include
"stdio.h"
int
main()
{
int
sum
=
0,
n
=
1;
while
(5*n+4
<=
1001)
{
sum
+=
5*n+4;
n++;
}
printf("%d\n",
sum);
return
0;
}
第二部分:
#include
"stdio.h"
int
main()
{
int
n;
printf("please
input
the
number
n:
");
while
(scanf("%d",
&n)
&&
n
!=
0)
{
while
(n>0)
{
for
(int
i=1;
i<=n;
i++)
printf("*");
printf("\n");
n--;
}
printf("\n");
printf("please
input
the
number
n:
");
}
return
0;
}
第三部分:
#include
"stdio.h"
int
main()
{
long
s
=
0,
t;
int
n;
printf("please
input
the
number
n:
");
scanf("%d",
&n);
while
(n
>
0)
{
t
=
1;
for
(int
i=1;
i<=n;
i++)
t
*=
i;
s
+=
t;
n--;
}
printf("the
sum
is:
%ld\n",
s);
return
0;
}
第四部分:
#include
#include
void
main()
{
int
option=0;
/*选择用变量,use
to
record
user's
press*/
int
celsius;
/*摄氏温度,she
shi
wen
du*/
int
fahrenheit;
/*华氏温度,hua
shi
wen
du*/
while
(option!=3)
{
printf("1
for
Fahrenheit
to
Celsius;\n");
printf("2
for
Celsius
to
Fahrenheit;\n");
printf("3
to
quit.\n");
printf("Please
to
choose:
");
scanf("%d",&option);
printf("\n");
if
(option
==
1)
{
scanf("%f",&fahrenheit);
celsius=(fahrenheit-32)*5/9;
printf("The
Fahrenheit
%f
in
Celsius
is
%f\n",fahrenheit,celsius);
}
else
if(option
==
2)
{
scanf("%f",&celsius);
fahrenheit=(celsius*9/5)+32;
printf("The
Celsius
%f
in
Fahrenheit
is
%f\n",celsius,fahrenheit);
}
printf("Press
any
key
to
continue...");
getch();
/*pause
for
screen,
press
any
key
to
continue*/
clrscr();
}
}
1.
//---------------------------------------------------------------------------
#include
long int fun(int i)
{
return (5*i+4);
}
int main(void)
{
long int s=0;
int i=0;
while (fun(i)<=1001)
s+=fun(i++);
printf("%ld\n",s);
return 0;
}
//---------------------------------------------------------------------------
2.
//---------------------------------------------------------------------------
#include
int main(void)
{
int i,j,n;
do{
printf("n=");
scanf("%d",&n);
if (n>20||n<=0) {
printf("0
}while (n<=0||n>20);
for (i = 0; i
for (j=1; j<2*(n-i)-1; j++) {
putchar('*');
}
putchar('\n');
}
return 0;
}
//---------------------------------------------------------------------------
3.
//---------------------------------------------------------------------------
#include
#include
long int fun(int n)
{
if (n>1) {
return n*fun(n-1);
}
else return n;
}
int main(void)
{
int i;
double s=0;
scanf("%d",&i);
assert(i>0&&i<=20);
while (i>0)
s+=fun(i--);
printf("%.0lf",s);
return 0;
}
//---------------------------------------------------------------------------
4.
/*Replace this with your Student-Number.*/
/*这个程序是进行温度转换*/
/*This program is to alter in Fahrenheit and Celsius*/
/*Modify this program's error*/
#include
#include
void main()
{
int option=0; /*选择用变量,use to record user's press*/
float celsius; /*摄氏温度,she shi wen du*/
float fahrenheit; /*华氏温度,hua shi wen du*/
while(option!=3){
printf("1 for Fahrenheit to Celsius;\n");
printf("2 for Celsius to Fahrenheit;\n");
printf("3 to quit.\n");
printf("Please to choose: ");
scanf("%d",&option);
printf("\n");
if (option==1) {
scanf("%f",&fahrenheit);
celsius=(fahrenheit-32)*5/9;
printf("The Fahrenheit %f in Celsius is %f\n",fahrenheit,celsius);
}
else if(option==2){
scanf("%f",&celsius);
fahrenheit=(celsius*9/5)+32;
printf("The Celsius %f in Fahrenheit is %f\n",celsius,fahrenheit);
}
printf("Press any key to continue...");
getch(); /*pause for screen, press any key to continue*/
clrscr();
}/*end While*/
}/*end main*/
第一部分:
#include "stdio.h"
int main()
{
int sum = 0, n = 1;
while (5*n+4 <= 1001)
{
sum += 5*n+4;
n++;
}
printf("%d\n", sum);
return 0;
}
第二部分:
#include "stdio.h"
int main()
{
int n;
printf("please input the number n: ");
while (scanf("%d", &n) && n != 0)
{
while (n>0)
{
for (int i=1; i<=n; i++)
printf("*");
printf("\n");
n--;
}
printf("\n");
printf("please input the number n: ");
}
return 0;
}
第三部分:
#include "stdio.h"
int main()
{
long s = 0, t;
int n;
printf("please input the number n: ");
scanf("%d", &n);
while (n > 0)
{
t = 1;
for (int i=1; i<=n; i++)
t *= i;
s += t;
n--;
}
printf("the sum is: %ld\n", s);
return 0;
}
第四部分:
#include
#include
void main()
{
int option=0; /*选择用变量,use to record user's press*/
int celsius; /*摄氏温度,she shi wen du*/
int fahrenheit; /*华氏温度,hua shi wen du*/
while (option!=3)
{
printf("1 for Fahrenheit to Celsius;\n");
printf("2 for Celsius to Fahrenheit;\n");
printf("3 to quit.\n");
printf("Please to choose: ");
scanf("%d",&option);
printf("\n");
if (option == 1)
{
scanf("%f",&fahrenheit);
celsius=(fahrenheit-32)*5/9;
printf("The Fahrenheit %f in Celsius is %f\n",fahrenheit,celsius);
}
else if(option == 2)
{
scanf("%f",&celsius);
fahrenheit=(celsius*9/5)+32;
printf("The Celsius %f in Fahrenheit is %f\n",celsius,fahrenheit);
}
printf("Press any key to continue...");
getch(); /*pause for screen, press any key to continue*/
clrscr();
}
}