Ⅰ c语言分数相加求和
#include<stdio.h>
#include<math.h>
intfenzi(inti)//分子就是137132131他们之间的差是246810
{
if(i<=0)
return1;
returni*2+fenzi(i-1);
}
intfenmu(inti)//分母就是2的i+1次方
{
return(int)pow(2,i+1);
}
intmain()
{
doublesum=0;
intflag,x,y;
for(inti=0;i<20;i++)
{
x=fenzi(i);
y=fenmu(i);
flag=pow(-1,i);//+-随i是奇偶变换
printf("%c%d/%d",flag>0?'+':'-',x,y);
sum+=flag*x*1.0/y;
}
printf("=%lf ",sum);
return0;
}
Ⅱ 在c语言中用调用函数求三个同学三科的总成绩,怎么编程
#include<stdio.h>
#defineN100
/*定义学生结构体*/
structStudent
{
intID;
charName[20];
floatMark1;
floatMark2;
floatMark3;
floatSum;
};
/*声明学生数组及学生数量*/
structStudentstudents[N];
//intnum=0;
/*求总分*/
floatSums(structStudentstu)
{
returnstu.Mark1+stu.Mark2+stu.Mark3;
}
/*输入学生信息*/
intStudent_Input(){
intnum=0;
while(1){
//printf("请输入学号:");
students[num].ID=num+1;//可以自行将学号改为手工输入
printf("请输入姓名:");
scanf("%s",&students[num].Name);
getchar();
printf("请输入成绩1:");
scanf("%f",&students[num].Mark1);
getchar();
printf("请输入成绩2:");
scanf("%f",&students[num].Mark2);
printf("请输入成绩3:");
scanf("%f",&students[num].Mark3);
getchar();
students[num].Sum=Sums(students[num]);
num++;
printf("是否继续?(y/n)");//继续输入数据?
if(getchar()=='n'){
break;
}
}
returnnum;
}
/*输出学生信息*/
voidStudent_Display(intn)
{
inti;
printf("%10s%10s%8s%8s%8s%8s ","学号","姓名","成绩","成绩","成绩","总成线");
printf("--------------------------------------------------------- ");
for(i=0;i<n;i++)
{
printf("%10d%10s%8.2f%8.2f%8.2f%8.2f ",students[i].ID,students[i].Name,
students[i].Mark1,students[i].Mark2,students[i].Mark3,students[i].Sum);
}
}
/*主程序*/
intmain(){
intn=0;
n=Student_Input();
Student_Display(n);
return0;
}
Ⅲ C语言编程题:求输入的10个学生的成绩之和(循环结构算法)
#include<stdio.h>
int main()
{
double score,sum = 0;
printf("请输入10个学生的分数:\n");
for(int i = 0;i < 10;i++)
{
scanf("%lf",&score);
sum += score;
}
printf("成绩之和为: %lf\n",sum);
return 0;
}
Ⅳ 用c语言编程如何实现求和的程序代码
1、首先把头文件,main函数写好#include<stdio.h> main(),如下图所示。
Ⅳ c语言编写三个函数分别求某学生三门课程总成绩和平均成绩和及格率
struct Student{
char name[30];
double C; // 语文成绩
double M; // 数学成绩
double E; // 英语成绩
};
typedef struct Student Student;
/* 学生的总成绩 */
void Total(Student* st){
printf("总成绩: %.2f\n", st->C+st->M+st->E);
}
void Avg(Student* st){
double x = (st->C+st->E+st->M)/3.0;
printf("平均分: %.2f\n", x);
}
void Pass(Student* st){
double x=0;
if(st->C >= 60){
x++;
}
if(st->E >=60){
x++;
}
if(st->M >= 60){
x++;
}
printf("及格率为: %.2f\n", x/3.0);
}
int main(){
Student st;
strcpy(st.name, "xiaoming");
st.C = 70;
st.E = 59;
st.M = 100;
Total(&st);
Avg(&st);
Pass(&st);
while(1);
return 0;
}