當前位置:首頁 » 編程語言 » c語言is0

c語言is0

發布時間: 2022-06-19 07:02:32

c語言 為什麼顯示0呀

#include<stdio.h>
#define LENGTH 4
void main()
{
void Input(float array[],int);

void Output(float array[],int);
float wuli[LENGTH+1];
float gaoshu[LENGTH+1];
float Sum[LENGTH+1];
float Average[LENGTH+1];
int counter;
int choice;
int choice1,choice3;
printf("\n Warning: You should inout your date before you use it!Or your date is 0!");
for(counter=0;counter<=LENGTH;counter++){
wuli[counter]=0;
gaoshu[counter]=0;
}
while(1){
printf("\nInput-----1;\nScreen-----2;\nOutput-----3;\nExit-----4.\n");
printf("Please enter your choice:");
scanf("%d",&choice);
if(choice==1){
while(1){
printf("\n Choose the subject :\nwuli-----1;\ngaosghu-----2;\nExit-----3;\n");
printf("\n Enter you choice:\n");
scanf("%d",&choice1);
if(choice1==1){
printf("\nwuli\n");
Input(wuli,LENGTH);
}
else if(choice1==2){
printf("\ngaoshu\n");
Input(gaoshu,LENGTH);
}
else{
break;
}
}
}
else if(choice==2){
for(counter=0;counter<=LENGTH;counter++){
Sum[counter]=wuli[counter]+gaoshu[counter];
Average[counter]=(wuli[counter]+gaoshu[counter])/2;
}

}
else if(choice==3){
while(1){
printf("\n OutPut\nwuli-----1;\ngaoshu-----2;\nSum-----3;\nAverage-----4;\nExit-----5.\n");
printf("Enter your choice:");
scanf("%d",&choice3);
if(choice3==1){
printf("\nOutput wuli\n");
Output(wuli,LENGTH);
}
else if(choice3==2){
printf("\nOutput gaoshu\n");
Output(gaoshu,LENGTH);
}
else if(choice3==3){
printf("\nOutput Sum\n");
Output(Sum,LENGTH);
}
else if(choice3==4){
printf("\nOutput Average\n");
Output(Average,LENGTH);
}
else{
break;
}
}
}
else{
break;
}
}
}

void Input(float array[],int length)
{
int counter;
for(counter=1;counter<=length;counter++){
printf("\nPlease enter the date of NUMBER %d:",counter);
scanf("%f3.1",&array[counter]);
}
}

void Output(float array[],int length)
{
float temp[LENGTH+1];
int index[LENGTH+1];
int n=1;
int m,UpLimit,counter;
float max;
float [LENGTH+1];
for(counter=1;counter<=length;counter++){
[counter]=array[counter];
}
for(UpLimit=length;UpLimit>0;UpLimit--){
max=0;
for(counter=1;counter<=length;counter++){
if([counter]>max){
m=counter;
max=[counter];
}
}
temp[n]=max;
index[n]=m;
n++;
[m]=0;
}
for(counter=1;counter<=LENGTH;counter++){
printf("\n%d-----%3.1f",index[counter],temp[counter]);
}
}

幫你把警告改掉了,還有output函數修改了,只保證output輸出由大到小不出錯,其他部分如果有邏輯錯誤就和我沒關系了.
output輸出全0是因為你寫錯了第一個for循環count=0
應該是count=1;
看了你的程序知道你把數組[0]丟掉沒用

㈡ c語言編程代碼

兩種方法我寫在一起,可以獨立拆開。

#include <stdio.h>

void finda1(char a[3][10]);

void finda2(char a[3][10]);

void show(char (*p)[10]);

int main()

{

char a[3][10]={{"gehajl"},{"788a987a7"},{"ccabbbabbb"}};

printf("原數組內容: ");

show(a);

printf(" 1、用數組指針的方法(函數finda1): ");

finda1(a);

printf("執行後: ");

show(a);


printf(" --------------------- ");


char b[3][10]={{"gehajl"},{"788a987a7"},{"ccabbbabbb"}};

printf("原數組內容: ");

show(a);

printf(" 2、用指針數組的方法(函數finda2): ");

finda2(b);

printf("執行後: ");

show(b);

return 0;

}

void finda1(char a[3][10])

{

int i,j;

char (*p)[10]=a;

for(i=0;i<3;i++)

for(j=0;j<10;j++)

if(p[i][j]=='a')

printf("發現:第%d行第%d個元素是『a』,已替換 ",i+1,j+1),p[i][j]='1';

}

void finda2(char a[3][10])

{

int i,j;

char *p[3]={&a[0][0],&a[1][0],&a[2][0]};

for(i=0;i<3;i++)

for(j=0;j<10;j++)

if(p[i][j]=='a')

printf("發現:第%d行第%d個元素是『a』,已替換 ",i+1,j+1),p[i][j]='1';


}

void show(char (*p)[10])

