Logo 
Search:

C Programming Articles

Submit Article
Home » Articles » C Programming » BeginnersRSS Feeds

Use of if for counting

Posted By: Lurline Fischer     Category: C Programming     Views: 1709

Use of if for counting.

Code for Use of if for counting in C Programming

   main()                                                      
   {                                                           
       int count, i;                                           
       float weight, height;                                   
       count = 0;                                              
       printf("Enter weight and height for 10 boys\n");        
                                                               
       for (i =1; i <= 10; i++)                                
       {                                                       
          scanf("%f %f", &weight, &height);                    
          if (weight < 50 && height > 170)                     
             count = count + 1;                                
       }                                                       
       printf("Number of boys with weight < 50 kgs\n");        
       printf("and height > 170 cm = %d\n", count);            
   }                                                        
                                                    
                                                               
   
Output                                                      
                                                               
   Enter weight and height for 10 boys                         
   45  176.5                                                   
   55  174.2                                                   
   47  168.0                                                   
   49  170.7                                                   
   54  169.0                                                   
   53  170.5                                                   
   49  167.0                                                   
   48  175.0                                                   
   47  167                                                     
   51  170                                                     
   Number of boys with weight < 50 kgs                         
   and height > 170 cm = 3                                     
  
Share: 


Didn't find what you were looking for? Find more on Use of if for counting Or get search suggestion and latest updates.

Lurline Fischer
Lurline Fischer author of Use of if for counting is from Frankfurt, Germany.
 
View All Articles

Related Articles and Code:


 
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!