C语言编程: 显示4个整数

来源:百度知道 编辑:UC知道 时间:2024/04/29 23:51:27
按下enter就显示4个整数。每个数字都是随机的 要求在0-9以内。
请问怎么写呀。谢谢各位了!

#include <stdlib.h>
#include <stdio.h>
#include <time.h>
int main()
{
int i,j;
char c;
srand(time(NULL));
while ((c=getchar())!='\n') ;
for(i=0;i<4;i++) {
j=rand()%10;
printf("\n%d",j);
}
}
//希望能帮到你!

#include<iostream>
#include <stdlib>
#include <stdio>
#include <time>
using namespace std;
int main()
{
int i,j;
char c;
srand(time(0));
while ((c=getchar())!='\n') ;
for(i=0;i<4;i++) {
j=rand()%10;
cout<<j;
}
}