Showing posts with label C PROGRAMS. Show all posts
Showing posts with label C PROGRAMS. Show all posts

Thursday, January 22

C code implementing a simple DFA

  Hello freinds,  Here I am posting my C implementation of DFA shown below. This DFA will accept any string containing 'a's and 'b' and last symbol should be 'a'. #include <stdio.h> #define TOTAL_STATES 2 #define FINAL_STATES 1 #define ALPHABET_CHARCTERS 2 #define UNKNOWN_SYMBOL_ERR 0 #define NOT_REACHED_FINAL_STATE 1 #define REACHED_FINAL_STATE 2 enum DFA_STATES{q0,q1}; enum input{a,b}; int Accepted_states[FINAL_STATES]={q1}; char alphabet[ALPHABET_CHARCTERS]={'a','b'}; int Transition_Table[TOTAL_STATES][ALPHABET_CHARCTERS]; int Current_state=q0; void DefineDFA() { Transition_Table[q0][a] = q1; ...

Monday, July 16

EIL (Engineers India Ltd) Exam questions and answer key

Hi reader, Here I'm posing some questions asked and its solution / key in EIL Management Trainee recruitment test in July 2012. All the information is collected from my freinds..!!! The Test comprises of 150 questions eacxh carrying 1 mark . for each wrong answer 0.25 marks will be deducted.Technical section(100 qustions) General AwarenessAptitude questionsEnglish.(Non technical 50 questions) General awareness section had some questions based on current affais , especiall on April 2012( note Exam held on July 2012)Sample:* Name of the British Citizn caputred by Maoists recently.* Richter scale reading of the drastic earthquake...

Tuesday, June 19

Pointers (Lecture Notes) : CUSAT s1s2 Questions

Hi friends,Here I'm posting some important concepts asked in CUSAT B Tech S1 S2 C programming examination. All the concepts are descried here in very briefly so that you can grasp it quickly.Here we go..!!! :)Pointer · Pointer is a variable that represents the location of a data item. · Address operator (&) : It evaluates the address of its operand. · Indirection Operator(*): Used to access data item referenced by a pointer. Example: Main() { Int a=3; Int *ptr; Ptr=&a; Printf(“%d %u” , *ptr, ptr); } Pointer to an array · A pointer can be used to reference an array. · The name...

Thursday, May 31

SELECTION SORT ~ CUSAT Previous Questions with Answers- C programming.( S1 S2)

Hi friends, Here I'm posting a C program implementing Selection sort. It is specially dedicated to S1 S2 B tech students because Selection sort is one of the most frequently asking questions in "Computer  Programming" exams. Hope this will be Useful  4  you.!!! :) #include<stdio.h> #include<conio.h> void main() { clrscr(); int n,i,j,temp,a[50];  printf("\nEnter how many elements="); scanf("%d",&n);  printf("\nEnter %d elements",n);// Input the elements for(i=0;i<n;i++) { scanf("%d",&a[i]); }  for(i=0;i<n-1;i++)// Sorting the elements { for(j=i+1;j<n;j++) { if(a[i]>a[j]) { temp=a[j]; a[j]=a[i]; a[i]=temp; } } } printf("\nSorted...

Monday, May 28

CUSAT Previous Questions with Answers- C programming.( S1 S2)

Hi Friends, here I'm posting one of the frequently asking question in CUSAT B tech C programming ( s 1 s2 ) and its solution: Question: Write a C program which prints all Armstrong numbers between 1 and 1000. Solution: #include<stdio.h> main() { int number, temp, digit=0, dup; printf("Printing all Armstrong numbers between 1 and 500:\n\n"); number = 1; while (number <= 500) { temp=0; dup=number; while(dup>0) { digit=dup%10; temp+=(digit*digit*digit); dup=dup/10; } if (temp==number) { printf("\nAmstrong Number:%d", temp); } number++; } getch(); } &nbs...

Monday, May 21

Generate Interesting Patterns Using C

