一个指针要同时接受三个变量,求指教!打印出来如下图.
来源:学生作业帮 编辑:百度作业网作业帮 分类:综合作业 时间:2024/05/09 02:05:05
一个指针要同时接受三个变量,求指教!打印出来如下图.
We know that theroots of a quadratic equation of the form
ax2 + bx + c = 0 are given by the following equations:
x1 = ( -b + square – root ( b2 – 4ac ) )/ 2a ;
x2 = ( -b - square – root ( b2 – 4ac ) )/ 2a ;
Write a function to calculate the roots.The functionmust use two pointer parameters,one to receive the coefficients a,b,and c,and the other to send the roots to the calling function.(Hint:function namesimilary to void answer(int *c,float *root))
We know that theroots of a quadratic equation of the form
ax2 + bx + c = 0 are given by the following equations:
x1 = ( -b + square – root ( b2 – 4ac ) )/ 2a ;
x2 = ( -b - square – root ( b2 – 4ac ) )/ 2a ;
Write a function to calculate the roots.The functionmust use two pointer parameters,one to receive the coefficients a,b,and c,and the other to send the roots to the calling function.(Hint:function namesimilary to void answer(int *c,float *root))
你忘了一句话”数组即指针”.只要把指针指向一个数组,就OK了.代码如下.#include<stdio.h>
#include<math.h>
void answer(int* c, float* root)
{
char ch = 'A';
int k = 0;
float fTemp;
for (ch = 'A'; ch < 'D'; ch++)
{
printf("Enter the Value of %c : ", ch);
scanf("%d", &c[ch - 'A']);
}
k = c[1] * c[1] - 4 * c[0] * c[2];
if (k < 0)
{
printf("the root is not possible.\n");
}
else if (k == 0)
{
root[0] = root[1] = (-c[1]) / (2 * c[0]);
printf("the root is %.2f\n", root[0]);
}
else
{
fTemp = sqrt((double)k);
root[0] = (-c[1] + fTemp) / (2 * c[0]);
root[1] = (-c[1] - fTemp) / (2 * c[0]);
printf("the roots are %.2f and %.2f\n", root[0], root[1]);
}
}
void main()
{
int factor[3] = {0};
float root[2] = {0};
answer(factor, root);
}
#include<math.h>
void answer(int* c, float* root)
{
char ch = 'A';
int k = 0;
float fTemp;
for (ch = 'A'; ch < 'D'; ch++)
{
printf("Enter the Value of %c : ", ch);
scanf("%d", &c[ch - 'A']);
}
k = c[1] * c[1] - 4 * c[0] * c[2];
if (k < 0)
{
printf("the root is not possible.\n");
}
else if (k == 0)
{
root[0] = root[1] = (-c[1]) / (2 * c[0]);
printf("the root is %.2f\n", root[0]);
}
else
{
fTemp = sqrt((double)k);
root[0] = (-c[1] + fTemp) / (2 * c[0]);
root[1] = (-c[1] - fTemp) / (2 * c[0]);
printf("the roots are %.2f and %.2f\n", root[0], root[1]);
}
}
void main()
{
int factor[3] = {0};
float root[2] = {0};
answer(factor, root);
}
C语言:定义两个变量A,B并赋值,分别两个指针指向这两个变量,通过指针变量a和b的值并打印出来.
指针:任意输入三个实数,打印其最大值,最小值,平均值,要求用函数及指针作函数实参,指针变量作形参
C语言中当我定义了一个指针变量的同时,是否就为这个指针变量开辟了一个空间
力控怎么打印?我现在做一个数据采集机,想把那一时刻温度,湿度,压力,型变量,这些数据打印出来
excel基本问题,请指教下小弟!如下图,我要计算箱数和零头的综合在重量那里计算出来.
用C语言 for 循环语句打印一个三角形图案 ,具体如下图
打印星号三角形.输入一个整数N,表示三角形的行数.输出如下图的三角形.
举例说明什么是指针?如何让指针指向一个变量?
两条线段把三角形分为三个三角形和一个四边形,如下图,求四边形面积
写程序 :输入两个变量,求和求积 (1.指针变量 2.只定义一个函数)
求SPSS相关分析高手,一个变量有三个分组,另一个变量有三个分组
C语言中向一个函数传递一个数组,函数中定义一个指针变量,请问这个指针变量在for循环中要怎么使用?