Pages
News
Android
C
C ++
Java
Advanced Java
Cyber Security
HTML
CSS
Java Script
PHP
Tuesday, 30 June 2015
Program 5 : Write a program to find sum of first N odd numbers. Ex. 1+3+5+7+_ _+N.
#include<stdio.h>
void main()
{
int i, n, sum = 0;
i = 1;
scanf("%d", &n);
while (i <= n)
{
if (i % 2 != 0)
sum = sum + i;
i++;
}
printf("sum : %d", sum);
}
No comments:
Post a Comment
Newer Post
Older Post
Home
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment