www.ylrr.net > 求一个关于C语言的程序! 问题:输入若干整数,统...

求一个关于C语言的程序! 问题:输入若干整数,统...

#include<stdio.h> void main() { int i,n,z,f,x; printf("请输入一共要处理几个数:"); scanf("%d",&n); for ( i=z=f=0;i<n;i++ ) { scanf("%d",&x); if ( x>0 ) z++; else if ( x<0 ) f++; } printf("大于0的数有%d个,小于0的数有%d个.",z,f); }

当然可以啊.你可以把n也当做一个变量,让用户选择输入.#include #include void main(void) { int n = 0; int i = 0; printf("请输入数据个数:"); scanf("%d", &n); for (i = 0; i { printf("请输入第%d个数\n", i + 1); } }

#include main() { int i,b=0,c=0; do { scanf("%d",&i); if(i>0) b++; else if(i c++; }while(i!=0); printf("%d,%d",b,c); }

#include int main() {int max,min,num; printf("Input numbers,-1 to end:\n"); scanf("%d",&num); max=min=num; while(num!=-1) { if(num>max)max=num; if(num scanf("%d",&num); } printf("max:%d,min:%d\n",max,min); system("pause"); return 0; }

#include "stdio.h"int main(int argv,char *argc[]){ int d[100],n[5]={0},i; printf("Input some numbers(int 1~5)\n"); for(i=0;i<300;i++){ if(scanf("%d",d+i)!=1){ printf("Enter

#includevoid main(){int a=0,b=0,n;scanf("%d",&n);while(n != 0 ){scanf("%d",&n);if(n>0) a=a+1; if(n 评论0 0 0

#include<stdio.h>#include<stdlib.h> void main() { int i,*a; a=(int *)malloc(sizeof(int)* 1); i=0; do{ scanf("%d",&a[i]);i++; a=(int *)realloc((int *)a,sizeof(int)*(i+1)); }while(a[i-1]!=-1); free(a); printf("num:%d\n",i-1); }

#include<stdio.h>#define M 100void main(){ int max,a[M],i=0,m; printf("输入数:\n"); scanf("%d",&a[0]); while(a[i]>=0){ scanf("%d",&a[++i]); } m=i; max=a[0]; for(i=1;i<m;i++) if(max<a[i]) max=a[i]; printf("%d\n",max);}

利用字符串处理方法:#include <stdio.h>#include <stdlib.h>void reversed(){ char c = getchar(); if (c == '\n') return; reversed(); putchar(c);}int main(){ reversed(); putchar('\n'); return 0;}

#include<stdio.h> main() { int n,s=1,k=-1; do{ scanf("%d",&n); s+=n; k++; }while(n!=-1); printf("和为%d,平均值为%f.",s,s*1.0/k); }您好,很高兴为您解答,流星不死为您答疑解惑 如果本题还有不懂的地方请追问,望采纳我的回答.祝楼主学习进步.上面的代码可以直接复制到编译器里,带换行.

网站地图

All rights reserved Powered by www.ylrr.net

copyright ©right 2010-2021。
www.ylrr.net内容来自网络,如有侵犯请联系客服。zhit325@qq.com