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<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
100
The sum of odd numbers from 1 to 199 is 10000
0 Comments