
输入用户想要输入的元素数量,然后输入用户想要从给定元素列表计算的总值。
Input : N=5 Enter any 5 values : 3 1 6 5 7 Enter sum you want to check : 10 Output : 3 1 6
START STEP1-> Take values from the user STEP2-> Take the sum a user want to check in the set. STEP3-> For i = 0; i < n; i++ STEP4-> Check If sum - *(ptr+i) >= 0 then, STEP4.1-> sum -= *(ptr+i); STEP4.2-> Print the value of *(ptr+i) END If END For STOP
#include <stdio.h>
int main(int argc, char const *argv[]){
int *ptr, n, i, sum;
printf("Enter number of digits you want to enter");
scanf("%d", &n);
ptr = (int*)malloc(sizeof(int)*n); //Dynamically allocating the memory of int
type
printf("Enter %d elements", n);
for(i = 0; i < n; i++) {
scanf("%d", (ptr+i)); //Inputting the value in dynamically
//allocated array
}
printf("Enter the sum you want to check");
scanf("%d", &sum);
for ( i = 0; i < n; i++) {
if(sum - *(ptr+i) >= 0) { //Checking the values which can be added to form the sum
X
sum -= *(ptr+i); //Updating the value of sum
printf("%d ", *(ptr+i)); //Printing the Values which can be summed up to form sum
}
}
return 0;
}如果我们运行上面的程序,它将生成以下输出
红色扁平化的外贸公司模板 扁平化概念的核心意义是:去除冗余、厚重和繁杂的装饰效果。而具体表现在去掉了多余的透视、纹理、渐变以及能做出3D效果的元素,这样可以让“信息”本身重新作为核心被凸显出来。同时在设计元素上,则强调了抽象、极简和符号化。扁平化的设计,尤其是手机的系统直接体现在:更少的按钮和选项,这样使得UI界面变得更加干净整齐,使用起来格外简洁,从而带给用户更加良好的操作体验。因为可以更加简
36
Enter number of digits you want to enter 5 Enter 5 elements 3 1 6 5 7 Enter the sum you want to check 10 3 1 6
以上就是打印可以相加得到给定和的元素的详细内容,更多请关注php中文网其它相关文章!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号