编程作业20191104132052

为君一笑 提交于 2019-12-05 01:04:10

1.

/**
	Module Name: 

	Description:

	Author:
	Created:
	Last Change:

	Functions:

*/
#include<stdio.h>
int main(void)
{
	char ch[26];
	int i;
	for(i=0;i<26;i++)
	{
		ch[i]='a'+i;
		printf("%c",ch[i]);
	}
	getchar();
	return 0;
}

2.

/**
	Module Name: 

	Description:

	Author:
	Created:
	Last Change:

	Functions:

*/
#include<stdio.h>
int main(void)
{
	int i,j;
	for(i=0;i<5;i++)
	{
		for(j=0;j<i+1;j++)
		printf("$");
		printf("\n");
	}
	getchar();
	return 0;
} 

3.

/**
	Module Name: 

	Description:

	Author:
	Created:
	Last Change:

	Functions:

*/
#include<stdio.h>
int main(void)
{
	int N=6,i,j;
	for(i=0;i<N;i++){
		for(j=0;j<=i;j++){
			printf("%c",(char)('A'+N-1-j));
		}
		printf("\n");
	}
	return 0;
}

4.

/**
	Module Name: 

	Description:

	Author:
	Created:
	Last Change:

	Functions:

*/
#include<stdio.h>
int main(void)
{
	int i=0,j=0;
	char aaa='A';
	for(i=1;i<=6;i++){
		for(j=1;j<=i;j++){
			printf("%c",aaa++);
		}
		printf("\n\n");
	}
	return 0;
} 

5.

/**
	Module Name: 

	Description:

	Author:
	Created:
	Last Change:

	Functions:

*/
#include<stdio.h>
int main(void)
{
	int i,j,k;
	char letter;
	printf("please input a capital:");
	scanf("%c",&letter);
	k=letter-'A'+1;
	for(i=0;i<k;i++){
		for(j=0;j<k-i;j++)
		   printf(" ");
		for(j=0;j<=i;j++)
		   printf("%c",'A'+j);
        for(j=i-1;j>=0;j--)
           printf("%c",'A'+j);
        printf("\n");
	}
	return 0;
} 

6.

/**
	Module Name: 

	Description:

	Author:
	Created:
	Last Change:

	Functions:

*/
#include<stdio.h>
int main(void)
{
	int lower,upper,index;
	int square,cube;
	printf("Enter starting integer and ending integer:");
	while(scanf("%d %d",&lower,&upper)==2){
		printf("%5s %10s %15d\n","num","square","cube");
		for(index=lower;index<=upper;index++){
			square=index*index;
			cube=index*square;
			printf("%5d %10d %15d\n",index,square,cube);
		}
		printf("Enter next pair(non-numeric to quit):\n");
	}
	return 0;
} 

7.

/**
	Module Name: 

	Description:

	Author:
	Created:
	Last Change:

	Functions:

*/
#include<stdio.h>
int main(void)
{
	char a[20];
	int i;
	printf("please input a word:");
	scanf("%s",a);
	for(i=strlen(a)-1;i>=0;i--)
	   printf("%c",a[i]);
    printf("\n");
    return 0;
}

8.

/**
	Module Name: 

	Description:

	Author:
	Created:
	Last Change:

	Functions:

*/
#include<stdio.h>
int main(void)
{
	float a,b,c;
	printf("Enter two float numbers:");
	while(scanf("%f %f",&a,&b)==2){
		c=(a-b)/(a*b);
		printf("c=%f\n",c);
		printf("Enter next pair(non-numeric to quit):\n");
	}
	return 0;
}

9.

/**
	Module Name: 

	Description:

	Author:
	Created:
	Last Change:

	Functions:

*/
#include<stdio.h>
int main(void)
{
	int lower,upper,index;
	printf("Enter lower and upper integer limits: ");
	while(scanf("%d %d",&lower,&upper)==2 && lower !=upper){
		int sum=0;
		for(index=lower;index<=upper;index++){
			sum+=index*index;
		}
		printf("the sums of the squares from %d to %d is %d\n",lower*lower,upper*upper,sum);
		printf("Enter next set of limits: ");
	}
	printf("done\n");
	return 0;
} 

10.

