当前位置:首页 » 编程语言 » c语言检验产品合格程序
扩展阅读
webinf下怎么引入js 2023-08-31 21:54:13
堡垒机怎么打开web 2023-08-31 21:54:11

c语言检验产品合格程序

发布时间: 2022-08-27 22:22:25

c语言求救2

楼上少了一题,而且一看楼上就是学C++的,C语言的题目用C++来回答。我晕,哈哈,我给出的答案是:
20-25::BDCBCC
26-27:AD
28题空,你没写
29: C
30:C
32:A (真机测试结果)
33:B
34:A

程序题1:
#include<stdio.h>

int main(void)
{
int i,temp=0,sum=0;

printf("请输入产品检测结果:\n");
for(i=1;i<=1000;i++)
{

scanf("%d",&temp);

//如果合格,累计合格数
if(temp==1)
sum++;
}
printf("产品合格率为:%f\n",(float)sum/1000);
return 0;
}

程序题2:
#include<stdio.h>

double girth(double r);

int main(void)
{
double temp;
printf("请输入半径:\n");
scanf("%lf",&temp);
printf("周长为:%lf\n",girth(temp));
return 0;
}

double girth(double r)
{
return 3.14*r*2;
}
第3题:
#include<stdio.h>

float Avg(float fenshu[],int length);

int main(void)
{
float score[3]={0};
int i;

for(i=0;i<3;i++)
{
printf("请输入第%d个学生的成绩:\n",i+1);
scanf("%f",&score[i]);
}

printf("3个学生的平均成绩是:%.2f\n", Avg(score,3));

return 0;
}

float Avg(float fenshu[],int length)
{
float sum=0;
int i;

for(i=0;i<length;i++)
{
sum+=fenshu[i];
}
return (float)(sum/length);
}

程序题全部通过上机测试,正常有效

❷ 帮忙设计个检测电器可靠性的程序【c语言程序设计】

第一个,因为没有看到你里面具体A代表的含义,假设A为这批试品的不合格率
A = (r/n)/(n/N)

if(A<=Ac)
{
printf("Proct PASS! \n");
}
else
{
printf("Proct Reject! \n");
}

第二个,假设不大不小的工作时间(应该是一个时间段吧)为T_OK_LOW 至 T_OK_HIGH,其中T_OK_LOW <T_OK_HIGH”,其中t[n-1]=tn,即 t[0]=t1,

UINT i,t[n]={0},t=0;

for(i=0;i<n;i++)
{
printf("Please input the work time of %d sample \n",i+1); //界面输入单个产品的检测时间,第i+1个
scanf("%d",&t[i]);
t=t+t[i];
if(t<(T_OK_LOW*(i+1)))
{
printf("Low-grade sample,Reject! \n");
return;
}
else if(t>(T_OK_HIGH)*(i+1))
{
printf("high-grade sample,Accept! \n");
return;
}

}

if(i==n)
{
printf("All samples work in suitable time. \n");
}

❸ 编写C语言程序实现对产品信息管理

(1)
#include <stdio.h>

struct chanp
{
int chan_ID;
char chan_Name[20];
float chan_Price;
};
struct chanp chanp1[3] = {{1001,"Asdf",100.2},{1002,"Bsdf",123.3},{1003,"Cfd",3313.0}};
void main()
{
struct chanp* p;

printf("Information: 产品编号 产品名称 产品价格\n");
for(p=chanp1;p<chanp1+3;p++)
{

printf("%d%10s%15.2f\n",p->chan_ID,p->chan_Name,p->chan_Price);
}
}

(2)
#include <stdio.h>
#include <string.h>
struct chanp
{
int chan_ID;
char chan_Name[20];
float chan_Price;
};

