#include <stdlib.h>
int sum( int x[], int n )
{
int i, s=0
for ( i=0i<ni++ )
s = s + x[i]
return s
}
void main()
{
int i, i1, i2, result
int x[10]
for ( i=0i<10i++ )
scanf( "%d", &x[i] )
scanf( "%d%d", &i1, &i2 )
result = sum( x+i1,i2-i1+1)
printf( "Sum=%d\n", result )
return 0
}
#include "stdio.h"main()
{ int sum(int)
int i
scanf("%d",&i)
if(i<=0) printf("Input error!")
else printf("sum=%d",sum(i))
}
int sum(int n)
{
if(n==1) return 1 //(1)
else return n+sum(n-1)//(2)
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)