int a[8]; int *p = a+4; |
int a[8]; int *p, *q; p = a+4; q = p-2; |
int a[8]; int *p, *q; p = a+4; q = p-2; |
int a[8]; int *p, *q; p = a+4; q = p-2; |
int a[8]; int *p1 = a+2; int *p2; |
int a[8]; int *p = &a[1]; int *q = &a[4]; |
#include <stdio.h>
int inputScores (double *);
void printStats (double *, int);
int main (void)
{
double scores[250];
int numScores;
printf ("Scores: a program to compute grade statistics.\n");
printf ("Enter all scores, finish with 1:\n\n");
numScores = inputScores (scores);
printStats (scores, numScores);
}
|
Scores: a program to compute grade statistics. Enter all scores, finish with -1: 57 85 97 16 82 -1 Average: 61.4 Median: 82 Standard Deviation: 32.2 |
void printStats (double *, int); |
void printStats (double *scores, int numScores)
{
...
}
|
double computeAverage (double *, int);
double computeMedian (double *, int);
double computeStandardDev (double *, int);
void printStats (double *scores, int num)
{
double average;
double median;
double stdDev;
average = computeAverage (scores, num);
median = computeMedian (scores, num);
stdDev = computeStandardDev (scores, num);
printf ("Average: %5.1f\n", average);
printf ("Median: %5.1f\n", median);
printf ("Standard deviation: %5.1f\n", stdDev);
}
|
/*
* computeAverage: calculate and return the average
* of the numbers in an array
*/
double computeAverage (double *array, int size)
{
int i;
double sum = 0.0;
for (i = 0; i < size; ++i)
sum += array[i];
return sum/size;
}
|
int inputScores (double *); |
int inputScores (double *scores)
{
...
}
|
int inputScores (double *scores)
{
int count = 0;
double score;
scanf ("%lf", &score);
while (score >= 0.0) {
scores[count] = score;
count += 1;
scanf ("%lf", &score);
}
return count;
}
|
int inputScores (double *scores)
{
int count = 0;
double score;
scanf ("%lf", &score);
while (score >= 0.0) {
scores[count++] = score;
scanf ("%lf", &score);
}
return count;
}
|
int inputScores (double *scores)
{
int count = 0;
double score;
scanf ("%lf", &score);
while (score >= 0.0) {
scores[count++] = score;
scanf ("%lf", &score);
}
return count;
}
|
char carray[14]; |
char carray[14] = {'H', 'e', 'l', 'l', 'o'};
|
char carray[] = {'H', 'e', 'l', 'l', 'o'};
|
char cstring[] = {'H','e','l','l','o','\0'};
|
printf ("Hello, world!\n");
|
extern int pclose(FILE *); extern FILE * popen(const char *, const char *); extern int printf(const char *, ...); extern int putc(int, FILE *); extern int putchar(int); |
extern int printf(const char *, ...); |
char cstring[] = {'H','e','l','l','o','\0'};
|
char cstring[] = "Hello"; |
char cstring[] = "Hello"; |
char *pstring = "Hello"; |
char cstring[] = "Hello"; |
char *pstring = "Hello"; |
char *pstring = "Hello"; |
char *pstring = "Hello"; |
char cstring[] = "Hello"; char *pstring = "Hello"; |
char cstring[] = "Hello"; char *pstring = "Hello"; |
printf (cstring); printf (pstring); |
char *dayName[] = {"Sunday", "Monday", "Tuesday",
"Wednesday", "Thursday", "Friday", "Saturday"};
|
printf ("%s\n", dayName[i]);
|