求解 C语言编程1~6

1. 读取用户输入的浮点数,分别按照如下格式输出:
1) 输出科学计数法表示的数值
2) 输出整数部分和小数部分长度为用户指定值的数值
Sample input
3.14 3 5
Sample output
*
*3.140000e+000*
* 3.14000*
2. 读取用户输入的第三个整数,分别按照如下格式输出:
1) 输出长度是20位,右对齐,不足20位左侧用0补位
2) 输出长度和至少输出位数为用户指定值,
Sample input
5 10 5
Sample output
*00000000000000000005*
* 00005*
3. 读取用户输入的三个整数,输入时用中文逗号分隔,输出三个整数的和
Sample input
1,2,3
Sample output
6
4. 读取用户输入的字符串,输出该字符串的长度,并输出该字符串内容,输出格式一起总长度为该字符串长度+3
Sample input
hello
Sample output
* hello*
5. 读取用户输入的字符串,截取该字符串中指定的前n个字符输出,输出总长度为m,m和n均为用户指定值
Sample input
Hellomyworld 5,10
Sample output
* Hello*
6. 编写程序计算n的阶乘
5!=5*4*3*2*1
Sample input
5
Sample output
120
麻烦用C语言编写

5部分程序写在一个程序里了。
#include<stdio.h>
int main()
{
//part1:
{
double x;
int m1,m2;
char fm[30];
printf("input 3.14 3 5\n");
scanf("%lf %d %d", &x, &m1, &m2);
sprintf(fm,"%%-%d.%df\n",m1+m2+1,m2);
printf("%e\n",x);
printf(fm,x);
};
//part2:
{
int x3;
printf("\ninput 5 10 5\n");
scanf("%*d %*d %d",&x3);
printf("%020d\n",x3);
printf("%05d\n\n",x3);
}
//part3:
{
int a,b,c;
printf("input 1,2,3\n");
scanf("%d,%d,%d",&a,&b,&c);
printf("%d\n\n",a+b+c);
}
fflush(stdin);
//part4:
{
char s[60];
int L;
char fm[30];
printf("input one line string: hello\n");
fgets(s,59,stdin);
L=strlen(s);
printf("string length is %d\n",L);
sprintf(fm,"%%%ds\n",L+3);
printf("string is:\n");
printf(fm,s);
printf("\n\n");
}
fflush(stdin);
{
char s[60],fm[50];
int n,m;
printf("input Hellomyworld 5,10\n");
scanf("%s %d,%d",s,&n,&m);
sprintf(fm,"%%%ds\n",m);
s[n]='\0';
printf(fm,s);
};

//part6:
{
int n,i;
double r=1;
printf("input 5\n");
scanf("%d",&n);
for (i=n;i>1;i--) r=r*i;
printf("%g\n",r);
}
return 0;
}追问

(自然没有星号,)要求是这样:

3.143 5

(空格)

3.140000e+000

3.14000

温馨提示:答案为网友推荐,仅供参考

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网