Why is it giving segmentation fault

there are lots of mistake in your code
i have corrected them and commented also

you can check

if you didn’t understand anything in this feel free to ask