當前位置:首頁 » 編程語言 » 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(" ");
}