void main()
{
struct chanp chan1[3];
struct chanp* p;
int id,findid;
int n=0;
char name[20];
float price;

for(int i =0;i<3;i++)
{
printf("Input: 产品编号 产品名称 产品价格\n"); scanf("%d%s%f",&id,name,&price);
chan1[i].chan_ID = id;
strcpy(chan1[i].chan_Name,name);
chan1[i].chan_Price = price;
}
printf("请输入ID:\n");
scanf("%d",&id);
for (p=chan1;p<chan1+3;p++)
{
if (id == p->chan_ID)
{
printf("该产品存在\n");
printf("Information: 产品编号 产品名称 产品价格\n"); �n");
printf("%d%10s%15.2f\n",p->chan_ID,p->chan_Name,p->chan_Price);
n++;
}
}
if (n == 0)
{
printf("该产品不存在\n");
}

}

(3)
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct chanp
{
int chan_ID;
char chan_Name[20];
float chan_Price;
};

void main()
{
struct chanp chan1[3];
struct chanp* p;
int id,findid;
char ch[10];
int n=0;
char name[20];
float price;

for(int i =0;i<3;i++)
{
printf("input: 产品编号 产品名称 产品价格�n");
scanf("%d%s%f",&id,name,&price);
chan1[i].chan_ID = id;
strcpy(chan1[i].chan_Name,name);
chan1[i].chan_Price = price;
}
printf("请输入查询产品的ID\n");
scanf("%d",&id);
for (p=chan1;p<chan1+3;p++)
{
if (id == p->chan_ID)
{
printf("产品存在。\n");
printf("需要修改产品信息请按Y或者y,否则请按任意键。\n");
scanf("%s",ch);
if (!strcmp(ch,"Y") || !strcmp(ch,"y"))
{
printf(" 请输入:产品名称 产品价格\n");
scanf("%s%f",name,&price);
strcpy(p->chan_Name,name);
p->chan_Price = price;
printf("Information: 产品编号 产品名称 产品价格\n"); �n");
printf("%d%10s%15.2f\n",p->chan_ID,p->chan_Name,p->chan_Price);
}
n++;
}
}
if (n == 0)
{
printf("该产品不存在。\n");
}

}
终于结束了

❹ 求判断及格不及格的c语言程序

感觉你这题有点模糊,给你个最简单的吧

#include"stdio.h"
void main()
{
double grade;

printf("请输入成绩:");

scanf("%f",&grade);

if(grade>=60)

printf("及格了!");
else

printf("不及格!");

}

❺ 关于C语言如何实现合法性的检验

可以使用如下的代码实现:
int y,m,d=0;
while(y<999||y>9999||m<1||m>12||d<1||d>31)
{printf("请输入日期mm/dd/yyyy:");
scanf("%2d/%2d/%4y",&m,&d,&y);
}

❻ C语言程序如何校验和执行

Ctrl+F9 - Alt+F5 反正不管哪个版本 先组建再编译 系统就自动检查是否有错误 最后在运行就OK了。

❼ c语言编程怎么测试程序的对错

自己好好看看程序吧,别依靠编译器,编译器不是万能的!

1.语法错误
在编译前浏览程序的源代码看看是否有明显的错误。
可以查看由编译器发现的错误。

发现错误——从第一个开始修改,每次修改1~2个,然后重现编译。
发现的错误位置可能比真正的错误要滞后一行。

2.语义错误
比较程序实际得到的结果和预期结果。
跟踪程序,执行步骤——可用EXCEL(语句行×变量值)
在程序的几个关键点处加入额外的printf()语句以监视所选变量的值。
或用调试器。

❽ C语言编程,手动输入<=1000的受检测产品,1表示正品,0表示次品,最后输出次品率和不合格的产品是第几个

#include<stdio.h>
voidmain()
{
intn,a,i=0,j=1,sum=0,x[100];
printf("inputtheprocts'number:");
scanf("%d",&n);
while(j<=n)
{
printf("iftureinput1,elseinput0:");
scanf("%d",&a);
if(a==0){x[i]=j;sum++;i++;}
j++;
}
printf("次品率:%f ",(float)sum/(float)n);
printf("次品分别是 ");
while(i)
{
printf("第%d个 ",x[i-1]);
i--;
}
printf(" ");
}