- 1
C language
This program have to takes 15 marks Then find the biggest one and calculate how much is needed till it becomes 20 , then plus that to every marks(for example the biggest one is 15 , 20-15=5,every marks have to be pluses with 5) It doesn’t run Do you know what is the problem?! https://code.sololearn.com/c3bg5I6zrQ7b/?ref=app
37 Answers
+ 7
#include <stdio.h>
#define MAX_SIZE 100
#define HLINE for(int i=1;i<=50;i++) \
printf("-"); int main()
{
int arr[MAX_SIZE], i, j, temp, N;
printf("Enter the size of your array:"); scanf("%d",&N);
printf("\nEnter you array (%d numbers):",N); for (i=0;i<=N-1;i++){
scanf("%d",&arr[i]); }
HLINE
printf("\nHere' what you entered:\n"); for (i=0;i<=N-1;i++)
printf("%d\n",arr[i]);
for(i=1;i<N;i++){ for(j=0;j<N-i;j++){
} }
if (arr[j]<arr[j+1]){ temp=arr[j];
arr[j]=arr[j+1];
arr[j+1]=temp; }
HLINE
printf("\nHeres the sorted array (Descending Order):\n"); for(i=0;i<=N-1;i++)
printf("%d\n",arr[i]);
return 0;
}
+ 3
#include <stdio.h>
int main(){
int arr[15], i, j, temp,c;
for(i=1;i<=15;i++){
scanf("%d",&arr[i]);
}
//for(i=1;i<=3;i++){
for(j=1;j<=14;j++){
if (arr[j]<arr[j+1]){
temp=arr[j+1];
//arr[j]=arr[j+1];
// arr[j+1]=temp;
}
}
//}
c=20-temp;
for(i=1;i<=15;i++){
arr[i]+=c;
printf("%d \n",arr[i]);
}
return 0; }
//remove commented lines...
//understand what changes i made...
+ 2
for(i=0;i<20;i++)
scanf("%d,m[i]);
In any for loop,
1) i=0 initialization block.
2) i<20; condition to execute loop, if this is loop executes. If condition becomes false, then stops executing further..
3) i++; iteration step count.
In your loop, you specified ..
Laya Mousavi
you set i=1, and condition is i==15 is false, so then loop never executes.
for(i=0;i<20;i++)
{
...
}
this executes from i=0 to i=19.
and when i=20, then it stops...
+ 1
Laya Mousavi Ok.. But is it needed to print in ascending order also...?
You not mentioned any where that...
So i commented swaping values in loop...
+ 1
Laya Mousavi
You can use a funtion to print calulated values..
Like this :
void print(int arr[],int c)
{
for(int i=1;i<=15;i++){
arr[i]+=c;
printf("%d \n",arr[i]);
}
}
Call this from main method..
+ 1
¿¿??
+ 1
C language
+ 1
#include <stdio.h>
int main(){
int arr[15], i, j, temp,c,x;
for (i=0;i<15;i++){
scanf("%d",&arr[i]);
}
for (i=0;i<15;i++){
for(j=0;j<14;j++){
if (arr[j]<arr[j+1]){
temp=arr[j];
arr[j]=arr[j+1];
arr[j+1]=temp;
if(arr[j]!=arr[j+1])
{
x=arr[j];
}
}
}
}
//
c=20-x;
for(i=0;i<15;i++){
arr[i]+=c;
printf("%d \n",arr[i]);
}
printf("\n\n>>>>> %d",x);
return 0; }
+ 1
Help me
0
Looking at your code I see your loops was supposedly going about 20 times rather than 15. Did you mean take 15 marks or 20?
Do you really need to sort the array to find the biggest mark though? you can find the biggest mark just by iterating the array with a little bit of comparison. And you can calculate the gap to 20 as you go iterating the array
If you need to sort the marks array you have the option to use `qsort` function (http://www.cplusplus.com/reference/cstdlib/qsort/). Your sorting way is flawed if I may say, check out bubble sort implementation example below to see how it is done correctly. It is in C++, but it works the same with C.
https://www.sololearn.com/learn/650/?ref=app
0
that was incorrect,now loops are going about 15 times
thanks
i just want to find the biggest one,and sth that i wrote were my only solution,do you have any idea?!
the question ask us to solve this with using arrys and function
Ipang
0
change i==15 to i <= 15 in every occurrence of ==
0
Jayakrishna i didn’t get your mean😭
i’m waiting
0
Laya Mousavi
Updated. Read it again.. Change your code. And give a reply... If you dont understand something, mention that...
0
i do some changes but it runs now,but it’s outputs are negative😳
bahha🐧
Jayakrishna
0
how many values do you enter?
better if you initialize the array instead of getting the values from input (scanf)
0
int arr[15] ={1,2,3,4,5,6,7,8,9,10,11,12,13,14,15};
int i, j, temp,c;
/*
for (i=1;i<=15;i++){
scanf("%d",&arr[i]);
}*/
0
15 values
actually it’s my exercise for university
this teacher ask us to solve this by using arrys and functions
bahha🐧
0
just for debugging set the array values instead of entering them every time. when fixed use whatever you want.
0
why are the loops in comment form?!
Jayakrishna