{

int i,j;

for(i=0;i<3;i++,printf(" "))

for(j=0;j<10;j++)

printf("%c ",p[i][j]);

}

㈢ C語言。定義一函數is(int number) 判斷number是否為素數

int is(int number)
{
int m=2,k=0;
while(m<number) /*從數學角度講這里比較到number開方就可以了sqrt(number)*/
{
if((number%m)!=0)
m++;
else
k++;
}
return k; /*這里的判斷不完整,*/
}

/*返回0表示有約數,1表示質數*/
int is(int number)
{
int m=2,k=0;
while(m<=sqrt(number)) /*從數學角度講這里比較到number開方就可以了sqrt(number)*/
{
if((number%m)==0)
return 0; /*直接返回就ok*/
else
m++;
}
return m==sqrt(number); /*這里如果沒有找到約數那麼必然是m==sqrt(number),/
}
你寫的思路稍微有點問題,邏輯上也有點問題,但是大體思路正確。你對比下我寫的,再看下我改的,你多思考思考,希望你有所收獲

㈣ 關於C語言編程作業問題

沒看明白你寫的,提供一個作參考……
//#include "stdafx.h"//vc++6.0加上這一行.
#include "string.h"
char *fun(char *p){
char *pt,f=0;
while(pt=strstr(p,"is"))
f=pt[0]='b',pt[1]='e';
if(f) return p;
else return NULL;
}
void main(void){
char a[1000];
printf("Type a string...\nstr=");
gets(a);
if(fun(a)) printf("\n%s\n",a);
else printf("\nNo \'is\'!\n");
}

㈤ 想知道c語言中is表示什麼意思

沒有is的,你看到的那個is是在雙引號內的,是一個字元串里的內容,輸出的時候按照原樣is輸出,你要是把is換成are那它輸出就變成are

㈥ C語言按照如下方式從頭到尾逐字元地對輸入字元串is 進行處理,以生成輸出字元串os 並作為結果輸出:

#include <stdio.h>

#include <string.h>

int main(void)

{

char is[1000],os[1000];

int len,len1;

int i = 0;

int j = 0;

int m;

gets(is);

len = strlen(is);


while(i < len)

{

if(is[i] >= '0' && is[i] <= '9')

{

len1 = is[i] - '0';

for(m = 0; m <=len1;m++)

{

os[j++] = 'a' + len1;

}

i++;

}

else


os[j++] = is[i++];

}

os[j] = '';

puts(os);




}

㈦ C語言編程:輸入任意字元串,判斷其中有幾個「is"

#include<stdio.h>
#include<string.h>
int str_num(char * source,char * search);
void main()
{
int i;
char string[81];//源字元串
char * str2="is"; //要統計個數的字串
gets(string);
i=str_num(string,"is");
printf("字元串%s中共有%d個%s",string,i,str2);
putchar('\n');
}

int str_num(char * source,char * search)
{
int i=0;
while((source=strstr(source,search))!=NULL)
source++,i++;
return i;
}

㈧ C語言.為什麼S=0呢

s=s+i; //這里應該為s=s+a[i]

㈨ C語言中的運算符的&與&& 和 |與||有什麼區別,用在什麼地方

&和|是位運算。&&和||表示邏輯關系,&&和||表達式最終的值只可能是真(1)或者假(0),而位運算表達式的值不限於0和1 兩者在特定情況下的效果是相同的。操作方法如下:

1、首先這里用到字元的ascii碼,A的ASCII碼為65,之後用scanf函數進行輸入。if設置為嵌套語句,判斷輸入的字元是不是在A-Z之間,系統比較的是二者的ASCII碼,來輸入大寫字母G。

㈩ c語言,查找一個從鍵盤輸入的字元串中是否含有單詞is,有則輸出yes,否則輸出no

http://..com/question/508281383.html?oldq=1你可以看下這個,第一個函數可以找到字元串中是否所含單詞的個數,當個數大於1了就可以判斷他輸出YES,當單詞中<=0就輸出no,在main函數調用就行了。

熱點內容
開源庫編譯管理員 發布:2025-02-06 09:39:14 瀏覽:914
臉書怎麼注冊安卓 發布:2025-02-06 09:36:47 瀏覽:381
車用安卓導航無線打不開什麼原因 發布:2025-02-06 09:27:50 瀏覽:790
安卓與蘋果如何互相傳送文件 發布:2025-02-06 09:27:40 瀏覽:26
華為伺服器盤符如何分配 發布:2025-02-06 09:26:41 瀏覽:560
傳奇h5源碼下載 發布:2025-02-06 09:26:06 瀏覽:78
編譯uclibc 發布:2025-02-06 09:09:04 瀏覽:152
用gcc編譯16位匯編 發布:2025-02-06 09:06:07 瀏覽:823
什麼低端安卓手機不卡 發布:2025-02-06 09:03:32 瀏覽:13
我的世界伺服器卡領地 發布:2025-02-06 08:50:45 瀏覽:256