Wednesday 11 April 2012

40).Write a Program to Find The Sum of The First 20 Odd Numbers

#include<conio.h>
#include<iostream.h>
void main()
{
   clrscr();
   int c=1,s=0,i=1;
   while(c<=20)
    {
      s=s+i;
      i=i+2;
      c++;

    }

     cout<<"Sum of The First 20 Odd Number is " <<s;
     getch();

}

1 comment:

  1. can you give the same program using do while loop?

    ReplyDelete

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...