Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Daniel - hw3q2
#include <stdio.h> #define NUM 100 int main() { int num[NUM]={0}, sequence=0, sum=0, elements=0, lower_avg=0; double avg[NUM]; printf("Please enter the numbers sequence:\n"); for(int i=0; i<NUM; i++){ scanf("%d", &num[i]); if(num[i]<=0){ break; } } for(int i=0; i<NUM; i++){ if((i!=0 && num[i-1]>num[i]) || i==99){ //here I thought about the option where i=99 - this is the last element so in a case where it gets there we need to enter the "barrier" area to add the last sub_sequence avg[sequence]=(double)sum/elements; ++sequence; sum=0; elements=0; } sum+=num[i]; elements++; if(num[i]<=0){ break; } } printf("The number of increasing subsequences is %d\n", sequence); printf("The averages are: "); for(int i=0;i<sequence-1;i++){ if(avg[i]<avg[sequence-1]){ lower_avg++; } printf("%.1f ", avg[i]); } printf("%.1f\n", avg[sequence-1]); //this prints the last avrage because you don't want to print a space at the end. printf("The number of subsequences with average lower than the average of the last one is %d\n", lower_avg); return 0; } // here is the input example: 1 2 7 9 4 75 75 100 104 7 7 8 11 4 1 4 4 700 888 -5
run
|
edit
|
history
|
help
0
Primes in binary
C)_Assign_q4
Vereinfachung
to find a number is even or not
ATM
Ordered Openmp
Test 4
poinres1
Lab 11 v1.0
Adding sums of two 1-D arrays