/**
	Module Name: 

	Description:

	Author:
	Created:
	Last Change:

	Functions:

*/
#include<stdio.h>
#define SIZE 8
int main(void)
{
	int a[SIZE],i;
	printf("enter %d interges.\n",SIZE);
	for(i=0;i<SIZE;i++)
	   scanf("%d",&a[i]);
    for(i=SIZE-1;i>=0;i--)
       printf("%d",a[i]);
    printf("\n");
    return 0;
}

11.

/**
	Module Name: 

	Description:

	Author:
	Created:
	Last Change:

	Functions:

*/
#include<stdio.h>
int main(void)
{
	float number1=1.0,number2=1.0;
	float result1=0,result2=0;
	int item;
	int i;
	printf("please input the items:\n");
	scanf("%d",&item);
	for(i=1;i<=item;i++,number2++){
		result1=result1+number1/number2;
	}
	foe(i=1;i<=item;i++,number2++){
		if(i%2==0){
			number1=-1.0;
		}
		else{
			number1=1.0;
		}
		result2=result2+number1/number2;
	}
	printf("result1=%f\n result2=%f",result1,result2);
	return 0;
}

12.

/**
	Module Name: 

	Description:

	Author:
	Created:
	Last Change:

	Functions:

*/
#include<stdio.h>
#define SIZE 8
int main(void)
{
	int a[SIZE],i;
	a[0]=1;
	for(i=1;i<SIZE;i++){
		a[i]=2*a[i-1];
	}
	i=0;
	do{
		printf("%d",a[i]);
		i++;
	}
	while(i<SIZE);
	printf("\n");
	return 0;
} 

13.

/**
	Module Name: 

	Description:

	Author:
	Created:
	Last Change:

	Functions:

*/
#include<stdio.h>
int main(void)
{
	double array1[8],array2[8];
	int i=0;
	double sum=0;
	printf("please input 8 integers:\n");
	for(i=0 ;i<8;i++){
		scanf("%1f",&array1[i]);
		sum=sum+array1[i];
	}
	for(i=0;i<8;i++){
		printf("%8.0f",array1[i]);
	}
	printf("\n");
	for(i=0;i<8;i++){
		printf("%8.0f",array2[i]);
	}
	return 0;
} 

14.

/**
	Module Name: 

	Description:

	Author:
	Created:
	Last Change:

	Functions:

*/
#include<stdio.h>
int main(void)
{
	char data[255];
	int i=-1;
	do{
		i++;
		scanf("%c",&data[i]);
	}
	while(data[i]!='\n');
	for(i=-1;i>=0;i--)
	return 0;
}

15.

/**
	Module Name: 

	Description:

	Author:
	Created:
	Last Change:

	Functions:

*/
#include<stdio.h>
int main(void)
{
	double sum1=100.00,sum2=100.00;
	double a=100.00;
	int year=0;
	do{
		year++;
		sum1=sum1+a 0.1;
		sum2=sum2+sum2 0.05;
	}
	while(sum1>=sum2);
	printf("after %d year,deirdre's account:%.2f,daphne's account:%.2f\n",year,sum1,sum2);
	return 0;
} 

16.

/**
	Module Name: 

	Description:

	Author:
	Created:
	Last Change:

	Functions:

*/
#include<stdio.h>
int main(void)
{
	double sum=100.00;
	int year=0;
	do{
		year++;
		sum=sum+sum*0.08;
		sum-=10;
	}
	while(sum>0);
	printf("after %d year,chuckie lucky has no money!\n",year);
	return 0;
} 

17.

/**
	Module Name: 

	Description:

	Author:
	Created:
	Last Change:

	Functions:

*/
#include<stdio.h>
int main(void)
{
	int quantity=5;
	int week=0;
	do{
		week++;
		quantity-=week;
		quantity=quantity*2;
	}
	while(quantity<=150);
	printf("after %d weeks,rabnud's friends over 150!\n",week);
	return 0;
} 

18.

/**
	Module Name: 

	Description:

	Author:
	Created:
	Last Change:

	Functions:

*/
#include<stdio.h>
#define RATE_SIMP 0.10 
#define RATE_COMP 0.05
#define INIT_AMT 100
int main(void)
{
	double daphne=INIT_AMT;
	double deidre=INIT_AMT;
	int years=0;
	while(deire<=daphne){
		daphne+=RATE_SIMP*INIT_AMT;
		deidre+=RATE_COMP*deidre;
		years++;
	}
	printf("%d years later,deidre's money more than daphne's\n",years);
	printf("daphne=%f\n",daphne);
	printf("deidre=%f",deidre);
	return 0;
}
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!