第一次C程序设计课后作业

姓名:林晓辉  学号:120705124   班级:12电信1

 

目标:初步了解和程序的编写

任务一:例5-7

 

我的程序:

/*源程序:exp5_7.cpp*/
#include<stdio.h>
void main()
{ int n,i=0;
  for(n=100;n<=150;n++)
  { if(n%3==0)
     continue;
    printf("%d",n);
	i++;
	if(i%10==0)
		printf("\n")
  }
  printf("\n");
}

 

第一次运行程序“错误列表”:

错误:少了一个分号

错误原因及解决方法:多录入了一个“;”。

程序运行效果截图:

 

------------------------------任务分割线-------------------------------------------

任务二:例5-10

 

我的程序

/*源程序:exp5_10.cpp*/
#include<stdio.h>
void main()
{ int i,j;
  int sum1,sum2=0;
  for(i=1;i<=5;i++)
  { sum1=1;
    for(j=1;j<=i;j++)
	  sum1=sum1*j;
	sum2=sum2+sum1;
  }
  printf("1!+2!+3!+4!+5!=%d\n",sum2);
}


 

第一次运行程序“错误列表”:

吸取上次教训,注意了一下标点,没有错误~

 

程序运行效果截图:

 

------------------------------任务分割线-------------------------------------------

任务三:例6-2

我的程序:

 

/*源程序:exp6_2.cpp*/
#include<stdio.h>
void main()
{
	void printfline();
	int max(int a,int b);
	int x,y,z,d;
	printfline();
	printf("input three numbers:\n");
	scanf("%d%d%d",&x,&y,&z);
	d=max(x,y);
	d=max(d,z);
	printf("maxmum=%d\n",d);
}
void printfline()
{
	printf("This is a C program!\n");
}
int max(int a,int b)
{
	if(a>b)return a;
	else return b;
}


第一次“错误列表”:

没有错误,顺利运行程序~

程序运行效果截图:

 

------------------------------任务分割线-------------------------------------------

任务四:例6-3

 我的程序:

/*源程序: exp6_3.cpp*/
#include<stdio.h>
void main()
{
	void swap(int x,int y);
	int a,b;
	a=2,b=6;
	printf("调用前:a=%d,b=%d\n",a,b);
	swap(a,b);
	printf("调用后:a=%d,b=%d\n",a,b);
}
void swap(int x,int y)
{
	int temp;
	printf("交换前:a=%d,y=%d\n",x,y);
	temp=x;
	x=y;
	y=temp;
	printf("交换后:x=%d,y=%d\n",x,y);
}


第一次“错误列表”:

顺利运行~

程序运行效果截图:

 

-------------------------------------------任务分割线------------------------------------------------

感想:完事都得细心,特别是入门阶段~不然会碰很多壁的,当然,吃一堑长一智,出错也不算太坏~

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值