Logo 
Search:

C Programming Articles

Submit Article
Home » Articles » C Programming » Homework HelpRSS Feeds

Compute sum of those integers that are evenly divisible by 5. Use the conditional operator ( ? : ).

Posted By: Falaknaz Ahmed     Category: C Programming     Views: 4469

Write a program to compute sum of those integers that are evenly divisible by 5. Use the conditional operator ( ? : ).

Code for Compute sum of those integers that are evenly divisible by 5. Use the conditional operator ( ? : ). in C Programming

#include<stdio.h>
#include<conio.h>
void main()
{
        int i,sum=0,n=100,j=0;
        clrscr();
        printf("\n\n THE SERIES IS UNDER : \n\n\n");
        i=2;
        while(i<=n)
        {
            sum=sum+i;
            i==2 ? printf("%d",i):printf(" + %d",i);
            i=i+3;
        }
        printf("\n\n\n THE SUMMATION OF SERIES IS %d",sum);
        printf("\n\n\n");
        i=2;
        while(i<=n)
        {
            sum=sum+i;
            i%5==0 ? j=j+i:0;
            i==5 ? printf("%d",i):0;
            i%5==0 ? printf(" + %d",i):0;
            i=i+3;
        }
        printf("\n\n\n THE SUMMATION OF DIVISIBLE 5 IS %d",j);
        getch();
}


*************************** OUTPUT *******************************************


        THE SERIES IS UNDER :

        2 + 5 + 8 + 11 + 14 + 17 + 20 + 23 + 26 + 29 + 32 + 35 + 38 + 41 + 44 + 47 + 50 + 53 + 56 + 59 + 62 + 65 + 68 + 71 + 74 + 77 + 80 + 83 + 86 + 89 + 92 + 95 + 98

     THE SUMMATION OF SERIES IS 1650

    5 + 5 + 20 + 35 + 50 + 65 + 80 + 95
        
    THE SUMMATION OF DIVISIBLE 5 IS 350


*******************************************************************************
  
Share: 



Falaknaz Ahmed
Falaknaz Ahmed author of Compute sum of those integers that are evenly divisible by 5. Use the conditional operator ( ? : ). is from Karachi, Pakistan.
 
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!