用C语言程序三种循环语句分别编写程序,求1-100的平方值?

如题所述

程序代码如下(已运行):
#include"iostream.h"
#include"math.h"
void main()
{
double a[101];//定义a[]为了后面输出格式控制
int i=1;
//用for循环实现
for(i=1;i<=100;i++)
{
a[i]=pow(i,2);
cout<<a[i]<<" ";
if(i%10==0) //控制每行输出10个数
cout<<endl;
}
cout<<endl;
//用while循环实现
i=1;
while(i<=100)
{
a[i]=pow(i,2);
cout<<a[i]<<" ";
if(i%10==0)
cout<<endl;
i++;
}
cout<<endl;
//用do…while循环实现
i=1;
do
{ a[i]=pow(i,2);
cout<<a[i]<<" ";
if(i%10==0)
cout<<endl;
i++;
}while(i<=100);
cout<<endl;
}
温馨提示:答案为网友推荐,仅供参考
第1个回答  推荐于2018-03-13
main()
{
int s = 1;
for (int i = 2; i <= 100; i++)
s += i * i;
printf("%d", s);
}

main()
{
int s = 0, n = 100;
while(n--)
s += (n+1) * (n+1);
printf("%d", s);
}

main()
{
int s = 0, n = 100;
do
{
s += n * n;
}
while(--n);
printf("%d", s);
}本回答被网友采纳
第2个回答  2014-05-17
第一个是C的
第二个是VC的
第3个回答  2014-05-17
楼上的都不错!

试用通过..楼主可以用了..
相似回答