From 6efe2d480bf11f4764fefbd8a5bed1c1e67bdbb9 Mon Sep 17 00:00:00 2001 From: shashank <55712254+Shanky2000@users.noreply.github.com> Date: Sat, 31 Oct 2020 23:38:45 +0530 Subject: [PATCH] sumoddnaturalno Write a program in C to display the n terms of odd natural number and their sum like: 1 3 5 7 ... n --- sumofoddnaturalno | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 sumofoddnaturalno diff --git a/sumofoddnaturalno b/sumofoddnaturalno new file mode 100644 index 00000000..114b16c1 --- /dev/null +++ b/sumofoddnaturalno @@ -0,0 +1,15 @@ +#include +void main() +{ + int i,n,sum=0; + + printf("Input number of terms : "); + scanf("%d",&n); + printf("\nThe odd numbers are :"); + for(i=1;i<=n;i++) + { + printf("%d ",2*i-1); + sum+=2*i-1; + } + printf("\nThe Sum of odd Natural Number upto %d terms : %d \n",n,sum); +}