Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Lab 8 part 2 v.07
//gcc 5.4.0 //Problem 2: //Write a C program that replaces each occurrence of a given value in an array by a new value. //(d) Write a pseudocode for this program //(e) Implement your pseudocode in C. (due next lab) //(f) Test You program using the following: //a. The character does not exist in the array. //b. Input sting: “aaaaaaaaaaaaaaaaaaaaa” and the given character is ‘a’. // char C[5]={1,2,3,4,5}; // char x[10]; // char y[10]; // READ x // READ y // // int n=size of array; // for(i=0;i<=n;i++){ // if(C[i]==x){ // C[i]=y; // printf("%c",C[i]); // } // else{ // printf("%c",C[i]); // continue; // } // } #include <stdio.h> #include <string.h> int main(void) { char C [5]={'a','b','c','e','f'}; char x [10] ; char y [10]; int z=0; scanf("%s",x); scanf("%s",y); // printf("x=%s\ny=%s\nC[2]=%c\nz=%d\n\n",x,y,C[2],z); int n=5; for(int i=0;i<=n;i++){ //printf("%c\n",C[i]); if(C[i]==x[0]){ C[i]=y[0]; printf("%c\n",C[i]); } else if(z==n){ printf("That character isn't in the array\n"); } else{ printf("%c\n",C[i]); ++z; } } // printf("x=%s\ny=%s\nC[2]=%c\nz=%d\n\n",x,y,C[2],z); }
run
|
edit
|
history
|
help
0
second P
Sheldon 9 area none aliens as aliens and farms Lockheed Kelly and lame lead district 9
Lab 9 v0.95
C141106_TablaMultiplicar
Undefined argument processing order in C
Lab 11
B_141202_funcionesString
X=1
square pyramid
18BCE2182 ASSESS_1 Q2-3