c語言is0
㈠ 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] = '