在线c语言编程
#include<stdio.h>
#define Pi 3.1415926
int main()
{
float r,h,s1,s2,v;
scanf("%f%f",&r,&h);
s1=Pi*r*r;
s2=2*s1+2*Pi*r*h;
v=s1*h;
printf("圆柱底面积=%.2f ",s1);
printf("圆柱表面积=%.2f ",s2);
printf("圆柱体积=%.2f ",v);
getch();
}
‘贰’ 求在线C语言编程
//从键盘上输入三个整数.由小到大的顺序输出;
#include<stdio.h>
#include<stdlib.h> //这里我采用了快速排序这一函数,需要在开头声明的库函数;
int compare (const void *elem1,const void *elem2) //引入比较函数
{
int *p1,*p2;
p1=(int *)elem1; //强制类型转换;
p2=(int *)elem2; //强制类型转换;
return (* p1)-(* p2); //这个函数返回值的特点:如果返回值是负数,则p1排在p2前面;
}
main()
{
int i;
int a[4];
for (i=0;i<3;i++)
scanf ("%d",&a[i]);
qsort (a,3,sizeof(int),compare);
for (i=0;i<3;i++)
printf("%d ",a[i]);
getchar(); //在Dev-C++中,为了看最后结果;
getchar();
}
//其实这个快速排序,可以很方便的一次性快排许多整数,非常cool!!
//打印出100~999之间的所有水仙花数
#include<stdio.h>
main()
{
int i,j,k,l; //j表示i的百位;k表示i的十位;l表示i的个位;
for (i=100;i<=999;i++)
{
j=i/100; //利用int类型自动保留整数,舍去小数的特点;
k=(i-100*j)/10;
l=i-j*100-k*10;
if (i==j*j*j+k*k*k+l*l*l)
printf ("%d\n",i);
}
getchar();
getchar();
}
//利用循环解构输出9.9乘法表
#include<stdio.h>
main()
{
int i,j;
for (i=1;i<=9;i++)
{
for (j=1;j<=i;j++)
{
printf ("%d*%d=%2d ",j,i,j*i);
}
printf ("\n");
}
getchar();
getchar();
}
//希望对你有帮助 ~~~
‘叁’ c语言编程在线急(用标签里的代码模板)
#include"stdio.h"
voidoutput(inta[],intn);
main()
{
intn,i,j,x,pos;
intc=0;//c表示有效的数据个数
inta[20];
scanf("%d",&n);
for(i=0;i<n;i++)//插入n个数据
{
scanf("%d",&x);
//查找插入的位置pos,并且向后移动数据
for(pos=c;pos>0;pos--)
if(x<a[pos-1])
a[pos]=a[pos-1];
else
break;
a[pos]=x;//在pos位置插入数据
c++;//个数加1
}
output(a,n);
return0;
}
voidoutput(inta[],intn)
{
inti;
for(i=0;i<n;i++)
printf("%d",a[i]);
printf(" ");
}
‘肆’ C语言编程 在线等
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#defineN100
structscore
{
floatmath;
floatenglish;
floatcomputer;
};
structstudent
{
intnumber;
charname[20];
structscoresco;
floataverage;
};
structstudentstu[N];
floatinput_score(int);//计算学生平均成绩
voidprint_student2(void);//显示表头
voidprint_student3(int);//显示学生信息
voidprint_student1(int);//显示全部学生资料
voidprint_student1(inta)//显示全部学生资料
{
printf("本班所有学生具体信息如下 ");
print_student2();
for(inti=0;i<a;i++)
{
print_student3(i);
}
}
voidprint_student3(inta)//显示学生信息
{
printf("%8d%12s%14.2f%14.2f%14.2f%14.2f ",stu[a].number,stu[a].name,stu[a].sco.math,stu[a].sco.english,stu[a].sco.computer,stu[a].average);
}
voidprint_student2(void)//显示表头
{
printf("学号姓名数学成绩英语成绩计算机成绩平均成绩 ");
}
voidinput_student1(inta)//输入学生信息
{
printf("学号:");
scanf("%d",&stu[a].number);
getchar();
printf("姓名:");
gets(stu[a].name);
printf("数学成绩:");
scanf("%f",&stu[a].sco.math);
printf("英语成绩:");
scanf("%f",&stu[a].sco.english);
printf("计算机成绩:");
scanf("%f",&stu[a].sco.computer);
}
floatinput_score(inta)//计算学生平均成绩
{
return(stu[a].sco.math+stu[a].sco.english+stu[a].sco.computer)/3;
}
//voidmain()
intmain()
//最好是intmain
{
structstudentstu[N];
input_score(student);
print_student2(student);
print_student3(student);
print_student1(student);
print_student1(student);
return0;
//加上返回值
}
‘伍’ C语言编程在线等
main()
{
float a,b;
char ch;
scanf("%f%c%f",&a,&ch,&b);
switch(ch){
case '+':{printf("=%f",a+b);break;}
case '-':{printf("=%f",a-b);break;}
case '*':{printf("=%f",a*b);break;}
case '/':{printf("=%f",a/b);break;}
default:break;
}
getch();
}
‘陆’ 在线c语言编程高手
#include <stdio.h>
int main()
{
float price=-1, last_price=-1;
int cnt = 0, total = 0;
int increase_flag = 0;
while(~scanf("%f", &price))
{
total++;
printf("%d\t%7.3f", total, price);
if(cnt > 2)
printf("\t%s", increase_flag ? "sell" : "buy");
printf("\n");
if(last_price != -1)
{
if(price > last_price)
{
if(increase_flag) cnt ++;
else increase_flag = 1, cnt = 1;
}
else if(price < last_price)
{
if(!increase_flag) cnt ++;
else increase_flag = 0, cnt = 1;
}
else cnt++;
}
last_price = price;
}
return 0;
}
part3的
#include <stdio.h>
int main()
{
float price=-1, last_price=-1;
int cnt = 0, total = 0;
int increase_flag = 0;
float cash = 10000, shares = 0;
printf("period price cash shares value\n");
printf("-----------------------------------------------\n");
while(~scanf("%f", &price))
{
total++;
if(cnt > 2)
{
if(increase_flag)
{
if(shares != 0)
{
cash = shares * price;
shares = 0;
}
}
else
{
if(cash != 0)
{
shares = cash / price;
cash = 0;
}
}
}
printf(" %3d \t%7.3f\t%10.2f\t%7.2f\t%10.2f\n", total, price, cash, shares, cash+shares * price);
if(last_price != -1)
{
if(price > last_price)
{
if(increase_flag) cnt ++;
else increase_flag = 1, cnt = 1;
}
else if(price < last_price)
{
if(!increase_flag) cnt ++;
else increase_flag = 0, cnt = 1;
}
else cnt++;
}
last_price = price;
}
return 0;
}
‘柒’ C语言编程(在线等)
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
int main(int argc, char *argv[])
{
char p[] = "ABCD1234efgh";
char *head = p;//指向字符串头
char *rear = p+strlen(p);//指向字符串尾的有效字符
rear--;//如果不-就指向\0了
char tmp;
while ( head<=rear )
{
tmp = *head;
*head = *rear;
*rear = tmp;
head++;
rear--;
}
printf("%s",p);
return 0;
}