IT Community - Software Programming, Web Development and Technical Support

Greatest of Three Numbers Without Using Two Variable

This is a discussion on Greatest of Three Numbers Without Using Two Variable within the C and C++ Programming forums, part of the Software Development category; The following program use only two variable for greatest of three number Code: #include<stdio.h> void main() { ...


Go Back   IT Community - Software Programming, Web Development and Technical Support > Software Development > C and C++ Programming

Register FAQ Members List Calendar Mark Forums Read
  #1 (permalink)  
Old 10-29-2007, 08:43 AM
Murali Murali is offline
D-Web Master
 
Join Date: Feb 2007
Location: India-Chennai.
Posts: 386
Murali is on a distinguished road
Send a message via AIM to Murali
Default Greatest of Three Numbers Using Two Variable

The following program use only two variable for greatest of three number

Code:
#include<stdio.h>
void main()
{
int a,b;
scanf("%d",&a);
scanf("%d",&b);
if(a>b)
b=a;
scanf("%d",&a);
if(a>b)
printf("Big value=%d",a);
else
printf("Big value=%d",b);

}

OUTPUT


Code:
10
20
30

Big value=30
__________________
-Murali..

Last edited by Murali : 10-29-2007 at 10:35 PM.
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 10-29-2007, 10:50 PM
Murali Murali is offline
D-Web Master
 
Join Date: Feb 2007
Location: India-Chennai.
Posts: 386
Murali is on a distinguished road
Send a message via AIM to Murali
Default Greatest of 'N' Numbers Using Three Variables

The following program use Three variable for Greatest of 'N' numbers

Code:
#include<stdio.h>
void main()
{
 int a,b,n;
 printf("Enter the N value=");
 scanf("%d",&n);
 printf("Enter the irst value=");
 scanf("%d",&b); 
 while (n>1)
  {
   printf("Enter the Next value=");
   scanf("%d",&a);
   if(a>b) 
   b=a;
   n=n-1;
  }
 if(a>b)
 printf("Big value=%d",a);
 else
 printf("Big value=%d",b);
}
OUTPUT

Code:
Enter the N value=5
Enter the First Value=40
Enter the Next value=38
Enter the Next value=19
Enter the Next value=42
Enter the Next value=37

Big Value=42
__________________
-Murali..
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Validating Numbers ragavraj PHP Programming 1 11-07-2007 07:12 AM
Greatest of Three Numbers Without Using Relational Operator? velhari C and C++ Programming 4 10-25-2007 03:10 AM
Static Global Variable and Static Local Variable vigneshgets C and C++ Programming 1 05-30-2007 11:50 AM
What is your greatest fear? KHyuga The Lounge 11 03-14-2007 10:53 AM
Your Greatest Regret? KHyuga The Lounge 0 02-23-2007 09:38 AM


All times are GMT -7. The time now is 08:59 PM.


Copyright ©2004 - 2007, DiscussWeb. All Rights Reserved.

SEO by vBSEO 3.0.0