Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
cstructVector
//gcc 7.4.0 //define a structure to represent a vector of integer values and write a modular program to perform the following tasks: create a vector, modify the value of a given element,multiply by a scalar value, display the vector in a sorted way(least to great) //this code is created by Rezaul Hoque on August 20,2021;contact: jewelmrh@yahoo.com //note: codes shared by Rezaul Hoque on rextester are not for sale; they are created and shared to facilitate the algorithm learning process; many like Hoque use this platform to practice programming ;Rezaul hopes his contribution helps others to fine tune their learning; #include <stdio.h> #include <stdlib.h> const int n=5; struct vector { int val; }; void mod(struct vector []); void scal(struct vector []); void sortdisp(struct vector []); void mod(struct vector vec[5]){ int pos; printf("Enter position to modify value:\n"); scanf("%2d",&pos); printf("Enter new value:\n"); scanf("%2d",&vec[pos-1].val); } void sortdisp(struct vector vec[5]){ for(int l=1;l<n;l++) { for(int j=1;j<=n-l;j++) { if(vec[j-1].val>vec[j].val){ int temp= vec[j-1].val; vec[j-1].val=vec[j].val; vec[j].val=temp; } } } for(int l=0;l<n;l++) printf("%d\t",vec[l].val); } void scal(struct vector vec[5]){ int k; printf("Enter scalar:\n"); scanf("%2d",&k); for(int l=0;l<n;l++) vec[l].val *= k; } int main (){ struct vector vec[5]; for(int l=0;l<n;l++) scanf("%2d\n",&vec[l].val); printf("Initial vector: \n"); sortdisp(vec); mod(vec); printf("Modified vector: \n"); sortdisp(vec); scal(vec); printf("After scalar multiplication: \n"); sortdisp(vec); return 0; }
run
|
edit
|
history
|
help
0
HW22
iplk
ChangeStructVal
lab5
141124_PI
Vowel Assignment
1.3 Max threads
bitwise operations
Lab 11 v1.0
gcc compiler code for delay