learn-C-09

char input[81];    //holds a string as long as 80 characters 
char *iptr=input;  //also could have done this: char *iptr=&input[0];
gets(iptr);       //makes sure that iptr points to the string typed by the user.

Read More

learn-C-08

#include
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
int main(void) {
char letters[50];
char userInit;
int ctr,n1,numInits=0;
for(ctr=0;ctr<50;ctr++){
letters[ctr]=65+(rand()%26);
}
printf("What is your first initial?\n");
userInit=getchar();
n1=getchar();
for(ctr=0;ctr<50;ctr++){
if(letters[ctr]==userInit){
numInits++;
}
}
printf("\nIn the array, there were %d of your initials.\n", numInits);
return 0;
}

Read More

learn-C-07

#include<math.h> po2=pow(2.0,2.0); printf("2 raised to the 2nd power is %.0f\n", po2); s2=sqrt(49); printf("The square root of 49 is %.0f\n", s2); si628=sin(6.28); print("The sine of 6.28 is %f\n", si628); r01=rand(); printf("A random number from 1 to 32767 is %f\n", r01);

Read More