for循环第一题:打印一个正方形
#include
void main()
{
//定义正方形边长
int x;
scanf("%d",&x);
for(int i = 0; i < x; i++)
{
for(int j = 0; j < x; j++)
{
printf("*");
}
printf("\n");
}
}
for循环第二题:打印九九乘法表
#include
void main()
{
for(int i = 1; i < 10; i++)
{
for(int j = 1; j <= i; j++)
{
printf(j + "×" + i + "=" + i * j + "\t");
}
printf("\n");
}
}
#include
void main()
{
struct
{
char name[10];
int age;
char job;
union
{
int stud;
char teach;
}depa;
}body[2];
int n,i;
for(i=0;i<2;i++)
{
cout<<"input name ,age and department"<
if(body[i].job=='s')
cin>>body[i].depa.stud;
else
cin>>body[i].depa.teach;
}
cout<<"\tname"<<"\tage"<<"\tjob"<<"\tstud_int/teach_ch"<
{
if(body[i].job=='s')
cout<<"\t"< else
cout<<"\t"< }
}