int num nums[] = { 1,1,2,2,3,4,4,4,5,5,5,6,7}; vector<int> b(num, num + 13); 为什么内存显示b的大小是0。

ASP.NET &&&&最新内容
ASP.NET &&&&相关内容Lua 5.3.4 source code - lobject.c
** $Id: lobject.c,v 2.113
13:08:50 roberto Exp $
** Some generic functions over Lua objects
** See Copyright Notice in lua.h
#include ""
#include &locale.h&
#include &math.h&
#include &stdarg.h&
#include &stdio.h&
#include &stdlib.h&
#include &string.h&
#include ""
#include ""
#include ""
#include ""
#include ""
#include ""
#include ""
#include ""
#include ""
** converts an integer to a "floating point byte", represented as
** (eeeeexxx), where the real value is (1xxx) * 2^(eeeee - 1) if
** eeeee != 0 and (xxx) otherwise.
(unsigned int x) {
int e = 0;
/* exponent */
if (x & 8)
while (x &= (8 && 4)) {
/* coarse steps */
x = (x + 0xf) && 4;
/* x = ceil(x / 16) */
while (x &= (8 && 1)) {
/* fine steps */
x = (x + 1) && 1;
/* x = ceil(x / 2) */
return ((e+1) && 3) | ((x) - 8);
/* converts back */
return (x & 8) ? x : ((x & 7) + 8) && ((x && 3) - 1);
** Computes ceil(log2(x))
(unsigned int x) {
static const
log_2[256] = {
/* log_2[i] = ceil(log2(i - 1)) */
0,1,2,2,3,3,3,3,4,4,4,4,4,4,4,4,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,
6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,
8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,
8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,
8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8
int l = 0;
while (x &= 256) { l += 8; x &&= 8; }
return l + log_2[x];
( *L, int op,
switch (op) {
case : return (+, v1, v2);
case :return (-, v1, v2);
case :return (*, v1, v2);
case : return (L, v1, v2);
case : return (L, v1, v2);
case : return (&, v1, v2);
case : return (|, v1, v2);
case : return (^, v1, v2);
case : return (v1, v2);
case : return (v1, -v2);
case : return (-, 0, v1);
case : return (^, ~(0), v1);
default: (0); return 0;
( *L, int op,
switch (op) {
case : return (L, v1, v2);
case : return (L, v1, v2);
case : return (L, v1, v2);
case : return (L, v1, v2);
case : return (L, v1, v2);
case : return (L, v1, v2);
case : return (L, v1);
(L, v1, v2, m);
default: (0); return 0;
( *L, int op, const
*p1, const
switch (op) {
case : case : case :
case : case :
/* operate only on integers */
if ((p1, &i1) && (p2, &i2)) {
(res, (L, op, i1, i2));
/* go to the end */
case : case : {
/* operate only on floats */
if ((p1, &n1) && (p2, &n2)) {
(res, (L, op, n1, n2));
/* go to the end */
default: {
/* other operations */
if ((p1) && (p2)) {
(res, (L, op, (p1), (p2)));
else if ((p1, &n1) && (p2, &n2)) {
(res, (L, op, n1, n2));
/* go to the end */
/* could not p try metamethod */
(L != NULL);
/* should not fail when folding (compile time) */
(L, p1, p2, res, (, (op - ) + ));
if ((c)) return c - '0';
else return ((c) - 'a') + 10;
static int
(const char **s) {
if (**s == '-') { (*s)++; return 1; }
else if (**s == '+') (*s)++;
** {==================================================================
** Lua's implementation for ''
** ===================================================================
#if !defined()
/* maximum number of significant digits to read (to avoid overflows
even with single floats) */
** convert an hexadecimal numeric string to a number, following
** C99 specification for 'strtod'
(const char *s, char **endptr) {
int dot = ();
/* result (accumulator) */
int sigdig = 0;
/* number of significant digits */
int nosigdig = 0;
/* number of non-significant digits */
int e = 0;
/* exponent correction */
/* 1 if number is negative */
int hasdot = 0;
/* true after seen a dot */
*endptr = (char *, s);
/* nothing is valid yet */
while (((*s))) s++;
/* skip initial spaces */
neg = (&s);
/* check signal */
if (!(*s == '0' && (*(s + 1) == 'x' || *(s + 1) == 'X')))
/* check '0x' */
return 0.0;
/* invalid format (no '0x') */
for (s += 2; ; s++) {
/* skip '0x' and read numeral */
if (*s == dot) {
if (hasdot)
/* second dot? stop loop */
else hasdot = 1;
else if (((*s))) {
if (sigdig == 0 && *s == '0')
/* non-significant digit (zero)? */
nosigdig++;
else if (++sigdig &= )
/* can read it without overflow? */
r = (r * (16.0)) + (*s);
else e++; /* ignore, but still count for exponent */
if (hasdot) e--;
/* decimal digit? correct exponent */
/* neither a dot nor a digit */
if (nosigdig + sigdig == 0)
/* no digits? */
return 0.0;
/* invalid format */
*endptr = (char *, s);
/* valid up to here */
/* each digit multiplies/divides value by 2^4 */
if (*s == 'p' || *s == 'P') {
/* exponent part? */
int exp1 = 0;
/* exponent value */
/* exponent signal */
/* skip 'p' */
neg1 = (&s);
/* signal */
if (!((*s)))
return 0.0;
/* must have at least one digit */
while (((*s)))
/* read exponent */
exp1 = exp1 * 10 + *(s++) - '0';
if (neg1) exp1 = -exp1;
e += exp1;
*endptr = (char *, s);
/* valid up to here */
if (neg) r = -r;
return (ldexp)(r, e);
/* }====================================================== */
/* maximum length of a numeral */
#if !defined ()
static const char * (const char *s,
*result, int mode) {
*result = (mode == 'x') ? (s, &endptr)
/* try to convert */
: (s, &endptr);
if (endptr == s) return NULL;
/* nothing recognized? */
while (((*endptr))) endptr++;
/* skip trailing spaces */
return (*endptr == '\0') ? endptr : NULL;
/* OK if no trailing characters */
** Convert string 's' to a Lua number (put in 'result'). Return NULL
** on fail or the address of the ending '\0' on success.
** 'pmode' points to (and 'mode' contains) special things in the string:
** - 'x'/'X' means an hexadecimal numeral
** - 'n'/'N' means 'inf' or 'nan' (which should be rejected)
** - '.' just optimizes the search for the common case (nothing special)
** This function accepts both the current locale or a dot as the radix
** mark. If the convertion fails, it may mean number has a dot but
** locale accepts something else. In that case, the code copies 's'
** to a buffer (because 's' is read-only), changes the dot to the
** current locale radix mark, and tries to convert again.
static const char * (const char *s,
*result) {
const char *
const char *pmode = strpbrk(s, ".xXnN");
int mode = pmode ? ((*pmode)) : 0;
if (mode == 'n')
/* reject 'inf' and 'nan' */
return NULL;
endptr = (s, result, mode);
/* try to convert */
if (endptr == NULL) {
/* failed? may be a different locale */
char buff[ + 1];
const char *pdot = strchr(s, '.');
if (strlen(s) &
|| pdot == NULL)
return NULL;
/* strin fail */
strcpy(buff, s);
/* copy string to buffer */
buff[pdot - s] = ();
/* correct decimal point */
endptr = (buff, result, mode);
/* try again */
if (endptr != NULL)
endptr = s + (endptr - buff);
/* make relative to 's' */
static const char * (const char *s,
*result) {
int empty = 1;
while (((*s))) s++;
/* skip initial spaces */
neg = (&s);
if (s[0] == '0' &&
(s[1] == 'x' || s[1] == 'X')) {
/* hex? */
/* skip '0x' */
for (; ((*s)); s++) {
a = a * 16 + (*s);
empty = 0;
/* decimal */
for (; ((*s)); s++) {
int d = *s - '0';
/* overflow? */
return NULL;
/* do not accept it (as integer) */
a = a * 10 +
empty = 0;
while (((*s))) s++;
/* skip trailing spaces */
if (empty || *s != '\0') return NULL;
/* something wrong in the numeral */
*result = ((neg) ? 0u - a : a);
(const char *s,
const char *e;
if ((e = (s, &i)) != NULL) {
/* try as an integer */
else if ((e = (s, &n)) != NULL) {
/* else try as a float */
/* conversion failed */
return (e - s) + 1;
/* return string size */
(char *buff, unsigned long x) {
int n = 1;
/* number of bytes put in buffer (backwards) */
(x &= 0x10FFFF);
if (x & 0x80)
/* ascii? */
buff[ - 1] = (char, x);
/* need continuation bytes */
unsigned int mfb = 0x3f;
/* maximum that fits in first byte */
/* add continuation bytes */
buff[ - (n++)] = (char, 0x80 | (x & 0x3f));
/* remove added bits */
mfb &&= 1;
/* now there is one less bit available in first byte */
} while (x & mfb);
/* still needs continuation byte? */
buff[ - n] = (char, (~mfb && 1) | x);
/* add first byte */
/* maximum length of the conversion of a number to a string */
** Convert a number object to a string
char buff[];
if ((obj))
len = (buff, sizeof(buff), (obj));
len = (buff, sizeof(buff), (obj));
#if !defined(LUA_COMPAT_FLOATSTRING)
if (buff[strspn(buff, "-")] == '\0') {
/* looks like an int? */
buff[len++] = ();
buff[len++] = '0';
/* adds '.0' to result */
(L, obj, (L, buff, len));
static void
( *L, const char *str, size_t l) {
(L, L-&top, (L, str, l));
** this function handles only '%d', '%c', '%f', '%p', and '%s'
conventional formats, plus Lua-specific '%I' and '%U'
const char * ( *L, const char *fmt, va_list argp) {
int n = 0;
for (;;) {
const char *e = strchr(fmt, '%');
if (e == NULL)
(L, fmt, e - fmt);
switch (*(e+1)) {
case 's': {
/* zero-terminated string */
const char *s = va_arg(argp, char *);
if (s == NULL) s = "(null)";
(L, s, strlen(s));
case 'c': {
/* an 'int' as a character */
char buff = (char, va_arg(argp, int));
if (((buff)))
(L, &buff, 1);
/* non- print its code */
(L, "&\\%d&", (buff));
case 'd': {
/* an 'int' */
(L-&top, va_arg(argp, int));
case 'I': {
/* a '' */
(L-&top, (, va_arg(argp, )));
case 'f': {
/* a '' */
(L-&top, (va_arg(argp, )));
/* convert the top element to a string */
(L, L-&top - 1);
case 'p': {
/* a pointer */
char buff[4*sizeof(void *) + 8]; /* should be enough space for a '%p' */
int l = (buff, sizeof(buff), "%p", va_arg(argp, void *));
(L, buff, l);
case 'U': {
/* an 'int' as a UTF-8 sequence */
char buff[];
int l = (buff, (long, va_arg(argp, long)));
(L, buff +
case '%': {
(L, "%", 1);
default: {
(L, "invalid option '%%%c' to ''",
*(e + 1));
fmt = e+2;
(L, fmt, strlen(fmt));
if (n & 0) (L, n + 1);
return (L-&top - 1);
const char * ( *L, const char *fmt, ...) {
const char *
va_start(argp, fmt);
msg = (L, fmt, argp);
va_end(argp);
/* number of chars of a literal string without the ending \0 */
#define (x)
(sizeof(x)/sizeof(char) - 1)
"[string \""
#define (a,b,l)
( memcpy(a,b,(l) * sizeof(char)), a += (l) )
(char *out, const char *source, size_t bufflen) {
size_t l = strlen(source);
if (*source == '=') {
/* 'literal' source */
if (l &= bufflen)
/* small enough? */
memcpy(out, source + 1, l * sizeof(char));
/* truncate it */
(out, source + 1, bufflen - 1);
*out = '\0';
else if (*source == '@') {
/* file name */
if (l &= bufflen)
/* small enough? */
memcpy(out, source + 1, l * sizeof(char));
/* add '...' before rest of name */
(out, , ());
bufflen -= ();
memcpy(out, source + 1 + l - bufflen, bufflen * sizeof(char));
/* format as [string "source"] */
const char *nl = strchr(source, '\n');
/* find first new line (if any) */
(out, , ());
/* add prefix */
bufflen -= (
/* save space for prefix+suffix+'\0' */
if (l & bufflen && nl == NULL) {
/* small one-line source? */
(out, source, l);
/* keep it */
if (nl != NULL) l = nl -
/* stop at first newline */
if (l & bufflen) l =
(out, source, l);
(out, , ());
memcpy(out, , (() + 1) * sizeof(char));c# - Display 1,2,3,4,5,6,8,10,11 as 1-6,8,10-11 - Stack Overflow
Join Stack Overflow to learn, share knowledge, and build your career.
or sign in with
I have this sequence 1,2,3,4,5,6,8,10,11
Expected output is 1-6,8,10-11
This problem is about formatting the sequence in easy readable form
I tried with c# and used many if & else.
Interviewer said, there is some simple algorithm to do this.
I have no idea how to achive this very simple.
Also for 1,2,3 i shown 1-3. They said its wrong!.
Is there any design pattern(interpreter) involved in this logic?
1,768134487
Here is one way of doing it:
int[] numbers = { 1, 2, 3, 4, 5, 6, 8, 10, 11 };
int start,
for (int i = 0; i & numbers.L i++)
start = numbers[i];
while (i & numbers.Length - 1 && numbers[i] + 1 == numbers[i + 1])
end = numbers[i];
if(start == end)
Console.WriteLine(start);
Console.WriteLine(start + " - " + end);
This will display subsequent numbers that grow incrementally as range. Numbers that are not increasing linearly are not written as part of a range.
Here is another version of the first approach, it utilizes the same for loop to iterate on range:
int temp = numbers[0], start,
for (int i = 0; i & numbers.L i++)
if (i & numbers.Length - 1 )
// if subsequent numbers are incremental loop further
if (numbers[i] + 1 == numbers[i + 1])
// if they are not, number at index i + 1 is a new 'start' for the next iteration
temp = numbers[i + 1];
end = numbers[i];
if (start == end)
Console.WriteLine(start);
Console.WriteLine(start + " - " + end);
7,39531627
A simple implementation in C# could look like this:
public string Format(IEnumerable&int& input)
var result = string.E
var previous = -1;
var start = -1;
var first =
foreach(var i in input)
if(start == -1)
else if(previous + 1 != i)
result += FormatRange(start, previous, first);
previous =
if(start != -1)
result += FormatRange(start, previous, first);
public string FormatRange(int start, int end, bool isFirst)
var result = string.E
if(!isFirst)
result += ", ";
if(start == end)
result += string.Format("{0}-{1}", start, end);
This will also output 1-3 for the input 1,2,3, which is perfectly valid. Without a specification what the output should be instead it's impossible to answer that part.
130k30231330
Probably not a suitable answer for an interview question, but using LINQ is another way to solve this.
int[] numbers = { 1, 2, 3, 4, 5, 6, 8, 10, 11 };
var remains = numbers.AsEnumerable();
while (remains.Any())
int first = remains.First();
int last = remains.TakeWhile((x, i) =& x - first == i).Last();
remains = remains.Skip(last - first + 1);
Console.Write(first + (first == last ? "" : "-" + last) + (remains.Any() ? "," : Environment.NewLine));
2,78721729
The following groups consecutive integers, and outputs a string for each group. However, it also allows you to specify the minimum length of group which y anything less will just give you the individual numbers. Thus if you only want to hyphenate groups of 4 or more, you can pass in 4; if you want to hyphenate pairs, you can pass in 2. (I'd want to use 3 myself, but I can't tell what they want.)
It also doesn't keep any collections of numbers as it goes along, because you don't need to.
static IEnumerable&string& Group(IEnumerable&int& input, int minLength)
int currentStart = int.MinV
int currentLength = 0;
foreach (int c in input)
if (currentLength & 0)
if (currentStart + currentLength == c)
currentLength++;
if (currentLength &= minLength)
yield return string.Format("{0}-{1}",
currentStart, currentStart + currentLength - 1);
for (int i = currentS i & currentStart + currentL i++)
yield return i.ToString();
currentStart =
currentLength = 1;
currentStart =
currentLength = 1;
if (currentLength &= minLength)
yield return string.Format("{0}-{1}",
currentStart, currentStart + currentLength + 1);
for (int i = currentS i & currentStart + currentL i++)
yield return i.ToString();
int minCount = 3;
int[] input = new[] { 1, 2, 3, 4, 5, 6, 8, 10, 11 };
Console.WriteLine(String.Join(",", Group(input, minCount)));
36.9k55498
Java code:
int[] arr = {1,2,3,4,5,6,8,10,11};
int start = arr[0], last = arr[0];
String output = "";
for (int i = 1; i &= arr. i++)
if (i == arr.length || arr[i] != last+1)
if (output.length() != 0)
output += ",";
if (start == last)
output += start + "-" +
if (i != arr.length)
start = last = arr[i];
last = arr[i];
System.out.println(output);
42.3k954101
Heres my best attempt. Not clever, but simple enough to satisfy that requirement I believe. I'm still pretty confused as to why "1-3" was wrong though....
var numbers = new int[] { 1, 2, 3, 4, 5, 6, 8, 10, 11, 12 };
var groups = new Dictionary&int, int&();
groups.Add(numbers.First(), numbers.First());
foreach (var num in numbers.Skip(1))
var grp = groups.Last();
if (grp.Value + 1 == num)
groups[grp.Key] =
groups.Add(num, num);
var output = string.Join(",", groups.Select(grp =& (grp.Key == grp.Value) ? grp.Value.ToString() : grp.Key.ToString() + "-" + grp.Value.ToString()));
Note: of course using the dictionary and linq etc is completely unnecessary (and way too specific for an answer requiring an algorithm), but I thought it highlighted the grouping aspect of the problem nicely
This is no valid C# code but to show the Idea.
Sort the list from Min to Max then do this:
For i = Min to Max
if i & MaxFound
int step = 1;
while Found(i + Step)
MaxFound = i + S
if i & MaxFound
Output = (i + "-" + MaxFound);
Output += ", ";
28.6k1979115
Here is one of the approach:
public static void main(String[] args) {
print(1, 2, 3, 4, 5, 7, 9, 10, 12);
public static void print(int ... nums) {
System.out.print(nums[0]);
int idx = 1;
for(int i = 1; i & nums. i++, idx++) {
if(nums[i] - nums[i - 1] != 1) {
if(idx & 1) {
System.out.print(" - " + nums[i - 1]);
System.out.print(", " + nums[i]);
if(idx & 1)
System.out.println(" - " + nums[nums.length - 1]);
Here's a Haskell version:
import Data.List
parseRange [] = ""
parseRange n =
let range = takeWhile (\x -& isInfixOf [x,x+1] n) n
in if not (null range)
then show (head range) ++ "-" ++ show (last range + 1)
++ (if length (tail n) & 1 then "," else "")
++ parseRange (drop (length range + 1) n)
else show (head n) ++ (if null (tail n) then "" else ",")
++ parseRange (drop 1 n)
*Main& parseRange [1,2,3,4,5,6,8,10,11]
"1-6,8,10-11"
10.4k21236
And a way to do it with fold in F# - just for fun.
let parseRange numbers =
|& Seq.fold
(fun list n -&
match list with
|(a,b) :: tail when b+1 = n -& (a, n) :: tail
|_ -& (n,n) :: list) []
|& List.rev
|& Seq.map (fun (a,b) -& if a = b then sprintf "%i" a else sprintf "%i-%i" a b)
|& String.concat ","
Your Answer
Sign up or
Sign up using Google
Sign up using Facebook
Post as a guest
Post as a guest
By posting your answer, you agree to the
Not the answer you're looking for?
Browse other questions tagged
Stack Overflow works best with JavaScript enabled1、以下对二维数组 a 的正确说明是(c)。
int a[3][] float a(3,4)
double a[1][4]
float a(3)(4)2、判断字符串a是否大于b,应当使用( d) if (a&b) if (strcmp(a,b)) if (strcmp(b,a)&0)
if (strcmp(a,b)&0)3、有以下程序1234
main(){ int a=666,b=888;
printf("%d\n",a,b);}程序运行后的输出结果是(
b)。 错误信息 666 888 666,8883、下列选项中,不能用作标识符的是(
d)。 1234 _1_2 int2 2int
标识符以下划线和字母开头
4、在 C++ 中,用于实现动态多态性的是( d)。 内联函数 重载函数 模板函数 虚函数5、下列标识符错误的是(
) xly _123 2ab _ab6、以下不符合 C 语言语法的赋值语句是(a)。 a=1,b=2 ++j; a=b=5; y=(a=3,6*5);7、以下对C语言函数的描述中,正确的是(a)。
C 程序必须由一个或一个以上的函数组成 C 函数既可以嵌套定义又可以递归调用 函数必须有返回值,否则不能使用函数 【void】 C 程序中有调用关系的所有函数必须放在同一个程序文件中
函数不可以嵌套定义
8、设 x,y,t 均为 int 型变量,执行下列语句后,y的值为(c)。x=y=3; t=++x||++y; 不确定 4 3 19、下列程序段,循环体执行次数是:d123
y = 2;while (y &= 8)
2 16 4 310、用变量a给出下面的定义:一个有10个指针的数组,该指针指向一个函数,该函数有一个整形参数并返回一个整型数 int a[10]; int (a)[10]; int (*a)(int);
int (*a[10])(int);11、下面有关java和c++的描述,错误的是? java是一次编写多处运行,c++是一次编写多处编译 c++和java支持多继承 Java不支持操作符重载,操作符重载被认为是c++的突出特征 java没有函数指针机制,c++支持函数指针
12、不能把字符串"HELLO!"赋给数组b的语句是(b) char b[10]={'H','E','L','L','O','!','\0'}; char b[10];b="HELLO!"; char b[10];strcpy(b,"HELLO!"); char b[10]="HELLO!";13、*p++ 自增p 还是 p 所指向的变量?a 自增p 自增p所指向的变量 和机器相关14、下面程序会输出什么:b12345678910111213
static int a=1;void fun1(void){
}void fun2(void){
}void fun3(void){
static int a=4;
}int main(int argc,char args){
printf(“%d”,a);
printf(“%d”,a);
printf(“%d”,a);
printf(“%d”,a); } 1 2 3 4 1 2 2 2 1 2 2 4 1 1 1 415、已知一运行正常的程序中有这样两个语句:int p1,p2=&a; p1=b; 由此可知,变量a和b的类型分别是(a)。 int和int int和int int和int int和int16、c++中,声明const int i,是在哪个阶段做到 i只可读的(a) 编译 链接 运行 以上都不对17、以下程序的运行结果是(b)int main(void){printf("%s , %5.3s\n","computer","computer");return 0;} computer , puter computer , com computer , computer computer , compu.ter18、运行下面这段C语言程序之后,输出在屏幕上的结果是:123456789101112131415161718
void foobar(int a, int b, int c)[d]{
int p = &a;
b =} int main(){
int a = 1;
int b = 2;
int c = 3;
int p = &c;
foobar(a, &b, &p);
printf("a=%d, b=%d, c=%d, p=%d\n", a, b, c, p);
return (0);} a=1, b=2, c=3, p=2 a=101, b=2, c=3, p=2 a=101, b=101, c=2, p=3 a=1, b=101, c=2, p=3
19、下列程序的运行结果是3,5,请为横线处选择合适的程序( )12345678910111213
#include&stdio.h& struct S {
char c[10]; } main() {
struct S a[3]={{3,"abc"},{5,"def"},{7,"ghi"}};
printf("%d,",(p).n);
printf("%d\n",_(*(p+1))); }
20、在 C 语言中下面那个语句的结果是 1 ?[b] main 函数正常结束的返回值 return 7&1; char *p="hello"; return p == "hello"; 上面都不对
21、下列给定程序中,函数fun的功能是:把形参a所指数组中的奇数按原顺序依次存放到a[0]、a[1]、a[2]…中,把偶数从数组中删除,奇数个数通过函数值返回。 例如,若a所指数组中的数据最初排列为:9,1,4,2,3,6,5,8,7,删除偶数后,a所指数组中的数据为:9,1,3,5,7,返回值为5。函数原型:int cnt_array_oushu(int *a, int len)
int cnt_array_oushu(int *a, int len){int num = 0 ;int i = 0 , j = 0;
for( i=0 ; i& i++ )
if( a[i]%2 == 1 )
a[j] = a[i];
}int main (void){char arr[]={9,1,4,2,3,6,5,8,7}int ret =cnt_array_oushu(arr,9)printf(“%d”ret);
声明:本文内容由互联网用户自发贡献自行上传,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任。如果您发现有涉嫌版权的内容,欢迎发送邮件至: 进行举报,并提供相关证据,工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。}

我要回帖

更多关于 abb中断程序intnum 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信