Hi friends, Look at the "+"  pattern generated by asterisks. Quite interesting na..!! :) Lets have a look in a C program which generates exactly the same pattern.!!!!!  main() { int i,j; for ( i= 0; i < 11; ++i) { for ( j = 0; j < 11; ++j)       if (j != 5 && i !=5 )      printf(" ");        else printf ("* "); printf("\n"); } } ...

Saturday, March 17

Concatenate strings without using library functions

#include<stdio.h> main() {       char first[20], second[20],result[40];       int i,j;       printf("Enter first string:");       gets(first);       printf("Enter second string:");       gets(second);    for(i=0;first[i]!='\0';i++)result[i]=first[i];    for(j=0;second[j]!='\0';i++,j++)result[i]=second[j];              printf("%s",result);       }...

Concatenate strings using library functions

#include<stdio.h> #include<string.h> main() {       char first[20], second[20],result[40];       int i,j;       printf("Enter first string:");       gets(first);       printf("Enter second string:");       gets(second);            for(i=0;i<strlen(first);i++)result[i]=first[i];       for(j=0;j<strlen(second);i++,j++)result[i]=second[j];       result[i]='\0';            printf("%s",result);          }...

Fibonacci series using Recursion ~ C program

Here is a C program which prints a Fibonacci series up to a limit using recursion. #include<stdio.h> void fibonacci(int a, int b,int count) {      printf("%d\t",a+b);      if(--count) fibonacci(b,a+b,count); } void main() {      printf("Enter limit:");      int count;      scanf("%d", &count);       printf("0\t 1\t");      fibonacci(0,1,count-2);          }    &nbs...

Saturday, January 21

Convert Decimal Number to Binary Equivalent Using Linked list - C

Hi friends,           In this post I'll explain "how  to convert a decimal number to binary equivalent using Linked list". Usually, we use array for this purpose, but arrays are created statically and memory wastage  may occur. Linked list is a  perfect solution for this as it is created dynamically and no there is no wastage of memory also.!!!! Algorithm Initialize PREV_NODE and NODE as NULL. Input a number 'num'. if num<=0 go to step 9 PREV_NODE=NODE add (num%2) to NODE->number NODE->next=PREV_NODE num=num/2 go to step 3 if NODE is NULL go to...

Monday, November 21

Read a file and copy content to other file~ C code

This C program will read an input file and copy the content to another file with Line numbers..!! #include<stdio.h> main() {       FILE *f1,*f2;       int t=0;       char line[20];       f1=fopen("in.c","r");       f2=fopen("out.c","w");           while(!feof(f1)){       fgets(line,20,f1);       t++;       fprintf(f2,"%d  %s",t,line);       }     ...

Sunday, November 20

Quadruple ~ C code

#include<stdio.h> #include<string.h> main() {  char line[20]; int s[20]; int t=1;       int i=0;      printf("Enter string..  :"); gets(line); for(i=0;i<20;i++)s[i]=0; printf("op\ta1\ta2\tres\n"); for(i=2;line[i]!='\0';i++) { if(line[i]=='/' || line[i]=='*') {                 printf("\n"); if(s[i]==0) { if(s[i+1]==0) { printf(":=\t%c\t\t t%d\n",line[i+1],t); s[i+1]=t++; } printf("%c\t",line[i]); (s[i-1]==0)?printf("%c\t",line[i-1]):printf("t%d\t",s[i-1]); printf("t%d \t t%d",s[i+1],t); s[i-1]=s[i+1]=t++; s[i]=1; } } } for(i=2;line[i]!='\0';i++) { if(line[i]=='+' || line[i]=='-') {                ...

Tuesday, November 1

FOLLOW OF GIVEN GRAMMAR USING C PROGRAM

Hello reader, In this post I am posting implementation of FOLLOW in C. Note: If your production statements contain multiple terms connected by '|'  then give these terms as separate productions   #include<stdio.h> #include<string.h> int n,m=0,p,i=0,j=0; char a[10][10],followResult[10]; void follow(char c); void first(char c); void addToResult(char); int main() { int i; int choice; char c,ch; printf("Enter the no.of productions: "); scanf("%d", &n); printf(" Enter %d productions\nProduction with multiple terms should be give as separate productions \n", n); for(i=0;i<n;i++) scanf("%s%c",a[i],&ch); ...