Logo 
Search:

C Programming Articles

Submit Article
Home » Articles » C Programming » BeginnersRSS Feeds

Illustration of the conditional operator ? :

Posted By: Olivia Campbell     Category: C Programming     Views: 1804

Illustration of the conditional operator ? : .

Code for Illustration of the conditional operator ? : in C Programming

#define   MAXLOAN  50000                                    
                                                               
   main()                                                      
   {                                                           
       longint loan1, loan2, loan3, sancloan, sum23;          
                                                               
       printf("Enter the values of previous two loans:\n");    
       scanf(" %ld %ld", &loan1, &loan2);                      
                                                         
       printf("\nEnter the value of new loan:\n");             
       scanf(" %ld", &loan3);                                  
                                                               
       sum23 = loan2 + loan3;                                  
       sancloan = (loan1>0)? 0 : ((sum23>MAXLOAN)?           
                    MAXLOAN - loan2 : loan3);                  
                                                                          
       printf("\n\n");                                                        
       printf("Previous loans pending:\n%ld %ld\n",loan1,loan2);                             
       printf("Loan requested  = %ld\n", loan3);                             
       printf("Loan sanctioned = %ld\n", sancloan);                          
                                                                          
   }                                                                          


Output                                                                           
                                                               
   Enter the values of previous two loans:                     
   0    20000                                                  
   Enter the value of new loan:                                
   45000                                                       
   Previous loans pending:                                     
   0   20000                                                   
   Loan requested  = 45000                                     
   Loan sanctioned = 30000                                     
   Enter the values of previous two loans:                     
   1000   15000                                                
Enter the value of new loan:                                
   25000                                                       
   Previous loans pending:                                     
   1000   15000                                                
   Loan requested  = 25000                                     
   Loan sanctioned = 0                                         
  
Share: 


Didn't find what you were looking for? Find more on Illustration of the conditional operator ? : Or get search suggestion and latest updates.

Olivia Campbell
Olivia Campbell author of Illustration of the conditional operator ? : is from Toronto, Canada.
 
View All Articles

 
Please enter your Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

 
No Comment Found, Be the First to post comment!