Friday 6 April 2012

Find sum of 'N' natural numbers.

#include<conio.h>
#include<iostream.h>
void main()
{
  clrscr(); 
  int sum=0,i,num;
  cout<<"Enter a number";
  cin>>num;
  for(i=1;i<=num;i++)
  {
      sum=sum+i;
  }
  cout<<"Sum of "<<num<<"natural numbers = " <<sum; 
  getch();
}

No comments:

Post a Comment

Write a program which reads a set of integers into an integer array and then prints "YES"if all of them are same otherwise print "NO".

#include<stdio.h> int main() { int a[10],M=0,i,n; printf("enter a value for n\n"); scanf("%d",&n); fo...