int sameSum(float one[], float two[], int size) { float sumOne = 0; float sumTwo = 0; int i; for (i = 0 ; i < size ; i++) { sumOne = sumOne + one[i]; sumTwo = sumTwo + two[i]; } if (sumOne == sumTwo) return 1; else return 0; }
int sameSum(float[], float[], int); int main() { float first[50]; float second[50]; int flag; int i; for (i = 0 ; i < 40 ; i++) { printf("enter a number: "); scanf("%f", &first[i]); } for (i = 0 ; i < 40 ; i++) { printf("enter a number: "); scanf("%f", &second[i]); } flag = sameSum(first, second, 40); if (flag) printf("the sums are the same\n"); else printf("the sums are different\n"); }
third fourth (12) r i less! firstPsecondthird fourth
int change(char* str) { int i = 0; int numMod = 0; while (*(str+i) != '\0') { if (*(str+i) < 'a' || *(str+i) > 'z') { *(str+i) = '#'; numMod++; } i++; } return numMod; }
char str[81]; puts("enter a string"); gets(str); int num = change(str); printf("your string is: %s (%d chars replaced)\n", str, num);
int main() { char strings[20][51]; FILE *pfile = fopen("poem.dat", "r"); int i; int numstr = 0; int numrep; while (fgets(strings[i], 51, pfile) != NULL) numstr++; for (i = 0 ; i < numstr ; i++) { numrep = change(strings[i]); printf("your string is: %s (%d chars replaced)\n", str, numrep); } }
Email Me |
Office Hours |
My Home Page |
Department Home |
MCC Home Page
© Copyright Emmi Schatz 2023