求和
/* 求两个整数之和 */#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
int main()
{
int i, j;
int sum;
sum = i + j;
printf("请输入两个整数\n");
scanf("i = %d j = %d\n", i, j);
printf("sum = %d\n", sum);
return 0;
}
求随机输入两个整数的和,编译说 i j 没定义,应该怎么写呀 #include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main(){
int i, j;
int sum;
//生成随机数
srand((unsigned)time(NULL));
i = rand() %100;//取100内的随机数,0-99
j = rand() %100;//取100内的随机数,0-99
sum = i + j;
printf("i= %d j= %d\ni + j =sum = %d\n",i,j, sum);
return 0;
}
取随机数,就不用scanf
置随机数种子
取随机数,每次随机数都不一样! 谢谢老哥那如果我用scanf怎么写呀 本帖最后由 xypmyp 于 2019-9-11 10:05 编辑
#include "stdio.h"
#include "stdlib.h"
int main()
{
int i;
int j;
int sum;
printf("Please enter 2 int\n");
scanf("%d %d", &i, &j);
sum = i + j;
printf("sum = %d\n", sum);
while (getchar() != '\n');
getchar();
return 0;
}
You have to given an address for scanf() function. &i, &j 谢谢
页:
[1]