當前位置:首頁 » 編程語言 » c語言採集8個數據
擴展閱讀
webinf下怎麼引入js 2023-08-31 21:54:13
堡壘機怎麼打開web 2023-08-31 21:54:11

c語言採集8個數據

發布時間: 2022-06-25 23:55:34

c語言編寫程序將用戶輸入的8個整數按從小到大的次序排序輸出,同時輸出平均值

因為數據量比較小,採用簡單的冒泡排序就可以實現,如果要更改為從大到小的次序排序,那麼只要把原先的大於號改為小於號就可以了,至於要輸出平均值,在讀入數據的時候,順便求總和最後除以8.0就可以得到平均值了

⑵ C語言中,從鍵盤輸入8個字元,分別統計其中大寫字母,小寫字母以及數字的個數。

#include<stdio.h>
#include<stdlib.h>
#include<ctype.h>

#defineletterAmount8

intmain(intargc,char*argv[])
{
unsignedintuppercaseAlpha=0,lowercaseAlpha=0,digit=0;
for(unsignedcharcount=1;count<=letterAmount;)
{
intc=getc(stdin);
if(isupper(c))
uppercaseAlpha++;
elseif(islower(c))
lowercaseAlpha++;
elseif(isdigit(c))
digit++;
else
continue;
count++;
}
fwprintf(stdout,L"uppercaseAlpha%u",uppercaseAlpha);
fwprintf(stdout,L"lowercaseAlpha%u",lowercaseAlpha);
fwprintf(stdout,L"digit:%u",digit);
system("pause");
returnEXIT_SUCCESS;
}

⑶ 求助 用c語言編程 用8個超聲波同時探測距離,並且把數據比較,然後控制輸出

利用雙重循環,可以實現大到小或者是小到大輸出
例如:
int a[8]={八個數據}
for(i=0;i<8;i++)
for(j=i+1,j<8;j++)
if(a[i]>a[j])
t=a[i],a[i]=a[j],a[j]=t;

⑷ 如何用C語言編寫一個循環採集8個通道數據的A/D轉換程序

如果使用TC,直接inport即可。每一種C都不一樣,看其幫助可以知道。

⑸ 是用C語言實現如下功能:從鍵盤輸入8個整數,使用冒泡排序法把他們升序輸出。

#include 「stdio.h」
main()
{int a[8];
int j,i;
for(i=0;i<8;i++)
{ printf(「請輸入第%d個數:\n」,i+1);
scanf(「%d」,&a[i]);
}
for(j=1;j<9;j++)
for(i=0;i<8–j;i++)
{if(a[i]>a[i+1]) a[i+1]=a[i];

}
for(i=0;i<8;i++)
printf("\n排序後的結果是:%d\n",a[i]);
return 0;
}

⑹ c語言對給定的8個數據排序

#include<stdio.h>
main()
{
int i,j,t,a[8];
printf("請輸入8個數:");
for(i=0;i<8;i++)
scanf("%d",&a[i]);
printf("\n");
for(i=0;i<8;i++)
{for(j=i+1;j<8;j++)
{if(a[j]>a[i])
{t=a[i];a[i]=a[j];a[j]=t;}}
}
for(i=0;i<8;i++)
{printf("%d\n",a[i]);}
}

試試這個吧,數組是從a[0]開始的,你讓它從a[1]開始了,還有你循環中用了j。但是在循環中沒有沒有用到j。所以有錯誤。。。

⑺ c語言我想從8個數中選擇5個不重復的數字,麻煩高手指點,據說可以用遞歸,但我一點都不會啊

#include<stdio.h>

#define N 5

int a[8]={1,2,3,4,5,6,7,8};

int b[N];//存儲選擇的數據

void FUN(int m,int n)
{
if(n>=N)
{
for(int i=0;i<N;i++)
printf("%d ",b[i]);
printf("\n");
}
else
{
for(int j=m;j<8;j++)
{
b[n]=a[j];
FUN(j+1,n+1);
}
}
}

void main()
{
FUN(0,0);

}

⑻ 單片機串列口自發自收八條數據的c語言怎麼寫,謝謝!!!

#include<reg51.h>
#defineucharunsignedchar
ucharrecive[8],send[8];
ucharnum;
voiart()interrupt4
{
if(RI)
{
RI=0;
recive[num]=SBUF;
num++;
num%=8;
}
}
main()
{
uchari;
TMOD=0x20;
TH1=0xfd;
TL1=0xfd;
TR1=1;
ES=1;
EA=1;
SCON=0x50;
for(i=0;i<8;i++)
{
SBUF=i;
while(TI==0);
TI=0;
}
while(1);
}

⑼ 用C語言編程怎麼將8個整數讀入一個數組,並以逆序存儲並顯示這8個數。

如果你需要的是字元串的比較請使用strcmp的系統函數

我寫的代碼

#include <stdio.h>
//返回值判斷首尾相同的結果
//n返回的是相同字元出現的次數
bool Jurdge(char *one, char *other,int* n)
{
bool begin = false;
bool end = false;
char *ptr_one = one;
char *ptr_other = other;
int counter = 0;
if(*one == *other)
{
begin = true;
}
while(*ptr_one)
{
ptr_one++;
}
while(*ptr_other)
{
ptr_other++;
}
if(*ptr_one == *ptr_other)
{
ptr_end = true;
}
if(strlen(one) >= strlen(other))
{
while(*other)
{
if(*one == *other)
{
counter+=1;
one++;
other++;
}
}
}
else
{
while(*other)
{
if(*other == *one)
{
counter+=1;
other++;
one++;
}
}
}
*n = counter;
if(begin&&end)
{
return true;
}
else
{
return false;
}
}