6.16 编程练习
#include <stdio.h>
#define SIZE 26
int main(void)
{
int i;
char ch[SIZE];
for(i=0;i<SIZE;i++)
{
ch[i]='a'+i;
printf("%c\t",ch[i]);
}
printf("\n");
return 0;
}
#include <stdio.h>
#define SIZE 5
int main(void)
{
unsigned short auto int row;
unsigned short auto int line;
for(row=0;row<SIZE;row++)
{
for(line=0;line<=row;line++)
printf("$");
printf("\n");
}
return 0;
}
#include<stdio.h>
#define SIZE 6
int main(void)
{
unsigned short auto int i,j;
char ch[SIZE];
for(i=0;i<SIZE;i++)
{
for(j=0;j<=i;j++)
{
ch[j]='F'-j;
printf("%c",ch[j]);
}
printf("\n");
}
return 0;
}
#include<stdio.h>
#define SIZE 6
int main(void)
{
unsigned short auto int i,j;
char ch[SIZE],c;
for(i=0,c='A';i<SIZE;i++)
{
for(j=0;j<=i;j++,c++)
{
ch[j]=c;
printf("%c",ch[j]);
}
printf("\n");
}
return 0;
}
#include<stdio.h>
int main(void)
{
printf("Enter number uper is lower:......\b\b\b\b\b\b");
unsigned auto short int up;
unsigned auto short int lo,i;
scanf("%hu%hu",&lo,&up);
i=lo;
while(i<=up)
{
printf("lower:=%hu square==:%hu cube==%hu\n",i,i*i,i*i*i);
i++;
}
return 0;
}
#include<stdio.h>
#include<string.h>
#define SIZE 50
int main(void)
{
char ch[SIZE];
printf("Enter word:......\b\b\b\b\b\b");
scanf("%s",ch);
unsigned auto short int size=strlen(ch);
while(size--)
printf("%c",ch[size]);
printf("\n");
return 0;
}
#include<stdio.h>
int main(void)
{
printf("Enter two doubles:......\b\b\b\b\b\b");
double f1,f2;
while(scanf("%lf%lf",&f1,&f2)==2)
{
printf("%lf\n",(f1-f2)/(f1*f2)),printf("Enter two doubles:......\b\b\b\b\b\b");
}
return 0;
}
#include<stdio.h>
double x(double f1,double f2);
int main(void)
{
printf("Enter two doubles:... ...\b\b\b\b\b\b\b");
double f1,f2;
while(scanf("%lf%lf",&f1,&f2)==2)
{
printf("%lf\n",x(fi,f2)),printf("Enter two doubles:... ...\b\b\b\b\b\b\b");
}
return 0;
}
double x(double f1,double f2)
{
return (f1-f2)/(f1*f2);
}
```
#include<stdio.h>
int main(void)
{
printf("Enter lower and upper integer limits:");
unsigned auto short int u,l,sum=0,x=0;
scanf("%hu%hu",&l,&u);
while(u>l)
{
x=u;
while(x >= l)
{
sum+=x*x;
x--;
}
printf("The sums of the squares from %u to %u is %u\n",l*l,u*u,sum); printf("Enter next set of limits:... ...\b\b\b\b\b\b\b");
scanf("%hu%hu",&l,&u);
}
printf("Done!");
return 0;
}
#include<stdio.h>
#define SIZE 8
int main(void)
{
unsigned auto short int arr[SIZE],index;
for(index=0;index<SIZE;index++)
scanf("%hu",&arr[index]);
for(index=SIZE-1;index>=0;index--)
printf("%hu\t",arr[index]);
printf("\n");
return 0;
}
#include<stdio.h>
int main(void)
{
unsigned auto short int times,index=1;
double f1=1.0,sum=1.0;
printf("Enter times:......\b\b\b\b\b\b");
scanf("%hu",×);
while(times>0)
{
while(index<=times)
{
sum+=f1/index ;
index++;
}
index=1;
while(index<=times)
{
sum+=f1/index;
index+=2;
}
printf("%lf\n",sum);
printf("Enter times:......\b\b\b\b\b\b"),scanf("%hu",×);
}
printf("Done!\n");
return 0;
}
#include<stdio.h>
#define SIZE 8
int main(void)
{
unsigned auto short int arr[SIZE],index,x;
for(index=0,x=1;index<SIZE;index++,x*=2)
arr[index]=x;
index=0;
do
printf("%hu\t",arr[index]);
while(index++<SIZE);
return 0;
}
#include<stdio.h>
#define SIZE 8
int main(void)
{
double f1[SIZE],f2[SIZE];
unsigned auto short int index=0,i=0;
printf("Enter array key\n");
while(index<SIZE)
{
scanf("%lf",&f1[index++]);
printf("%lf\t",f1[index]);
}
printf("\n");
index=0,i=0;
while(i<SIZE)
{
f2[i]=f1[index++]+f2[i-1];
printf("%lf",f2[i++]);
}
printf("\n");
printf("Enter array key\n");
for(index=0,i=0;index<SIZE;index++,i++)
{
scanf("%lf",&f1[index]);
f2[i]=f1[index]+f2[i-1];
printf("%lf\t",f1[index]);
}
printf("\n");
for(index=0;index<SIZE;index++)
printf("%lf\t",f2[index]);
printf("\n");
return 0;
}
#include<stdio.h>
#define SIZE 255
int main(void)
{
unsigned char ch[SIZE],c;
unsigned auto short int index=0;
printf("Enter word\n");
while(index<SIZE)
{
scanf("%c",&c);
ch[index++]=c;
}
index=SIZE-1;
while(index>=0)
printf("%c",ch[index--]);
return 0;
}
#include<stdio.h>
#define M 100
int main(void)
{
float dp=M;
float dr=M;
unsigned auto year=1;
while((dr+=dr*0.05)<=(dp+=M*0.1))
year++;
printf("%.2fdeirdre %u year daphne %.2f \n",dr,year,dp);
return 0;
}
#include<stdio.h>
int main(void)
{
unsigned auto year=1;
double m=100,t=10,r=0.08,s=0.0;
s=m*r+m-t;
while(s>=0.0)
{
printf("year== %hu s==%.2lf\n",year,s);
s+=m*r-t;
year++;
}
return 0;
}
#include<stdio.h>
#define D 150
int main(void)
{
unsigned auto start=5;
unsigned week =0;
while(start<D)
{
printf("week == %u d==%u\n",week,start);
week++;
start=(start-week)*2;
}
return 0;
}