第1~4題:
#include <stdio.h>
#include <stdlib.h>
float cm2feet(float cm);
int age(int myage);
int main()
{
int myage;
float kg,n,cm,feet;
printf("張龜雅\n輸入公斤重:");
scanf("%f",&kg);
n=kg*9.81;
printf("我的體重%f牛頓\n",n);
printf("輸入公分:");
scanf("%f",&cm);
feet=cm2feet(cm);
printf("我的身高%f英呎\n",feet);
printf("輸入年齡:");
scanf("%d",&myage);
age(myage);
return 0;
}
float cm2feet(float cm)
{
float feet;
feet=cm*0.0328;
return feet;
}
int age(int myage)
{
int i,sum;
sum=myage;
for(i=1;i<=10;i++)
{
sum+=1;
printf("%d年後我%d歲\n",i,sum);
}
return 0;
}
#include <stdio.h>
#include <stdlib.h>
void one(int x);
void two(int x);
int main()
{
int x,y,i;
printf("請輸入x:");
scanf("%d",&x);
printf("請輸入y:");
scanf("%d",&y);
one(x);
for(i=3;i<=y;i++)
{
two(x);
}
one(x);
return 0;
}
void one(int x)
{
int i;
for(i=1;i<=x;i++)
{
printf("囧");
}
printf("\n");
}
void two(int x)
{
int i;
for(i=1;i<=x/2;i++)
{
printf(" ");
}
printf("囧\n");
}
第6題:
#include <stdio.h>
#include <stdlib.h>
int main()
{
int i,j,allday,day;
allday=31;
j=1;
day=1;
printf(" 日 一 二 三 四 五 六\n");
for(i=1;i<=allday+2;i++)
{
if(i<3)
{
printf(" ");
j++;
}
else
{
if(j<7)
{
printf("%3d",day);
j++;
}
else
{
printf("%3d\n",day);
j=1;
}
day++;
}
}
return 0;
}
第7~8題:
#include <stdio.h>
#include <stdlib.h>
#include <gd/gd.h>
#include <gd/gdfontg.h>
#include <gd/gdfontt.h>
#include <gd/gdfonts.h>
#include <gd/gdfontmb.h>
#include <gd/gdfontl.h>
#include <math.h>
void star(int x,int y, int radius);
int red,orange,yellow,green,blue,cyan,purple,black,white;
float degree = 3.14159/180.;
gdImagePtr im;
FILE *in;
int main(int argc, char *argv[])
{
int j,i;
float x,y;
//----------------------------------
char file[40];
char end[40] = ".htm";
//----------------------------------
im = im = gdImageCreate(500, 500);
green=gdImageColorAllocate(im,128,255,0);
red=gdImageColorAllocate(im,255,0,0);
white = gdImageColorAllocate(im, 255, 255, 255);
orange=gdImageColorAllocate(im,255,128,0);
yellow=gdImageColorAllocate(im,255,255,0);
blue=gdImageColorAllocate(im,0,0,255);
cyan=gdImageColorAllocate(im,0,255,255);
purple=gdImageColorAllocate(im,255,0,255);
black = gdImageColorAllocate(im, 0, 0, 0);
//----------------------------------------------------------
FILE *outfile;
printf ( "Please input a file name: " );
scanf ( "%s" , file );
strcat ( file , end );
outfile = fopen ( file , "wb" );
fprintf(outfile, "<img src=gdimage.png><br>\n");
for(i=1;i<=20;i++)
{
x=250+100*sin(i*18*degree);
y=250+100*cos(i*18*degree);
fprintf(outfile, "Coordinates %d (%f,%f)<br>\n",i,x,y);
star(x,y,30);
}
fclose(outfile);
//----------------------------------------------------------
in = fopen("gdimage.png", "wb");
if (!in) {
printf("cannot open < gdimage.png for writing\n");
return 1;
}
gdImagePng(im, in);
fclose(in);
gdImageDestroy(im);
return 0;
}
void star(int x,int y, int radius)
{
gdImageFilledEllipse(im, x, y, radius, radius, red);
}
沒有留言:
張貼留言