Please help, writing this program in C, not C++, Objective: 1. get familiar with
ID: 3590400 • Letter: P
Question
Please help, writing this program in C, not C++,
Objective: 1. get familiar with the process of completing a programming project in UNIX 2. declare and use of variables of basic types: int, char, float, and array 3. learn the basic human-computer interface with standard IO (printf, scanf) 4. use basic if and if-else statements for program selection 5. use while loop for program repetition 6. practice on designing and implementing algorithm/strategy to solve problems Description: In this project, you will design and implement a program that prints out numbers, both integers and floating point (real numbers), in a variety of formats, using only the basic sd and &c; format specifiers. Using other format specifiers (such as %nd. %) will result in a loss of points. The program will prompt the user to choose from a menu of options and from there your program will interact with the user to get input number and print it out in the required format.Explanation / Answer
#include<stdio.h> //preprocessor directive
#include<math.h>
int count(float no)
{
// this function counts number of values present after decimal point
int cou=0;
return cou;
}
void main()
{
float a[20]; //declare a array of size 20
int a1[20],a2[20]; //these are used to store the numbers of scanned array
int i,n,m,c;
scanf("%d",&m); //to check if option 5 is presses or not
if(m==5)
{
printf("Please enter the number of values you would like to print ");
scanf("%d",&n);
for(i=0;i<n;i++)
{
scanf("%d",&a[i]); //this scans all the elements
c=count(a[i]);
if(c==0)
{
a2[i]=0;
}
else
{
a2[i]= (a[i] - (int)a[i]) * pow(10,c); //i am sorry this is where loigic is gone wrong logic to store the digits after decimal integer in a integer array
}
a1[i] = (int)a[i]; //(this stores the integer pass of number by using type casting
for(i=0;i<n;i++)
{
printf("%d . %d ",a1[i],a2[i]); //this present the output in the desired format
}
}
}