POLITO COMPUTER SCIENCE lab numero uno

**这玩意纯属于自己练习时候写的而且没写完,别介意写成啥样。

Draw the flow-chart to determine if a number is a prime number; in particular, the solution must :
满足以下条件
a) Acquire using the keyboard an integer value
通过键盘来输入一个实数
b) Use the simple structures while - do or do - while to determinate, using a loop, if the number is a prime number
使用do-while或者while-do来判断是否是一个prime number(素数:既除其本身和1无任何公约数)
c) Print in the screen a message depending on the cases.
用switch case将其显示在屏幕上

#include<stdio.h>
int main()
{
	printf("pls int the value! \n");
	int num, temp = 1,result,mark=1;
	scanf("%d", &num);
	if (num==0)
	{
		printf("shouldn't be 0!");
		return 0;
	}
	else if(num == 1)
	{
		printf("it is 1!");
		return 0;
	};
	do
	{
		temp++;
		result = num % temp;
		if (result==0)// 等于0的话代表着能被整出
		{
			mark = 0;
		}
	} while (temp<num-1&&mark!=0);
	switch (mark)
	{
	case 0:printf("this is not a prime num!\n");
	case 1:printf("this is a  prime num\n");
	}
		return 0;
}

Write a C program that defines 3 integer variables called operand1, operand2 and result. The program must:
写一个C语言程序:定义三个值:operand1, operand2 和result.
a) Acquire using the keyboard the values of operand1 e operand2 using the scanffunction
通过键盘和scanf函数来输入operand1 和 operand2的数值。
b) Compute the sum of operand1 and operand2 and save it in the result variable
求其和并保存在result中
c) Display on the screen the value of the result variable using the printf function
然后在用printf函数将其打印在屏幕上

int main()
{	
		int operand1, operand2, result;
		printf("pls int two value!");
		scanf("%d %d", &operand, &operand);
		result = operand1 + operand2;
		printf("%d", result);
		return 0;
}

Write a C program able to solve a first degree equation given in the form ax + b = 0;
the program must :
写一个计算ax+b=0程序
a) Define two integer values(int), a and b to store the coefficients of the equation
定义 a和b
b) Define an integer variable x in order to store the result of the equation
定义一个x来储存结果
c) Acquire using the keyboard the value of the coefficients a and b
在键盘上输入a和b的值;
d) Compute the value x and display it on the screen.
计算出x的值
In - depth: consider, among the others, the case in which the value a is equal
to 0.注意a=0的情况

*/

#include<stdio.h>
int main()
{
	int a;
	int b;
	float x;
	printf("pls int a and b\n");
	scanf("%d %d", &a, &b);
	if (a==0)/*这里是a=0时候的处理*/
	{
		printf("a shoulden't be zero!");
		return 0;
	};
		x = -b / a;
	printf("x is %f", x);
	return 0;
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值