在線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;
}