write a C program with a.out file. you can email me. there\'s a check file I can
ID: 3872469 • Letter: W
Question
write a C program with a.out file. you can email me. there's a check file I can email it to you that you can use to check the program is right...
Option 1: Print the author's info
Option 2: run the integer operation
Option 3: run floating point operation
Option 4: Calculate a power. When this operation is chosen you should ask for a base and exponent and then calculate the base raised to the exponent and print the result
Option 5: Calculate a factorial. When this operation is chosen you should ask for a value and calculate the factorial of this value and print the result.
Option 6: Print a multiplication table. Ask the user to enter a max value. Your program should then print a multiplication table from 0 to the max value.
Note on the multiplication table: For full credit the multiplication table should be of the following format.
If you do not include the headers then your max score for the assignment will be 9
The example uses max value 3.
The top row shows and first column show the value for the row/column of the table.
0 1 2 3
0 0 0 0 0
1 0 1 2 3
2 0 2 4 6
3 0 3 6 9
Note on power: There are no restrictions on how you calculate this portion. The intended method is to use loops, but if you use google you can find
another way to do this. Another note however: if you try what might be your first instinct, try it for a few values to see if it works the way you think
(it likely won't)
Explanation / Answer
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
void auth_info()
{
printf("Author Name : ________________ ");
printf("Version : ________________ ");
}
int operation_int(int x)
{
return x++;
}
float operation_float(int x)
{
return x*x;
}
double calc_power(int x, int y)
{
int i,res=x;
for(i=1;i<y;i++)
res=res*x;
return res;
}
unsigned long fact(int n)
{
if( n==1 ) return 1;
else return n*fact(n-1);
}
void mul_table(int n)
{
int i,j,k=0;
if ( n < 9 )
{
printf(" ");
for(k=0;k<=n;k++)
printf("%4d",k);
printf(" ");
for(i=0;i<=n;i++)
{
printf("%4d", i);
for(j=0;j<=n;j++)
printf("%4d",i*j);
printf(" ");
}
}
else
{
for(i=0;i<=n;i++)
{
for(j=0;j<=n;j++)
printf("%4d",i*j);
printf(" ");
}
}
}
int menu()
{
int ch;
printf(" =========================================== ");
printf("Option 1: Print the author's info ");
printf("Option 2: run the integer operation ");
printf("Option 3: run floating point operation ");
printf("Option 4: Calculate a power ");
printf("Option 5: Calculate a factorial ");
printf("Option 6: Print a multiplication table ");
printf("Option 7: Exit ");
printf("============================================ ");
printf("Enter your option [ 1 - 7 ] : ");
scanf("%d",&ch);
return ch;
}
int main()
{
float x;
int a,b,n;
while(1)
{
switch(menu())
{
case 1: auth_info(); break;
case 2: printf("Enter an integer :");
scanf("%d",&n);
printf("Integer operation : %d ",operation_int(n));
break;
case 3: printf("Enter a floating point value :");
scanf("%f",&x);
printf("Floating point operation : %f ",operation_float(x));
break;
case 4: printf("Enter base value : ");
scanf("%d",&a);
printf("Enter exp value : ");
scanf("%d",&b);
printf("Calculate %d power %d : %lf ",a,b,calc_power(a,b));
break;
case 5: printf("Enter a value : ");
scanf("%d",&n);
printf("%d factorial is %ld ", n,fact(n));
break;
case 6: printf("Enter a number : ");
scanf("%d",&n);
mul_table(n);
break;
case 7: exit(0);
default: printf("Invalid option choice.... ");
}
}
}
/*
output
========
lenovo@lenovo-Vbox:~/chegg$ cc menu.c
lenovo@lenovo-Vbox:~/chegg$ ./a.out
===========================================
Option 1: Print the author's info
Option 2: run the integer operation
Option 3: run floating point operation
Option 4: Calculate a power
Option 5: Calculate a factorial
Option 6: Print a multiplication table
Option 7: Exit
============================================
Enter your option [ 1 - 7 ] : 1
Author Name : ________________
Version : ________________
===========================================
Option 1: Print the author's info
Option 2: run the integer operation
Option 3: run floating point operation
Option 4: Calculate a power
Option 5: Calculate a factorial
Option 6: Print a multiplication table
Option 7: Exit
============================================
Enter your option [ 1 - 7 ] : 2
Enter an integer :5
Integer operation : 5
===========================================
Option 1: Print the author's info
Option 2: run the integer operation
Option 3: run floating point operation
Option 4: Calculate a power
Option 5: Calculate a factorial
Option 6: Print a multiplication table
Option 7: Exit
============================================
Enter your option [ 1 - 7 ] : 3
Enter a floating point value :5
Floating point operation : 25.000000
===========================================
Option 1: Print the author's info
Option 2: run the integer operation
Option 3: run floating point operation
Option 4: Calculate a power
Option 5: Calculate a factorial
Option 6: Print a multiplication table
Option 7: Exit
============================================
Enter your option [ 1 - 7 ] : 4
Enter base value : 4
Enter exp value : 2
Calculate 4 power 2 : 16.000000
===========================================
Option 1: Print the author's info
Option 2: run the integer operation
Option 3: run floating point operation
Option 4: Calculate a power
Option 5: Calculate a factorial
Option 6: Print a multiplication table
Option 7: Exit
============================================
Enter your option [ 1 - 7 ] : 5
Enter a value : 8
8 factorial is 40320
===========================================
Option 1: Print the author's info
Option 2: run the integer operation
Option 3: run floating point operation
Option 4: Calculate a power
Option 5: Calculate a factorial
Option 6: Print a multiplication table
Option 7: Exit
============================================
Enter your option [ 1 - 7 ] : 6
Enter a number : 5
0 1 2 3 4 5
0 0 0 0 0 0 0
1 0 1 2 3 4 5
2 0 2 4 6 8 10
3 0 3 6 9 12 15
4 0 4 8 12 16 20
5 0 5 10 15 20 25
===========================================
Option 1: Print the author's info
Option 2: run the integer operation
Option 3: run floating point operation
Option 4: Calculate a power
Option 5: Calculate a factorial
Option 6: Print a multiplication table
Option 7: Exit
============================================
Enter your option [ 1 - 7 ] : 7
lenovo@lenovo-Vbox:~/chegg$
*/
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.