Answer the question
In order to leave comments, you need to log in
I stumbled on the solution of the problem on the steppe in cycles. What's wrong?
https://stepik.org/lesson/64123/step/7?unit=41087 Here are the tasks for cycles. I'm stuck starting from step 6, I can't move on at all if I skip it. does not work. I just can't understand the algorithm of tasks. I don’t have any ideas .. help me solve these problems ... now I’ll post my solution, it’s not correct, just tell me where I screwed up and how to fix it. I've been fighting with them all week. nothing helps
step 6:
Maximum and minimum
Need to find the maximum and minimum element of a sequence of unknown length.
Input data:
A sequence of integers ending in zero. The number zero itself is not a member of the sequence, but is only a signal that the end of the sequence has been reached. There is at least one non-zero number in the sequence.
Output
Print two integers M and m, where M is the maximum element of the sequence, m is the minimum element of the sequence.
Sample Input:
123 443 652 828 2 4212 0
Sample Output:
4212 2
#include <stdio.h>
int main() {
int n,res, k=1;
scanf("%d",&n);
while(res<=n){
res=k*k;
k+=1;
printf("%d ",res);
}
return 0;
}
шаг 7:
Точные квадраты
Выведите на экран все точные квадраты натуральных чисел, не превосходящие данного числа N. Выводить квадраты следует от меньшего к большему.
Входные данные:
Одно целое число N. (1≤N≤10000)
Выходные данные:
Квадраты натуральных чисел, записанные через пробел.
Sample Input 1:
50
Sample Output 1:
1 4 9 16 25 36 49
#include <stdio.h>
int main() {
int n,res, k=1;
scanf("%d",&n);
while(res<=n){
res=k*k;
k+=1;
printf("%d ",res);
}
return 0;
}
шаг 8:
Степень двойки
По данном числу N определить, является ли оно степенью числа 2.
Входные данные:
Одно целое неотрицательное число N.
Выходные данные:
YES -- если число N является степенью двойки, и NO в противном случае.
Sample Input:
128
Sample Output:
YES
#include <stdio.h>
#include <math.h>
int main() {
int N=0,two,step;
scanf("%d",&N);
N=pow(two,step);
do{
if(two==2){
step+=1;
printf("YES");
}else{
printf("NO");
}
}while(N);
return 0;
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question