What is wrong with the following program? Explain how you will fix it in the code.
#include int main()
{ int i; int *ptr = &i;
scanf("%d", &ptr);
printf("The value of i is: %d\n", *ptr);
return 0;
}
What is wrong with the following program? Explain how you will fix it in the code....
Programming C....... function code is clear but compile is wrong .. I input 8 and compiled 2 0 1 1 2 3 5 8 13.. look first number 2 is wrong. The correct answer 8 is 0 1 1 2 3 5 8 13 21.. Need fix code to compile correctly.. Here code.c --------------------------------------------------------------------------------------------------------------------- #include <stdio.h> #include <math.h> int fibonacciIterative( int n ) { int fib[1000]; int i; fib[ 0 ] = 0; fib[ 1 ] = 1; for (...
Fix the code. Use Valgrind to compile below code with no warning and no memory error. Also give a comment about how you fix the code. gcc -std=c99 -pedantic -Wall -Wextra -ftrapv -ggdb3 $* -o question5 question5.c && ./question5 gcc -std=c99 -pedantic -Wall -Wextra -ftrapv -ggdb3 -fsanitize=address -o question5 question5.c && ./question5 Both of these should get the same output . For example if we input 65535 4 3 2 1 it should give us a output with What is...
C program help 2. For the following code: #include "stdafx.h" struct State char out struct State *next[2]; b; typedef struct State States; #define STe &FSM[8] #define ST1 &FSM[1] #define ST2 &FSM[2] States FSM[3] { {"L', {STe, ST1)), {'1', {STe, sT2)), {ST1, = {.2', ST2))); int main() States "ptr &FSM[e]; int in; while (1) printf("cIn", ptr->out); printf("Enter a e or 1 to operate this machine: "); scanf s("Xd", &in); ptr ptr->next[in]; return e; Draw the finite state machine diagram for this...
The following code is a C Program that is written for encrypting and decrypting a string. provide a full explanation of the working flow of the program. #include <stdio.h> int main() { int i, x; char str[100]; printf("\n Please enter a valid string: \t"); gets (str); printf ("\n Please choose one of the following options: \n"); printf ("1 = Encrypt the given string. \n"); printf("2 = Decrypt the entered string. \n"); scanf("%d",&x); // using switch case statements switch (x) {...
Explain the following code, line by line. As well as the is going on over all. #include <stdio.h> int main() { int a[30]; int i,j,lasti; int num; lasti=0; // scanf the number scanf("%d",&a[0]); while (1) { // sacnf the new number printf("Enter another Number \n"); scanf("%d",&num); for(i=0;i<=lasti;i=i+1) { printf("%d \n",a[i]); // we check if the num that we eneterd is greter than i if(a[i] > num) { for(j=lasti; j>= i;j--) { a[j+1]=a[j]; } a[i]=num; lasti++; break; } }...
Consider the following C codes to compute the gcd of two integers. /// code 1 #include <stdio.h> int gcd(int a, int b) { while (a != b) { if (a > b) a = a - b; else b = b - a; } return a; } /// code 2 #include <stdio.h> int getint() { int i; scanf("%d", &i); return i; } void putint(int i) { printf("%d\n", i); } int main()...
c++ What is wrong with the following code segment? Fix the error and explain why its wrong. int* m[3]; for(int i = 0; i < 3; i++) m[i] = new int[4]; delete [] m;
I am trying to add a string command to my code. what am i doing wrong? #define _CRT_SECURE_NO_WARNINGS #define _USE_MATH_DEFINES #include <stdio.h> #include <string.h> #include <math.h> int main(void) { int i, j; int rowA, colA, rowB, colB; int A[10][10], B[10][10]; int sum[10][10]; char str1[10]; printf("This is a matrix calculator\n"); //read in size from user MATRIX A printf("Enter in matrix A....\n"); printf("\t#row = "); scanf("%d", &rowA); printf("\t#col = "); ...
i need flowchart for the following c code #include <stdio.h> int main() { int n, i, sum = 0; printf("Enter an integer: "); scanf("%d",&n); i = 1; while ( i <=n ) { sum += i; ++i; } printf("Sum = %d",sum); return 0; }
/* • 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"); ////////////////////////////////////////////////////////////////////////// ////////////// ...