Program Using For Loop
/* Program To Display The Following Using For Loop 1) SUM OF ALL DIGITS FROM 1 -> n 2) SUM OF THE SQUARES OF ALL DIGITS FROM 1 -> n 3) SUM OF THE SQUAREROOTS OF ALL THE DIGITS FROM 1 -> n */ #include
#include
#include
void main() { int i,n,s1; float s3; long s2; clrscr(); printf("\nEnter a number\n\n"); scanf("%d",&n); for(i=1,s1=0,s2=0,s3=0;i<=n;i++) { s1 = s1+i; s2 = s2+i*i; s3 = s3+sqrt(i); } printf("\nsum of the digits from 1 to %d = %d\n",n,s1); printf("\nsum of the squares of the digits from 1 to %d = %ld\n",n,s2); printf("\nsum of the squareroots of the digits from 1 to %d = %f\n",n,s3); getch(); }
Please send comments to
vgdarur.javafive@blogger.com
Copyright © 2008 - iForeRunner.com
http://www.iforerunner.com/