c语言程序设计,共3提
发布网友
发布时间:2022-05-19 05:15
我来回答
共1个回答
热心网友
时间:2023-09-04 06:23
1、用条件表达式(?:)
main()
{
int a,b,c,temp,max;
printf("input three interger: ");
scanf("%d, %d, %d",&a,&b,&c);
temp=(a>b)?a:b;
max=(temp>c)?temp:c;
printf("max=%d\n",max);
}
1、用if语句
main()
{
int a,b,c;
printf("input three integer: ");
scanf("%d,%d,%d",&a,&b,&c);
if(a<b)
if(b<c)
printf("max=%d\n",c);
else
printf("max=%d\n",b);
else if(a<c)
printf("max=%d\n",c);
else
printf("max=%d\n",a);
}
2、
main()
{int n,i=1;long sum=0,s=1;
while(i<=10) {s=s*i;sum=sum+s;i++;}
printf("sum=%ld\n",sum);
}
3、
#include"stdio.h"
main()
{char c;
int n=0;
int check(char c); //函数声明
while((c=getchar())!='\n')
n=check(c); //函数调用
printf("the number is:%d\n",n);
}
int check (char s) //函数定义
{
static int i=0;
if(s>=48&&s<=57) i++;
return(i);
}