Question:
1.WAP find the largest of 4 no using macros 2.WAP read a line from file from location N1 to N2 using command line agruments Eg:exe 10 20 a.c
Answer:
Ans 1: #define max(a,b,c,d) (((a>b?a:b) > (c>d?c:d) ) ? (a>b?a:b) : (a>b?a:b)) Source: CoolInterview.com
Answered by: Amey vaidya | Date: 11/29/2007
| Contact Amey vaidya
#include<stdio.h> #define MAX(x,y) ((x > y )? x : y ) int main() { int a,b,c,d; int max1,max2,max; printf(" Enter the four digits"); scanf("%d%d%d%d",&a,&b,&c,&d); if( MAX(a,b) == a ) if( MAX(a,c) == a ) if(MAX(a,d) == a) printf(" MAx is %d",a); else printf(" MAx is %d",d); else if( MAX(c,d) == c) printf(" MAx is %d",c); else printf(" MAx is %d",d); else if( MAX ( b,c ) == b) if(MAX(b,d) ==b ) printf(" MAx is %d",b); else printf(" MAx is %d",d); else if( MAX(c,d) == c) printf(" MAx is %d",c); else printf(" MAx is %d",d); system("pause"); return 0; } Source: CoolInterview.com
Answered by: Syed Baseer Ahmed | Date: 12/5/2007
| Contact Syed Baseer Ahmed
#define MAX(a,b) ((a) > (b) ? (a) : (b)) #define LARGEST(a,b,c,d) (MAX((a), MAX((b), MAX((c) , (d))))) void main() {
printf("Largest 4,10,17,29 is %d",LARGEST(4,10,17,29)); }
Source: CoolInterview.com
Answered by: Michael | Date: 11/17/2009
| Contact Michael
i would like to thank Mr.Syed Baseer Ahmed for the most compact and accurate code.nice work sir. Source: CoolInterview.com
Answered by: shashank kumar | Date: 7/29/2010
| Contact shashank kumar
If you have the better answer, then send it to us. We will display your answer after the approval.
Rules to Post Answers in CoolInterview.com:-
- There should not be any Spelling Mistakes.
- There should not be any Gramatical Errors.
- Answers must not contain any bad words.
- Answers should not be the repeat of same answer, already approved.
- Answer should be complete in itself.
|