1. c语言 这个函数怎么写啊
2.任意输入一个三位整数,然后逆序输出。如输入为123,则输出为321。
百位:number/100
十位:(number/10)%10
个位:number%10
#include<conio.h>
#include<stdio.h>
void main()
{
int number;
printf("input number(100~999):");
scanf("%d",&number);
if(number>=100&&number<=999)
printf("%d%d%d",number%10,(number/10)%10,number/100);
else printf("Error Input(100~999)\n");
getch();
}
2. c语言的输出函数怎么写
#include /** 输出函数 printf("你要输出的内容"); %d - int %ld - long int %c - char %f - float %u – 无符号数 %hd – 短整型 %lf –double %x – 十六进制输出int 或者long int 或者short int %o - 八进制输出 %s – 字符串 ? printf("你要输出的内容对应的占位符"); 在C语言中,默认保留小数点后六位 要想保留对应的位数,就需要在百分号后边加上“.数字” 十进制:12345678 二进制:101111000110000101001110 110000101001110 不同的类型,要用不同的占位去输出,否则精度丢失。
*/ main(){ char c = 'A'; int i = 12345678; long l = 123456789; float f = 3.1415; double d = 3.1415926535; printf("c==%c\n",c); printf("i==%d\n",i); //101111000110000101001110 printf("l==%ld\n",l); printf("f==%.4f\n",f); printf("d==%.10lf\n",d); printf("i==%hd\n",i); // 110000101001110 //C语言的数组的括号不能写在变量左边 char cArray[] = {'A','B'}; printf("cArray的内存地址:%#x\n",&cArray); char* text = "I love you!"; printf("text内容==%s\n",text); system("pause");。
3. C语言,C++,怎么写主函数
主函数的作用是程序的入口。就是说只要程序一开始,第一句执行的就是主函数中的第一条语句。
编写规律:主函数一般是调用函数和简单的逻辑判断,代码长度不宜超过80行。
技巧:将功能尽量整合到一个子函数,采用调用。例如,长方形体积是一个子函数一样。
举例如下:
#include<stdio.h>
double V(double a, double b, double c); //声明子函数
void main() //主函数
{double a,b,c; //长 宽 高
double v;
scanf("%lf%lf%lf",&a,&b,&c); //输入长 宽 高
v = V(a,b,c); //体积子函数
printf("%lf",v);
}
double V(double a, double b, double c)
{
double v;
v = a*b*c;
return v; //返回给主函数的值
}
4. 用C写一个函数
int strstr( char * str1, const char * str2 ){ char *cp = (char *) str1; char *s1, *s2; if ( !*str2 ) return 0; while (*cp) { s1 = cp; s2 = (char *) str2; while ( *s1 && *s2 && !(*s1-*s2) ) s1++, s2++; if (!*s2) return 1; cp++; } return 0;}。
5. c语言输入函数怎么写在一起啊
第一个函数要输入的:
float a,b,c;scanf("%f%f",&a,&b);
第二个函数要输入的:
int d,e,f;scanf("%d%d",&d,&e);
和在一起:
float a,b,c;
int d,e,f;
scanf("%f%f%f%d%d%d", &a,&b,&c,&d,&e,&f);
6. C语言,写一个函数
第一题:(这是没有用函数的)
#include<stdio.h>
void main()
{
int n;
scanf("%x",&n);
printf("%d",n);
}
方法二
#include<stdio.h>
#include<string.h>
void main()
{
char a[80];
gets(a);
printf("%d\n",fun(a));
}
int fun(char a[])
{
int i,n=0,t=1;
for(i=strlen(a)-1;i>=0;i--,t*=16)
if(a[i]>='a'&&a[i]<='f')
n+=t*(a[i]-'a'+10);
else if(a[i]>='A'&&a[i]<='F')
n+=t*(a[i]-'A'+10);
else
n+=t*(a[i]-'0');
return n;
}
第二题:
#include<stdio.h>
int i=0;
char a[80];
void main()
{
int n;
scanf("%d",&n);
fun(n);
puts(a);
}
int fun(int n)
{
if(n!=0)
fun(n/10);
if(n!=0)
return a[i++]=n%10+'0';
}