当前位置:三九宝宝网 → 宝宝教育 → 教学论文 → 正文

C语言统计数组每个元素个数

更新:01-03 整理:39baobao.com
字体:

[C数组 strlen函数问题]strlen所作的仅仅是一个计数器的工作,它从内存的某个位置(可以是字符串开头,中间某个位置,甚至是某个不确定的内存区域)开始扫描,直到碰到第一个字符串结束符'\0'为止,然后返回计数...+阅读

void test()

{

srand((int)time(0));

int i, j;

int a[100];

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

{

a[i] = (int)(rand() * 10.0 / RAND_MAX); //随机数限定在0~10之间更能看出效果

}

//排序

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

{

for(j=i; j<100; j++)

{

if(a[i]> a[j])

{

int temp = a[i];

a[i] = a[j];

a[j] = temp;

}

}

}

//输出统计结果

i=0;

while(i<100)

{

int count =0;

int v = a[i];

while((v == a[i]) & i<100)

{

i++;

count++;

}

printf("%d 出现 %d 次\n", v, count);

}

}

本文地址:https://www.39baobao.com/show/29_21908.html

以上内容来自互联网,请自行判断内容的正确性。若本站收录的信息无意侵犯了贵司版权,请联系我们,我们会及时处理和回复,谢谢.

以下为关联文档:

万方 CNKI EI读秀这四个数据库的优劣势1、万方的特点:在中文文献全文中一个字“精”。科技文献都是精品,特别是万方的医药数据库,“中华牌”的系列,权威性很高。外文靠的是文献传递。 2、CNKI:一个字“全”,收录量与期...

研究生毕业论文在知网上查重的话都是参照哪几个数据库1、知网学位论文检测为整篇上传,格式对检测结果可能会造成影响,需要将最终交稿格式提交检测,将影响降到最小,此影响为几十字的小段可能检测不出。对于3万字符以上文字较多的论文...

c语言将一个数组里的字符串复制到另一个数组中比如源字符串是s,要复制到另一字符串t中,这里必须满足t能放得下s的全部元素,否则将会有危险发生。举例代码如下: //#include "stdafx.h"//If the vc++6.0, with this line. #inclu...

C语言传字符串数组当指针用 // aa.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include <iostream> using namespace std; void fu(char *buf) { str...

c语言:数组:不用strcpy函数实现字符串的复制#include<stdio.h> void Copy_string(char* str1, char* str2); //函数声明 int main() { char str1[20]; char str2[20]; puts("请输入字符串str1:"); gets(str1); //获取从键盘...

C语言:编写一个函数实现把一字符串复制到一个字符数组展开全部 # include void strcopy( char str1[], char str2[]) { int i; for(i=0;str[i]!= '\0';i++) { str1[i]=str2[i]; s1[i]='\0'; } } void main() {char str1[20];str...

c语言中怎样统计字符串中包含英文字母的个数#include int count_letter(char *str) { char *p = str; int cnt = 0; //开始计数 while (*p != '\0') { if ((*p >= 'a' & *p = 'A' & *p cnt++; } p++; } //计数完成 pri...

C语言统计二维字符数组里的字母个数怎么做#include <stdio.h>int fun(char ar[4][6], char c) { int count = 0, i, j; for (i = 0; i < 4; ++i) for (j = 0; j < 6; ++j) if (ar[i][j] == c) ++count; return count...

c语言数组下标越界int a[2]; -- c / c++ 语言中叫它是 “声明”,声明 a 是整型数组,有2个元素。 c / c++ 语言 下标 从0起计。 声明 int a[2]; 它只含 数组元素, 下标变量 a[0],a[1]。 语句中 写...