0

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..

4
Contributors
14
Replies
16
Views
6 Years
Discussion Span
Last Post by Daita
0

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..

0
#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 by mike_2000_17: Fixed formatting

0

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

0

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

0

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

0

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

0

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

0

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

Edited by Trentacle: n/a

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.