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] = '