打印梯形的代码(c++)

我看了一下c++的练习书上

有一个

让我们打印出一个

梯形

好了上代码!

(跪求赞和评论!!)

(跪求赞和评论!!)

(跪求赞和评论!!)

#include<bits/stdc++.h>
using namespace std;
int main ()
{ 
    int n;
    cin>>n;
    for(int i = 1;i <=n;i++) 
       {
			for(int j = 1;j <= n-i;j++) 
			{
				cout<<" ";
		    } 
			for(int k = 1;k <= 2*i+1;k++) 
			{
				cout<<"*";
			}
			cout<<endl;
       }
       return 0;
}

cout也可以用System.out.print()来写的。

一起加油!!

  • 9
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 5
    评论
以下是一个简单的C语言代码示例,用于对投影仪进行自动梯形校正: ```c #include <stdio.h> #include <stdlib.h> #include <math.h> // 模拟获取摄像头捕捉的图像 void capture_image(int image_width, int image_height, float *image) { for (int y = 0; y < image_height; y++) { for (int x = 0; x < image_width; x++) { image[y * image_width + x] = 1.0f; } } } // 计算图像的平均灰度值 float compute_average_gray(int image_width, int image_height, float *image) { float sum = 0.0f; for (int y = 0; y < image_height; y++) { for (int x = 0; x < image_width; x++) { sum += image[y * image_width + x]; } } return sum / (image_width * image_height); } // 对图像进行自动梯形校正 void auto_trapezoidal_correction(int image_width, int image_height, float *image, float correction_ratio) { float average_gray = compute_average_gray(image_width, image_height, image); float max_correction = (correction_ratio * image_height) / 2.0f; for (int y = 0; y < image_height; y++) { float correction = (float)y / (float)image_height * max_correction; for (int x = 0; x < image_width; x++) { float gray = image[y * image_width + x]; float corrected_y = (float)y + correction * (1.0f - gray / average_gray); int corrected_index = (int)corrected_y * image_width + x; if (corrected_index >= 0 && corrected_index < image_width * image_height) { image[y * image_width + x] = image[corrected_index]; } } } } int main() { int image_width = 640; int image_height = 480; float *image = (float*)malloc(sizeof(float) * image_width * image_height); capture_image(image_width, image_height, image); auto_trapezoidal_correction(image_width, image_height, image, 0.2f); // 输出校正后的图像 for (int y = 0; y < image_height; y++) { for (int x = 0; x < image_width; x++) { printf("%.2f ", image[y * image_width + x]); } printf("\n"); } free(image); return 0; } ``` 这个示例代码的基本思路是先获取摄像头捕捉的图像,然后计算出图像的平均灰度值,并根据设定的梯形校正比例计算出最大的校正量。接下来,对图像进行遍历,并根据每个像素点的灰度值计算出该点应该向上或向下校正的量,并使用这个量来计算校正后的像素位置。最后,将校正后的像素值复制回原图像中。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值