/*源程序:exp4_12(1).cpp*/
#include<stdio.h>
#include<stdlib.h>
void main()
{
int r;
int g;
r=rand();
printf("Input a number:");
scanf("%d",&g);
if(g==r)
printf("Right!\n");
}
/*源程序:exp4_12(2).cpp*/
#include<stdio.h>
#include<stdlib.h>
void main()
{
int r;
int g;
r=rand();
printf("Input a number:");
scanf("%d",&g);
if(g==r)
printf("Right!\n");
else
printf("The number is:%d,You are wrong!\n",r);
}
/*源程序:exp5_2.cpp*/
#include<stdio.h>
main()
{ int i=1;
int sum=0;
while(i<=100)
{ sum=sum+i;
i++;
}
printf("sum=%d\n",sum);
}
/*源程序exp5_5.cpp*/
#include<stdio.h>
void main()
{ int i;
int sum=0;
for(i=1;i<=100;i++)
{
sum=sum+i*(i+1);
}
printf("1x2x3x4x...x100x101=%d\n",sum);
}