#include <stdio.h>
#include <conio.h>
int main()
{
int iNum = 0, iSum = 0, iNVal = 0;
printf("Program to find the sum of first N numbers");
printf("\nEnter the number:");
scanf("%d",&iNum);
iNVal = iNum;
while(iNum)
{
iSum = iSum+iNum;
iNum--;
}
printf("\nSum of first %d number(s) is %d",iNVal,iSum);
getche();
return 0;
}
It depends on the series.
if (n%2==0) sum=n/2*(n+1); else sum=(n+1)/2*n;
//sum and product of 3 nos #include #include void main() { int a,b,c; printf("enter the 3 nos"); scanf("%d%d%d",&a,&b,&c); printf("sum of 3 nos",a+b+c); printf("product of 3 nos",a*b*c); getch(); }
int sum (int n) { if (n<=1) return n; else return n + sum (n-1); }
The nos. Are 8 and -8 Sum of the nos. 8+(-8)=0 Product of the nos. 8 × (-8) = -64
148
Each one of them can be expressed as a sum of two primes.
write an assembly language program to find sum of N numbers
The name of the program. For example: program sum ! This is a comment. Your program's code goes here... end program sum
int sum = 0; int n = 0; while( sum <= 999 ) { sum += (++n); }
Write a program to find the number and sum of all integers from 100 to 300 that are divisible by 11
11x11