1.编写一个函数的累计和,用静态变量,在主函数中调用此函数分别求1~40的累加和。
#include<stdio.h>
int Sum(int n)
{
static int total = 0;
int i=1;
for(; i<=n; i++)
{
total += i;
}
return total;
}
int main(){
int i,s;
scanf("%d",&i);
s=Sum(i);
printf("%d",s);
}
#include <stdio.h>
#define MAX(a, b, c) (a > b ? a : b) > c ? (a > b ? a : b) : c
int main(int argc, char* argv[])
{
int a = 2;
int b = 1;
int c = 3;
int max = 0;
max = MAX (a, b, c);
printf ("%d\n", max);
return 0;
}
#include <stdio.h>
#define SWAP(a, b,t) t=a,a=b,b=t
int main(int argc, char* argv[])
{
int a = 2;
int b = 1;
int m;
int swap;
swap = SWAP(a,b,m);
printf ("%d %d\n", a,b);
return 0;
}
#include <stdio.h>
#define fun(t) t%5
int main(int argc, char* argv[])
{
int a;
scanf("%d",&a);
if(fun(a)==0)
printf ("能被整除");
else
printf("不能整除");
return 0;
}
#include <stdio.h>
#define MYALPHA(C) (((C>='A'&&C<='Z')||(C>='a'&&C<='z'))?1:0)
main()
{ char a;
int b;
scanf("%c",&a);
b=MYALPHA(a);
printf("b=%d\n",b);
}