Blogger templates

Pages

Tuesday, 15 May 2012

Write a C Program to Calculate the Sum of First Fifty Numbers

sum of first 50 numbers

Data types:
  • Data Type Defines what type of value you can store in a Variable.
  • Primary Data Types: int ,float ,char.
Int:
  • Format Specifier = %d
  • Keyword = int
  • Space = 2 byte
  • Range = -32768 to 32767
  • Decimal values are allowed.
Statement of C program: Find the Sum of first 50 Numbers by using for Statement:

#include<stdio.h>
#include<conio.h>
void main()
{
int a,b=0;
clrscr();
for( a=1 ; a<=50 ; a++ )
{
b=b+a;                                                          // It can also be written as b+=a
}
printf(" sum is =%d" , b);
getch();
}

 Output:
 Sum is =1275


0 comments:

Post a Comment