-4
#include <stdio.h> 
#include<conio.h>
int main () 
{ 
        printf("Enter the Physics ,Chemistry and Maths Marks"); 
        int mark[3]= {40,50,10};
        int s[3];
        int i; 
        int sum = 0, highest = 0; 
        clrscr(); 
        for (i = 0; i < ; i++) 
             { 
                sum += mark[i]; 
                if (mark[i] > highest) 
                        highest = mark[i]; 
             } 

        printf("The Highest Mark is %d: \n", highest); 
        getch(); 

    return 0; 

} 

its working fine, I need to give a input dynamically and get the output

How to do that?

Enter the Marks : 30 20 10
output: 30
Spikatrix
  • 20,225
  • 7
  • 37
  • 83
k.nisha Cuty
  • 35
  • 1
  • 10
  • 2
    Hint: Use `scanf` to get input. BTW, That code won't compile and has some unused variables. Also, why do you have `clrscr()` *after* the first `printf`? – Spikatrix Sep 06 '15 at 10:39
  • yes i will remove that unused variable and clrscr() .how to get the input array it shows wrong max value – k.nisha Cuty Sep 06 '15 at 10:45
  • `#include #include int main () { clrscr(); printf("Enter the Physics ,Chemistry and Maths Marks"); int mark[3]; mark[3]=scanf ("%d",mark[3]); int i; int sum = 0, highest = 0; for (i = 0; i < ; i++) { sum += mark[i]; if (mark[i] > highest) highest = mark[i]; } printf("The Highest Mark is %d: \n", highest); getch(); return 0; }` – k.nisha Cuty Sep 06 '15 at 10:45
  • Please add the code into the question by [editing it](http://stackoverflow.com/posts/32422634/edit). Also, `for (i = 0; i < ; i++)` won't compile. – Spikatrix Sep 06 '15 at 10:51
  • possible duplicate of [How can I obtain which of this variables have the highest value?](http://stackoverflow.com/questions/16409701/how-can-i-obtain-which-of-this-variables-have-the-highest-value) – Vineet1982 Sep 06 '15 at 19:29

2 Answers2

0

This:

int mark[3];
mark[3] = scanf("%d",mark[3]);

is wrong because of several reasons. It seems that you don't know how to use scanf properly. It should be

int mark[3];
scanf("%d", &mark[0]);
scanf("%d", &mark[1]);
scanf("%d", &mark[2]); /* Get each number from stdin and store it in the address of the variable given */

or better

int mark[3];
scanf("%d %d %d", &mark[0], &mark[1], &mark[2]);

or even better

int mark[3], i;
for(i = 0; i < 3; i++) /* Loop 3 times */
{
    scanf("%d", &mark[i]);
}
Spikatrix
  • 20,225
  • 7
  • 37
  • 83
  • if i giving that it shows wrong output value, It will Always shows 12803 as output – k.nisha Cuty Sep 06 '15 at 10:50
  • Then the problem is somewhere else. Please post the **exact** code and the error and/or warning messages that you get. Currently,neither the code in the question nor the code in the comment compiles. You should also include your input and the output you get along with the expected output. – Spikatrix Sep 06 '15 at 10:55
0

You can get the numbers from the input using scanf() and then find the highest number using fmax():

#include <stdio.h>
#include <math.h>

int main()
{
    int mark[3] = {0, 0, 0};
    int highest = 0;

    printf("Enter the Marks\n");
    for (int i = 0; i < 3; i++) {
        printf("%d: ", i + 1);
        scanf("%d", &mark[i]);
        highest = fmax(highest, mark[i]);
    }

    printf("The Highest Mark is %d: \n", highest);
}
sergej
  • 17,147
  • 6
  • 52
  • 89