/*
• The following code consists of 5
parts.
• Find the errors for each part and fix them.
• Explain the errors using comments on top of each
part.
*/
#include <stdio.h>
#include <string.h>
int main( ) {
//////////////////////////////////////////////////////////////////////////
////////////// Part A. (5
points)
//////////////////
int g(void)
{
printf("%s", Inside function g\ n " );
int h(void)
{
printf(" % s ", Inside function h\ n
");
}
}
printf("Part A: \n ");
g();
printf(" \n");
//////////////////////////////////////////////////////////////////////////
////////////// Part B. (5
points)
//////////////////
int sum( int x, int y )
{
int result;
result = x + y;
}
printf("Part B: % d \n", sum(5,3));
//////////////////////////////////////////////////////////////////////////
////////////// Part C. (5
points)
//////////////////
void f( float a );
{
float a;
printf( "%f", a );
}
printf("Part C: % 1f \n", f(1.1));
//////////////////////////////////////////////////////////////////////////
////////////// Part D. (5
points)
//////////////////
#include <stdio.h>
#include <string.h>
int main( ) {
int sum( int n )
{
if ( 0 == n )
{
return 0;
}
else
{
n + sum( n - 1 );
}
}
printf("Part D: % d \n", sum(3));
return 0;
}
//////////////////////////////////////////////////////////////////////////
////////////// Part E. (5
points)
//////////////////
void product( void )
{
int a, b, c, result;
printf( "%s", "Enter three integers: " )
scanf( "%d%d%d", &a, &b, &c );
result = a * b * c;
printf( "Result is: %d", result );
return result;
}
printf( "Part E: %d", product ());
return 0;
}
////////////////////////////////////////////////////////////////////////// int g(void) printf("Part A: \n "); ////////////////////////////////////////////////////////////////////////// In part one error is becase of printf("%s", Inside function g\ n " ); here we are trying to print string but Inside function g\ n " it is not a string string should in betwenn " and " so correct syantax is printf("%s"," Inside function g\ n " ); for part 1 correct code is:
////////////////////////////////////////////////////////////////////////// int g(void)
////////////////////////////////////////////////////////////////////////// |
There is know error in part B.Everything works fine |
In part c there lot of error 1)void f( float a ); here we are trying to create a function f but we are put ; at the end so it doesn't act as a function it acts as a statement so we have to remove semicolon 2)float a; we are alredy passing a as an argument so it leads to redeclaration to avoid this eirther we have to remove float a from functino body or we have to change it's name. 3)printf("Part C: % 1f \n", f(1.1)); Part C: float f( float a )
|
D) There is no error in part D internally.But if we observe it it has a main method. we are writing part D inside a main method.A c programm doesn't contain two main methods. we can resolve it by 1) writing part D in a separate file |
void product( void ) { int a, b, c, result; printf( "%s", "Enter three integers: " ) scanf( "%d%d%d", &a, &b, &c ); result = a * b * c; printf( "Result is: %d", result ); return result; } printf( "Part E: %d", product ()); In part E 1) printf( "%s", "Enter three integers: " ) there is no semicolon at the end so insert ; at the end. 2)void product( void ) here we are returning void but return result; in function body we are returning an int type. so change it return type to int. int product(void); Part E: int product( void ) printf( "Part E: %d", product ()); |
//entire code for part a,b,c,e
////////////////////////////////////////////////////////////////////////// int g(void) printf("Part A: \n ");
//////////////////////////////////////////////////////////////////////////
printf("Part B: % d \n", sum(5,3));
printf( "%f", a );
////////////// Part E. (5 points) //////////////////
printf( "Part E: %d", product ());
|
//////////////////////////////////////////////////////////////////////////
int sum( int n ) printf("Part D: % d \n", sum(3));
|
/* • The following code consists of 5 parts. • Find the errors for each part...
answer two question,each question has 3syntax errors,find it. 1(a) The following segment of code contains at least three (3) syntax errors that will compilation to fail with errors. Identify each of these errors and specify the solution. [2 marks each, 6 marks in total] cause #include <stdio.h> void main (void) float height; float area; printf "input height of the rectangle: ") scanf( "%f", &height) printf"input length of the rectangle: scanf"", &length); height length; area printf( area of rectangle %f high...
In C language 5. What is the OUTPUT of each of these programs? If you aren't confident of an answer, type mpile and run the program to test it. (a) <stdio.h> #include int main main int count; int sum0; for (count 1; count10; count++) sum sum+ count; for count printf("sum= %d\n", return 0; sum); )main (b) #include int main ) <stdio.h> main/ int count; int sum -0 for (count 1 count10; count 2) sum sum + count; for count print...
PUT INTO PYTHON CODE #include <stdio.h> #include <float.h> int main(void) { float a = 1; float b = 0.5; float c = a + b; int bits = 0; while (c != a) { bits = bits + 1; b = b / 2; c = a + b; } printf("%d\n",bits); return 0; }
Please explain how these code run for each line #include<stdio.h> #include<string.h> /** * Part A */ struct myWord{ char Word[21]; int Length; }; int tokenizeLine(char line[], struct myWord wordList[]); void printList(struct myWord wordList[], int size); void sortList(struct myWord wordList[], int size); /** * main function */ int main() { struct myWord wordList[20]; char line[100]; printf("Enter an English Sentence:\n"); gets(line); int size = tokenizeLine(line, wordList); printf("\n"); printf("Unsorted word list.\n"); printList(wordList, size);...
PART FOUR:(20 points) Predict the output that would be shown in the terminal window when the following program fragments are executed 1. Assume that an int variable takes 4 bytes and a char variable takes 1 byte #include<stdio.h> int main() int A[]-{10, 20, 30, 40); int *ptrl - A; int ptr2 = A +5; printf("The Resull: %d\n".(ptr2-ptrl)); printf("The Resul2: %d\n".(char*)ptr2-(char*)ptr); return 0; 2. What does the following program print? #include <stdio.h> int main(void) unsigned int x 1: unsigned int total...
I need the pseudocode for this c program source code. #include<stdio.h> void printarray(int array[], int asize){ int i; for(i = 0; i < asize;i++) printf("%d", array[i]); printf("\n"); } int sum(int array[], int asize){ int result = 0; int i = 0; for(i=0;i < asize;i++){ result = result + array[i]; } return result; } int swap( int* pA,int*pB){ int result = 0; if(*pA > pB){ int tamp = *pA; *pA = *pB; *pB = tamp; result = 1; } return result;...
I must call multiply, divide and remainder functions inside of SUBTRACT function.. I am stuck at this point. Thank you #include<stdio.h> int getDifference(int a, int b); int main() { int a, b, result, multiply, divide, rem; printf("Enter the two integer numbers : "); scanf("%d %d", &a, &b); //Call Function With Two Parameters result = getDifference(a, b); printf("Difference of two numbers is : %d\n" , result); return (0); } int getDifference(int a, int b) { int c, multiply; float...
#include <stdio.h> void printHelp () { printf ("\n"); printf ("a: a(x) = x*x\n"); printf ("b: b(x) = x*x*x\n"); printf ("c: c(x) = x^2 + 2*x + 7\n"); printf ("q: quit\n"); } void a(float x) { float v = x*x; printf (" a(%.2f) = %.2f^2 = %.2f\n", x, x, v); } // end function a void b(float x) { float v = x*x*x; printf (" a(%.2f) = %.2f^3 = %.2f\n", x, x, v); } // end function b void c(float x)...
10 What does the last printf in this code print to the screen? a)n-7 b)n- 0 c)n--1 d) None of the above 鬐include< stdio. h> int main) int n-0 for (n-7: n<O; n-- printf (n") printf ("n *%d", n); - return 11-What does the code print to the screen? 鬐include< stdio.h> void fun (int) int main) b) 8 d) None of the above fun (3) return void fun (int a) int x-10 while(a !_ 3 x > s} if a...
C programming problem please help my computer crashed what is the output of each program ? (c) #include <stdio.h> int main() { /* main */ int f3, t = 9; int func3 (int x); printf("Inside main, t = $d\n", t); f3 - func3(t); printf("Inside main, f3 = %d\n", f3); return 0; } /* main */ int func3 (int x) { /* func3 */ printf("Inside func3, X = %d\n", x); return x; } /* func3 */ (d) #include <stdio.h> int main()...