Monday, 8 December 2014

C program to print sum and product of ODD numbers

program to print sum and product of ODD numbers
#include<stdio.h>
#include<stdlib.h>
main()
{
int n,i,sum=0,pro=1;
printf("enter value for n\n");
scanf("%d",&n);
        for(i=1;i<=n;i++)
        {
        if(i%2!=0)
        {
        printf("odd numbers are %d\n",i);
        sum=sum+i;
        pro=pro*i;
        }
        }
        printf("sum of n odd numbers is %d\n",sum);
        printf("product of n odd numbers is %d\n",pro);
}
OutPut:
madan@madan-Lenovo-G570:~/madan$ ./a.out
enter value for n
15
odd numbers are 1
odd numbers are 3
odd numbers are 5
odd numbers are 7
odd numbers are 9
odd numbers are 11
odd numbers are 13
odd numbers are 15
sum of n odd numbers is 64
product of n odd numbers is 2027025