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

Programming in C

  PDF Download Links University Question Papers Notes Laboratory Manual Record Important Questions and Question Bank Important Questions Pro...