Could we find the largest among three numbers using 'for' and if?
I have the following program, please check it
#include<stdio.h>
main()
{
int a,b,c,sum=o,i';
printf("enter the numbers");
scanf("%d%d%d",&a,&b,&c);
sum=a+b+c;
for(i=sum;i<=sum,i--)
{
if(i==a||i==b||i==c)
printf("%d the greatest");
exit();
}}........please clarify the logic if it is correct to the intention..

Did you tried to compile it??

in First line only you have so many mistakes ..

sum = o

It showed be

sum = 0

remove ` after i..

Use { } correctly

and in

printf("%d blah blah");

what you are printing ????
i ?? sum ???

Make this changes compile it,
if got error copy paste that code..

#include<stdio.h>
main()
{
int a,b,c,i,sum = 0;
printf("enter the numbers");
scanf("%d%d%d",&a,&b,&c);
sum=a+b+c;
For(i=sum;i<=sum,i--)
if(i==a||i==b||i==c)
printf("%d",i);
exit()
}

Edited 3 Years Ago by mike_2000_17: Fixed formatting

Sorry, I can't see your screen from here. It might be nice to let us know what errors -- or should we guess?

I am sorry .The errors are...possible use of i before definition,and funtion call missing

First one is in the column 8 and the second in the 12th

So the e in include is using i before definition and the d in stdio.h is a function call missing?

Sorry, but this is like pulling teeth. If you want help, you MUST give us all the information necessary to understand the problem. Not bits and pieces that are useless without the rest of the information.

Copy and Paste everything that will help rather than paraphrasing which leaves out important clues...

And learn to format your code

Problem with exit()

exit(0);

Use { } may take few seconds more to type but they help

Check this now

#include<stdio.h>
main()
{
int a,b,c,sum=0,i;
printf("enter the numbers");
scanf("%d%d%d",&a,&b,&c);
sum=a+b+c;
for(i=sum;i<=sum ;i--)
{
        if(i==a || i==b || i==c)
        {
        printf("%d the greatest",i);
        exit(0);
        }
}
}

looks so neat and easy to understand

Sorry, missed the second page. Everything I had to say has been said

Edited 5 Years Ago by Trentacle: n/a

This question has already been answered. Start a new discussion instead.