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) {...
What is wrong with this computer science program? I have an error at line 22, saying "identifier 'gets' is undefined". How do I fix this? #include<stdio.h> #include<string.h> int countvowel(char* str) { int i = 0, count = 0; while (str[i] != '\0') { if (str[i] == 'A' || str[i] == 'E' || str[i] == 'I' || str[i] == 'O' || str[i] == 'U' || str[i] == 'a' || str[i] ==...
Hi, I'm trying to write C code that will print the odd abundant numbers between 1 and 5000 and I've written a program for it but it doesn't work. If you would be able to help me fix it or point out where I went wrong that would be awesome. # include <stdio.h> int main () { int getSum(int n) int i, n, j, sum = 0; /* print initial statement to give context of program*/ printf("...
Hello, I need help with the following C code. This program asks the user to enter three numbers and outputs the sum on the screen , all im trying to do is have the program reprompt the user for a number if anything other than a number is entered for each of the entries. I wanted to use do while for each of the functions but that did not work for example: Enter Number 1: 2 Enter Number 2: Hello...
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; } }...
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;
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()...