Wednesday, April 3, 2024

C Program to Calculate Sum of Odd Values in an Array

 #include<stdio.h>

main()
{
    int a[10],i,sum=0;
    printf("Enter upto 5 Values: ");
    for(i=0; i<5; i++)
        scanf("%d",&a[i]);
    for(i=0; i<5; i++)
    {
        if(a[i]%2==1)
            sum=sum+a[i];
    }
    printf("Total Sum of Odd values is: %d ",sum);
   
}

 OUTPUT:

Enter upto 5 Values: 2 3 5 4 7
Total Sum of Odd values is: 15

No comments:

Post a Comment

Matrix multiplication in C

  Matrix multiplication  in C: We can add, subtract, multiply and divide 2 matrices. To do so, we are taking input from the user for row num...