{"id":53,"date":"2025-08-29T14:47:15","date_gmt":"2025-08-29T14:47:15","guid":{"rendered":"https:\/\/craftks.com\/wp\/?p=53"},"modified":"2025-08-29T19:53:05","modified_gmt":"2025-08-29T19:53:05","slug":"c-programming-code-for-bullet-energy-calculation","status":"publish","type":"post","link":"https:\/\/craftks.com\/wp\/c-programming-code-for-bullet-energy-calculation\/","title":{"rendered":"C Programming Code for Bullet Energy Calculation"},"content":{"rendered":"\n<p>A couple of C programs that I wrote that do the exact same thing, but are coded a bit different. They both calculate the energy of a bullet. You have to input the weight in grains and the velocity in feet per second. I am learning how to program in C and wanted to try new things.<\/p>\n\n\n\n<p>The first one uses a struct and has some functions. The second one is much simpler and just has one main function. They both should compile with any C compiler.<\/p>\n\n\n\n<pre class=\"wp-block-code has-tertiary-background-color has-background\"><code>#include &lt;stdio.h&gt;\n\nstruct bullet\n{\n  double fps;\n  double grains;\n  double energy;\n};\n\n\/\/function declarations\nvoid read(struct bullet *);\nvoid write(struct bullet);\n\nint main()\n{\n  struct bullet b;\n\n  \/\/keep looping for multiple calculations\n  while(1)\n  {\n    read(&amp;b);\n    if(b.grains == 0)\n    {\n      break;\n    }\n    \/\/calculate energy and convert to proper units\n    b.energy = (.00000444 * b.fps * b.fps * b.grains)\/2;\n    write(b);\n  }\n  return(0);\n}\n\nvoid read(struct bullet *b)\n{\n  printf(\"Bullet Grains(Enter 0 to exit): \");\n  fflush(stdout); \/\/some systems do not print line without newline character unless you use this to force it to print\n  scanf(\"%lf\", &amp;(*b).grains);\n  if((*b).grains == 0)\n  {\n    printf(\"Exiting\\n\");;\n  }\n  else\n  {\n    printf(\"Feet per sec: \");\n    fflush(stdout);\n    scanf(\"%lf\", &amp;b-&gt;fps);\n  }\n}\n\nvoid write(struct bullet b)\n{\n  printf(\"\\nEnergy in Ft-Lbs: %.1lf\\n\\n\", b.energy);\n  fflush(stdout);\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code has-tertiary-background-color has-background\"><code>#include &lt;stdio.h&gt;\n\nint main()\n{\n  double fps;\n  double grains;\n  double energy;\n\n  \/\/keep looping for multiple calculations\n  while(1)\n  {\n    printf(\"Bullet Grains(Enter 0 to exit): \");\n    fflush(stdout); \/\/some systems do not print line without newline character unless you use this to force it to print\n    scanf(\"%lf\", &amp;grains);\n    if(grains == 0)\n    {\n      break;\n    }\n    printf(\"Feet per sec: \");\n    fflush(stdout);\n    scanf(\"%lf\", &amp;fps);\n\n    \/\/calculate energy and convert to proper units\n    energy = (.00000444 * fps * fps * grains)\/2;\n    printf(\"\\nEnergy in Ft-Lbs: %.1lf\\n\\n\", energy);\n    fflush(stdout);\n  }\n  return(0);\n}<\/code><\/pre>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>A couple of C programs that I wrote that do the exact same thing, but are coded a bit different. They both calculate the energy of a bullet. You have to input the weight in grains and the velocity in feet per second. I am learning how to program in C and wanted to try [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_uag_custom_page_level_css":"","footnotes":""},"categories":[7],"tags":[],"class_list":["post-53","post","type-post","status-publish","format-standard","hentry","category-code"],"uagb_featured_image_src":{"full":false,"thumbnail":false,"medium":false,"medium_large":false,"large":false,"1536x1536":false,"2048x2048":false},"uagb_author_info":{"display_name":"Ryan","author_link":"https:\/\/craftks.com\/wp\/author\/usaryan1\/"},"uagb_comment_info":0,"uagb_excerpt":"A couple of C programs that I wrote that do the exact same thing, but are coded a bit different. They both calculate the energy of a bullet. You have to input the weight in grains and the velocity in feet per second. I am learning how to program in C and wanted to try&hellip;","_links":{"self":[{"href":"https:\/\/craftks.com\/wp\/wp-json\/wp\/v2\/posts\/53","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/craftks.com\/wp\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/craftks.com\/wp\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/craftks.com\/wp\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/craftks.com\/wp\/wp-json\/wp\/v2\/comments?post=53"}],"version-history":[{"count":2,"href":"https:\/\/craftks.com\/wp\/wp-json\/wp\/v2\/posts\/53\/revisions"}],"predecessor-version":[{"id":91,"href":"https:\/\/craftks.com\/wp\/wp-json\/wp\/v2\/posts\/53\/revisions\/91"}],"wp:attachment":[{"href":"https:\/\/craftks.com\/wp\/wp-json\/wp\/v2\/media?parent=53"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/craftks.com\/wp\/wp-json\/wp\/v2\/categories?post=53"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/craftks.com\/wp\/wp-json\/wp\/v2\/tags?post=53"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}