好吧伙计们,所以这是一个家庭作业,但它已被提交,我收到了78:。我的教授尚未回复我的帮助电子邮件所以我现在在这里。分数减少C程序
代码的第一部分应该是将分数减少到最低的形式,它的工作原理除非当最大公分母大于10时。这是C类的介绍,我几乎没有经验与C和它的特殊性。任何有关GCD问题的帮助/指导/想法..?
#include <stdio.h>
int main (void)
{
int num;
int den;
int x;
int y;
int i;
int a;
int n;
int w;
int j;
printf("\n *************Question 1 *************** \n");
printf("Please enter the numerator: ");
scanf("%d", &num);
printf("Please enter the denominator: ");
scanf("%d", &den);
printf("The fraction entered is: \n %d/%d \n", num, den);
if (num > den)
x=den;
else
x=num;
for(i=x; i>=1; i--){
if(num % i == 0 && den % i == 0){
printf("This fraction can be reduced! \n");
num = num/i;
den = den/i;
printf("The reduced fraction is %d/%d \n \n", num, den); break;}
else
printf("This fraction cannot be reduced any further \n");
break;
}
printf("\n ***************Question 2****************** \n");
printf("Please enter a number and I will print the even squares up to your input ");
scanf("%d", &n);
for (w=1; w<=n; w++)
if (w*w%2 == 0 && w*w <= n)
printf("%d \n", w*w);
printf("Question 5 test... please enter 10.3 then 5 then 6 ");
scanf("%d%f%d",&i,&x,&j);
printf("%d %f %d \n",i,x,j);
return 0;
}
你对得到一个+ 1)告诉我们它是家庭作业,由欧几里德描述b)您尝试过一些东西。但请在缩进 –
处有另一个,由于代码的易读性较低,您可能会损失大部分额外的22个百分点。永远不要低估可读性的重要性。另外,你最好更有意义地给你的变量命名,并且根本没有评论来表明你的代码是/应该做什么。 –