#include <stdio.h>
void main()
{
int i;
int sum;
sum = 0;
for (i=0; i<1000; i++)
{
if ( ((i+1)%13==0) &&
((i+1)%2==1) )
sum = sum + (i+1);
}
printf("Sum is %d\n", sum);
}
請寫一個程式由鍵盤輸入十個數字, 列印 10 個數字的平方和? 以及立方和?
#include <stdio.h>
#include <math.h>
void main()
{
int x;
int i;
int sumOfSquare;
int sumOfCubic;
sumOfSquare = 0;
sumOfCubic = 0;
for (i=0; i<10; i++)
{
scanf("%d", &x);
sumOfSquare += pow(x, 2);
sumOfCubic += pow(x, 3);
}
printf("Sum of square is %d\n", sumOfSquare);
printf("Sum of cubic is %d\n", sumOfCubic);
}