1、void main()
{
int n,value;
int i,count=0;
float average = 0;
long int sum = 0;
scanf("%d",&n);
for(i = 0; i < n; i++)
{
scanf("%d",&value);
if(value%2 == 0)
{
sum+=value;
count++;
}
}
average = sum / (float)count;
printf("the average is %f\n",average);
}
2、
#include "stdio.h"
void main()
{
char ch;
int zm = 0, sz = 0;
ch = getchar();
while(ch != '*')
{
if((ch >= 'A' && ch <= 'Z') || (ch >= 'a' && ch < 'z') )
zm++;
if(ch >= '0' && ch <= '9')
sz++;
ch = getchar();
}
printf("zm = %d ; sz = %d\n",zm,sz);
}
3、
void main()
{
long i_value;
int sum = 0;
int temp = 0;
scanf("%ld",&i_value);
if(i_value < 0) {printf("you input the int is error!\n");return;}
for(;;)
{
temp = i_value%10;
i_value = i_value/10;
sum+=temp;
printf("%d+",temp);
if(i_value == 0)break;
}
printf("\b=%d\n",sum);
}
4、
#include "stdio.h"
void main()
{
char ch;
ch = getchar();
while(ch != '.')
{
if((ch >= 'A' && ch <= 'Z'))
{
ch = ch + 32;
putchar(ch);
}
else if((ch >= 'a' && ch < 'z') )
{
ch = ch - 32;
putchar(ch);
}
else
{
putchar(ch);
}
ch = getchar();
}
printf("\n");
}
5、
void main()
{
float sum = 200;
int count = 0;
for(;;)
{
sum = sum+ sum*0.045;
count++;
if(sum > 500)break;
}
printf("the %d years later complete!\n",count);
}
6、
void main()
{
int i,temp=0,bit=0;
for(i = 1 ; i <= 999; i++)
{
if(i%3 == 0)
{
temp = i;
for(;temp != 0;)
{
bit = temp%10;
if(bit == 5){printf("%d,",i);break;}
temp = temp/10;
}
}
}
printf("\b \n");
}
7、
#include <stdio.h>
int main(void)
{
int steps = 29, i = 1;
while ( steps % 7 )
{
steps = (30 * ++i) - 1;
}
printf("Total steps: %d\n", steps);
return 0;
}
8、
main()
{
int i,j,k,n;
printf("the narcissus number is:\n");
for(n=100;n<1000;n++)
{i=n/100;
j=n/10-i*10;
k=n%10;
if(i*i*i+j*j*j+k*k*k==n) printf("%d\n",n);
}
}
9、
main()
{ float i,j,temp,n,sum;
int t;
i=2;j=1;sum=0;
scanf("%d",&t);
for(n=1;n<=t;n++)
{sum=sum+i/j;
temp=i;i=i+j;j=temp;
}
printf("2/1+3/2+5/3+8/5+13/8+...=%f\n",sum);
}
10、
void main()
{
int nWidth,a,b;
scanf("%d",&nWidth);
for(a=(nWidth%2);a<=nWidth;a+=2)
{
for(b=0;b<nWidth;b++)
{
char chOut =' ';
int nleft =(nWidth -a)/2;
int nright = (nWidth+a)/2;
if(b>=nleft&&b<nright)
{
chOut ='*';
}
printf("%c",chOut);
}
printf("\n");
}
}
11、
void main()
{
int i=1,j=1;
for(i=1;i<=9;i++)
{
for(j=1;j<=i;j++)
printf("%d*%d=%d",i,j,i*j);
printf("\n")
}
}
12、
#include "stdio.h"
void main()
{
char c;
//count1是正數(shù)的個數(shù)
//count2是負數(shù)的個數(shù)
int count1=0,count2=0;
//sum1是正數(shù)之和
//sum2是負數(shù)之和
int sum1=0,sum2=0;
int flage = 0;
c=getchar();
while(c != '*')
{
if(c == '-')flage = 1;
if(flage == 0)
{sum1+=(c-48);count1++;}
else
{if(c != '-'){sum2-=(c-48);flage=0;count2++;}}
c = getchar();
}
printf("%d,%d\n",count1,count2);
printf("%f,%f\n",sum1/count1,sum2/count2);
}
13、
void main()
{
int i,j;
int s = 0;
for(i = 100 ; i <= 999; i++)
{
s = 0;
for(j=1; j < i-1 ; j++)
{
if( i%j == 0 ) s = s + j;
}
if(s == i)printf("%5d",i);
}
}
14、
#include <stdio.h>
#include <math.h>
void main()
{
int n;
long k = 1;
float e = 1;
n = 1;
clrscr();
while ( fabs(1.0/k) >= 0.000001)
{
n++;
e = e+ 1.0/k;
k = k * n;
}
printf("%f\n",e);
}
15、
#include "math.h"
main()
{float x0,x1,x2,f0,f1,f2;
x1=-10;
f1=2*x1*x1*x1-4*x1*x1+3*x1;
x2=10;
f2=2*x2*x2*x2-4*x2*x2+3*x2;
do
{ x0=(x1+x2)/2;
f0=2*x0*x0*x0-4*x0*x0+3*x0;
if((f0*f1)<0)
{x2=x0; f2=f0;}
else
{x1=x0; f1=f0;}
}
while(fabs(f0)>1e-6);
printf("______2*x*x*x-4*x*x+3*x=0______\n");
printf("the root is %f\n",x0);
}