×

# to find max and min

 0 i am a beginner. i am on my first problem and its not working. i really want help. the question is to find max and min of n numbers . the code is not working as it is supposed to, my code is- #include  int main() { int n,m,i,max,min,num1,num2,x,y,temp; int large[100],small[100],index1=1,index2=1; printf("Give N : \n"); scanf("%d",&n); printf("N=%d\n",n); scanf("%d",&max); min=max; m=n-1; if(n%2==0){ scanf("%d",&min); m=m-2;} if(min>max){ temp=max; max=min; min=temp; }  for(i=1;i<=m/2;m++){ scanf("%d %d",&num1,&num2); if(num1max) max=num1; if(num2

 0 You are incrementing 'm' instead of 'i' in the for loop answered 25 Dec '14, 19:08 3★p00r 139●1●6 accept rate: 10% That still doesn't give required output. (25 Dec '14, 19:13) Given proper input, I am sure that this code will work fine! Link : http://ideone.com/pMAsW0 (25 Dec '14, 21:59) p00r3★

use selection sort its easy

# include<stdio.h>

void main() { int ,i,j,temp,a[100],pos ; printf("Enter the number of item "); scanf("%d",&n); \input element to sort printf("enter the items to sort \n"); for(i=0;i<n;i++) { scanf("%d",&a[i]); } \sort the elements for(i=0;i<n-1;i++) { pos =i; for(j=i+1;j<n;j++) { if(a[j]<a[pos])pos=j; } temp=a[pos]; a[pos]=a[i]; a[i]=temp; } printf("the sorted items are \n"); for(i=0;i<n;i++) { printf("%d"\n ,a[i]); } }

1
accept rate: 0%

 0 @vedant2080 I have not understood your solution but if you want to print maximum and minimum number then you may sort the array and for minimum print array[0] and for maximum print array[lengthOfArray-1]. answered 26 Dec '14, 01:07 1.9k●1●12●43 accept rate: 14%
 0 After hours of debugging it is finally working. But the original code from where i am learning is still not working. After i have modified the code upto much extent it is working. I am currently learning from nptel.ac.in ,hope you people know about nptel. The course is from IIT Kharagpur and course name is- Programming and Data Structures. I am currently completed it's 5th lecture ,the link is- http://nptel.ac.in/courses/106105085/5 answered 26 Dec '14, 19:03 9●1●4 accept rate: 0%
 0 No need to print Extra things , You have to print according to the sample output given. Such as printf("Give N : \n"); answered 26 Dec '14, 19:58 2★ambika93 81●3●8 accept rate: 0%

# include<stdio.h>

main(){ int min,max,n,i,j,t; scanf("%d",&n); int a[n]; for(i=0;i<n;i++) scanf("%d",&a[i]);="" for(i="0;i&lt;n;i++){" for(j="i-1;j&lt;n;j++){" if(a[i]="">a[j]){ t=a[i]; a[i]=a[j]; a[j]=t; } } } printf("Min is:%d, Max is:%d",a[0],a[n]); }

This answer is marked "community wiki".

0★syedazar
1
accept rate: 0%

 0 Well still the original code from where i am learning is not working.I have provided the link to the video tutorial above.The link to original code that is not working on my computer but working on the proffesor's computer is- link text Why is this code not working on my computer properly. I am using Dev C/C++ compiler on windows 7. Please Help! answered 27 Dec '14, 10:12 9●1●4 accept rate: 0%
 toggle preview community wiki:
Preview

By Email:

Markdown Basics

• *italic* or _italic_
• **bold** or __bold__
• image?![alt text](/path/img.jpg "title")
• numbered list: 1. Foo 2. Bar
• to add a line break simply add two spaces to where you would like the new line to be.
• basic HTML tags are also supported
• mathemetical formulas in Latex between \$ symbol

Question tags:

×690
×432
×26

question asked: 25 Dec '14, 17:44

question was seen: 1,180 times

last updated: 27 Dec '14, 10:12