2024.1.15作业

1打印奇数金字塔

           

#include<stdio.h>
#include<string.h>
int main(int argc, const char *argv[])
{
	int i,j;
	for(i=1;i<=4;i++)
	{
		for(j=1;j<=4-i;j++)
			printf(" ");
			for(j=1;j<=2*i-1;j++)
			{	

				printf("*");
			}
		putchar(10);
	}
	return 0;
}

2.在终端输入一串内容,然后按下回车,判断输入的数字有几个?大写字母几个?小写字母几个,其他字符几个?

#include<stdio.h>
#include<string.h>
int main(int argc, const char *argv[])
{
	char c;
	int count_num=0;// 总数字
	int count_c1=0,count_c2=0;//总字母
	int count_zf=0;//总字符
	while(c!='\n')
	{
		scanf("%c",&c);
		if(c>='0' && c<='9')
		{
			count_num++;
		}
		else if(c>='A' && c<='Z')
		{
			count_c1++;
		}
		else if(c>='a' && c<='z')
		{
			count_c2++;
		}
		else
		{
			count_zf++;
		}
	}
	printf("共有%d个数字,%d个大写字母,%d个小写字母%d个其他字符\n",count_num,count_c1,count_c2,count_zf-1);
	return 0;
}

(3)打印1000以内的所有质数

#include<stdio.h>
#include<string.h>
int main(int argc, const char *argv[])
{
	int i,j;
	for(i=2;i<1000;i++)  //2~1000遍历
	{
		for(j=2;j<i;j++)
		{
			if(i%j==0)
			break;
		}
		if(i==j)
		{
				printf("%d\n",i);
		}
	}		

	return 0;
}

  • 9
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值