Ticker

6/recent/ticker-posts

Header Ads Widget

Contact Us For Advertisement: 9858091920

Sum of first 100 odd Number - C Programming Language

Tutor Chetan

C Programming Language

 Question: Sum of first 100 odd Number




/* 1. Sum of first 100 odd numbers */ 
/* Program Coded By Chetan Thapa Magar. */ 

#include<stdio.h>
#include<conio.h>
void main()
{
int i, k, sum=0, l;
printf("Enter how many odd numbers:\n");
scanf("%d", &k);
l=2*k-1;
for(i=1; i<=l; i+=2)
sum=sum+i;
printf("\nThe sum of odd numbers from 1 to %d is %d", l, sum);
getch();
}

Output / Execution:
Enter how many odd numbers:
100 

The sum of odd numbers from 1 to 199 is 10000 

Post a Comment

0 Comments