Question

C programming, deterministic machine, states should be given by the user as the example below in...

C programming, deterministic machine, states should be given by the user as the example below in a dynamic array, the same for alphabet (symbols), final states, the first state given by the user will be used as initial/starting state by default, transition function same as before given by the user for that I was thinking in something as a simple table.

The user will provide an entrance string "w" and this one will print "accepted" when the last state given by the user in string "w" is a final state declared by the user before, if the last memeber of "w" is not a a final state will print "not accepted". The program should display each change of state after the user gives the entrnace string "w".

PLEASE EXPLAIN EXACTLY HOW WORKS EACH PART OF THE PROGRAM, COMMENT IT, THANKS!!!

p.d. The simplest way possible

#include<stdio.h>

int main()
{
   int n=0,i=0;
  
printf("Write the number of states: \n");
scanf("%d", &n);
char state[n][20] ;

for (i = 0; i<n; i++){
   printf("Write state # %d: \n",i);
   printf("%d",i);
scanf("%s", &state[i]);
}
  

printf("%s %s %s %s %s", state[0],state[1],state[2],state[3],state[4]);
return 0;
  
}

Homework Answers

Answer #1

#include<stdio.h> //Header files

int main() //Main function starts here and it runs first

{

int n=0,i=0; //Integers n and i were declared as 0.

printf("Write the number of states: \n"); //Printing given string

scanf("%d", &n); // Taking input from user that number of states into n variable.

char state[n][20] ; //Initializing a character array as state[][] with dimensions n and 20.

for (i = 0; i<n; i++){ //Initializing for loop from 0 to n

printf("Write state # %d: \n",i); //Printing the given string

printf("%d",i); //Printing the integer i

scanf("%s", &state[i]); //Taking input string from user into state[i] i.e., we are taking string directly into state[i][0],state[i][1],state[i][2]............state[i][19].

}

printf("%s %s %s %s %s", state[0],state[1],state[2],state[3],state[4]); //Here we are printing in string format where state[0] prints state array first row totally and state[1] prints second row continues upto 5th row.

return 0;

} //In this program we have taken character array and we are taking inputs in string format and they will be stored in charater format in the memory and if we print state[0][0]state[0][1]state[0][2]state[0][3]state[0][4].......state[0][19] it also prints first row of array i.e., same as state[o]. But if we take 2Dinteger array and if we print int[0] it prints address of first integer of first row and int[1] prints first integer of second row.

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
C - Language Write an expression that executes the loop while the user enters a number...
C - Language Write an expression that executes the loop while the user enters a number greater than or equal to 0. Note: These activities may test code with different test values. This activity will perform three tests, with user input of 9, 5, 2, -1, then with user input of 0, -17, then with user input of -1. Also note: If the submitted code has an infinite loop, the system will stop running the code after a few seconds,...
/*C PROGRAMMING: HOW TO INSERT ERROR BELOW CODE? QUESTION: This program reads integers from standard input....
/*C PROGRAMMING: HOW TO INSERT ERROR BELOW CODE? QUESTION: This program reads integers from standard input. The first integer indicates the number of values that will follow. Read that many values, and return their sum, ignoring any additional values that may follow. However, if there are fewer integers than specified in the input, print "Error" and terminate. Hint: int n, success; ... success = scanf("%d", &n); // FIRST INTEGER INPUT reads an integer from stdin, returning 1 if the integer...
The code is in C programming language pls convert it into python. Thanks. Program --> #include...
The code is in C programming language pls convert it into python. Thanks. Program --> #include <stdio.h> #include <stdlib.h> void main() { //declare variables FILE *fileptr; char filename[15]; char charRead; char filedata[200],searchString[50]; int i=0,j=0,countNoOfWord=0,count=0; //enter the filename to be opened printf("Enter the filename to be opened \n"); scanf("%s", filename); /* open the file for reading */ fileptr = fopen(filename, "r"); //check file exit if (fileptr == NULL) { printf("Cannot open file \n"); exit(0); } charRead = fgetc(fileptr); //read the string...
C CODE PLZ! Need all TO DO sections finished thanks #include <stdio.h> int main(int argc, char...
C CODE PLZ! Need all TO DO sections finished thanks #include <stdio.h> int main(int argc, char **argv) { const int BUF_LEN = 128; char str[BUF_LEN]; int i; char c; int is_binary; int d, n; /* Get the user to enter a string */ printf("Please enter a string made of 0s and 1s, finishing the entry by pressing Enter.\n"); for (i=0; i<BUF_LEN-1; i++) { scanf("%c", &c); if (c == '\n') { break; } str[i] = c; } str[i] = '\0'; /*...
debug code on C(not C+ or C++) I try to fix by myself, node part show...
debug code on C(not C+ or C++) I try to fix by myself, node part show error. This program should work for scan 5 ints from the user Using those 5 ints, it require construct a linked list of 5 elements. After this, it sould prntf of the list using the PrintList. #include <stdio.h> struct Node{    int data;    Node* next; }; int main(void){    struct Node first = {0, 0};    struct Node* second = {0, 0};   ...
USE C programming (pls label which file is libcipher.h and libcipher.c) Q4) A shift cipher is...
USE C programming (pls label which file is libcipher.h and libcipher.c) Q4) A shift cipher is one of the simplest encryption techniques in the field of cryptography. It is a cipher in which each letter in a plain text message is replaced by a letter some fixed number of positions up the alphabet (i.e., by right shifting the alphabetic characters in the plain text message). For example, with a right shift of 2, ’A’ is replaced by ’C’, ’B’ is...
This is a debugging question. Please write comments where it is fixed. Thanks. q7.4 Fix the...
This is a debugging question. Please write comments where it is fixed. Thanks. q7.4 Fix the errors in the code (in C) //This program is supposed to scan 5 ints from the user //Using those 5 ints, it should construct a linked list of 5 elements //Then it prints the elements of the list using the PrintList function #include <stdio.h> struct Node{ int data; Node* next; }; int main(void){ struct Node first = {0, 0}; struct Node* second = {0,...
create case 4 #include <stdio.h> int main(void) { int counter; int choice; FILE *fp; char item[100];...
create case 4 #include <stdio.h> int main(void) { int counter; int choice; FILE *fp; char item[100]; while(1) { printf("Welcome to my shopping list\n\n"); printf("Main Menu:\n"); printf("1. Add to list\n"); printf("2. Print List\n"); printf("3. Delete List\n"); printf("4. Remove an item from the List\n"); printf("5. Exit\n\n"); scanf("%i", &choice); switch(choice) { case 1: //add to list //get the input from the user printf("Enter item: "); scanf("%s", item); //open the file fp = fopen("list.txt","a"); //write to the file fprintf(fp, "\n%s", item); //close the file...
q7.3 Fix the errors in the code (in C) //This program uses a function called CharacterScan...
q7.3 Fix the errors in the code (in C) //This program uses a function called CharacterScan to read a char from the user //The function must take an int pointer as a parameter //The program should print the char and ascii code for each character the user enters //The program should only exit whe nthe user enters escape #include <stdio.h> char CharacterScan(int*); int main(void){ while(1){ int aCode; int* iPtr; char* c = CharacterScan(iPtr); if(aCode) break; else printf("%c is ASCII code...
I am trying to write a program that reads a string (in my case a domain...
I am trying to write a program that reads a string (in my case a domain name). What I am struggling with is how to traverse through the array and see if there are any invalid characters in the string such as a semi colon or a space. Here is what I have as of now. #include <stdio.h> int main() {    char min[1];    char max[253];    char domain[253]; printf("Enter a domain: "); scanf("%s", domain);    return 0; }
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT