我是指针的新手,并尝试使用指向结构的指针.但在第一次进入后,我的程序崩溃了.请帮助我.
这是结构定义:
struct students{//structure students definition
char name[20];
char RegNo[15];
char CourseUnit[10];
int score;
char grade;
};
Run Code Online (Sandbox Code Playgroud)
等级不应由用户输入,而是由程序计算.
到目前为止,这是我写的代码:
int main()//start of main
{
struct students *myStudPtr,myStud[SIZE];
myStudPtr=&myStud[SIZE];
int i;//declare variables
int count;
printf("How many students do you want to deal with?\n");
scanf("%d",&i);//number of entries
for(count=1;count<=i;count++) {
printf("Enter student's name\n");
scanf("%s",&(*myStudPtr).name);
printf("Enter the student's registration number\n");
scanf("%s",&(*myStudPtr).RegNo);
printf("Enter the course unit\n");
scanf("%s",&(*myStudPtr).CourseUnit);
printf("Enter the marks scored\n");
scanf("%d",&(*myStudPtr).score);
}
printf("NAME\tREGISTRATION\t\tCOURSE UNIT\tSCORE\t\tGRADE\n");//tabulates the output
printf("%s\t", myStudPtr->name);
printf("%s\t\t", myStudPtr->RegNo);
printf("%s\t", myStudPtr->CourseUnit);
printf("%d\t\t", myStudPtr->score); …Run Code Online (Sandbox Code Playgroud) 有人问我:
用剩余元素的总和替换列表中的每个数字,列表不排序.
所以假设我们有一个数字列表{2, 7, 1, 3, 8},现在我们要用其余元素的总和替换每个元素.输出应该是:
{(7 + 1 + 3 + 8), (2 + 1 + 3 + 8), (2 + 7 + 3 + 8), (2 + 7 + 1 + 8), (2 + 7 + 1 + 3)}
== {19, 14, 20, 18, 13}
Run Code Online (Sandbox Code Playgroud)
我回答了一个明显的解决方案:
首先评估sum所有数字然后从中减去每个元素sum.所以对于上面的列表sum是2 + 7 + 1 + 3 + 8= 21,那么对于输出做如下:
{sum - 2, sum - 7, sum - 1, sum …Run Code Online (Sandbox Code Playgroud) 这是一个我不完全理解的练习测试中的问题.
对于代码片段
int i = 0, j = 0, k = 0;
for (i=-1; i<=10; ++i){
j = i; ++k;
}
Run Code Online (Sandbox Code Playgroud)
我被要求在执行代码后找到变量的值.
答案是:
i = 11 j = 10 k = 12
Run Code Online (Sandbox Code Playgroud)
我不明白怎么样,有人可以帮忙吗?
如何将字符串中"00034800"的Double 解析为Double值?最后2位数实际上是小数点,所以我要找的结果是348.00.我可以使用十进制格式这样的格式吗?
在下面的程序中,我尝试在1to 之间输入一个数字,100但是如果我在语句的执行时间内输入a 'character'或"string"(如s或sova),scanf()则会创建一个无限循环.所以我试着做....当我输入一个字符串或一个字符时,它向我显示一条消息,例如"输入了错误的值.再次输入",它将再次输入...
Thanx;
#include<stdio.h>
int main()
{
int a;
scanf("%d",&a);
while(!(a>=1&&a<=100))
{
printf("wrong value entered. enter again\n");
scanf("%d",&a);
}
printf("you enter %d. Thanxz",a);
return 0;
}
Run Code Online (Sandbox Code Playgroud) 我写了一个a.py像这样的python文件:
x = 1
def hello():
print x
hello()
Run Code Online (Sandbox Code Playgroud)
当我这样做import a,它打印的价值x
直到现在我的理解是import包括变量和函数定义,但为什么它正在执行方法hello()?
matrix = [ [1,2,3], [4,5,6], [7,8,9] ]
import pprint
pp = pprint.PrettyPrinter(indent=4)
pp.pprint(matrix)
Run Code Online (Sandbox Code Playgroud)
这不是很好的印刷品.它打印丑陋.
[[1, 2, 3], [4, 5, 6], [7, 8, 9]]
Run Code Online (Sandbox Code Playgroud)
是什么赋予了??
我有一个清单:
['8C', '2C', 'QC', '5C', '7C', '3C', '6D', 'TD', 'TH', 'AS',
'QS', 'TS', 'JS', 'KS']
Run Code Online (Sandbox Code Playgroud)
我需要得到这样的字典:(排序并不重要)
{'C': ['QC', '8C', '7C', '5C', '3C', '2C'],
'S': ['AS', 'KS', 'QS', 'JS', 'TS']
}
Run Code Online (Sandbox Code Playgroud)
码:
def parse_flush(cards):
cards = sort_by_color(cards)
flush_dic = {}
print str(cards)
count = 0
pos = 0
last_index = 0
for color in colors:
for i, card in enumerate(cards):
if card[1] == color:
count += 1
last_index = i+1
if count == 1:
pos = i
if count >= 5: …Run Code Online (Sandbox Code Playgroud) 如何制作以下列表:
nested_list = [['dave','dave'],['ian','ian'],['james','james']]
Run Code Online (Sandbox Code Playgroud)
从:
list = ['dave', 'ian', 'james']
Run Code Online (Sandbox Code Playgroud) 所以这就是我的尝试
list(itertools.combinations_with_replacement('01', 2))
Run Code Online (Sandbox Code Playgroud)
但这是产生的 [('0', '0'), ('0', '1'), ('1', '1')]
我还需要一个('1','0')元组,有没有办法让itertools也做组合和命令?
python ×5
c ×3
algorithm ×1
arrays ×1
for-loop ×1
integer ×1
java ×1
list ×1
loops ×1
pointers ×1
pretty-print ×1
puzzle ×1
python-2.7 ×1
python-3.x ×1
structure ×1