What is the algorithm using c to delete duplicate elements from an array?
To detect the duplicate, you will have to write a nested loop that compares each element with all the previous elements.
To actually delete the duplicate, once you find it, you have to move over all the elements after the duplicate. If the order of the elements doesn't matter, it is faster to just move the LAST array element, overwriting the duplicate element. Use a variable to keep track how many elements of the array are "usable". For example, if your array had 10 elements, and you delete 1, the array size will still be 10... but (after moving the elements over) only 9 of those elements have useful information.
Find the absolute value write a program of a no entered through the keyboard?
#include<stdio.h>
#include<conio.h>
int main ()
{
int num;
printf("enter the number");
scanf("%d",&num);
if(num<0)
num=(-1)*num;
printf("absolute value=%d",num);
getch();
return 0;
}
Add two matrices by using arrays and functions?
#include
#include
void main()
{ int a[10][10],b[10][10],c[10][10];
printf("\nEnter the Row:");
scanf("%d",&r);
printf("\nEnter the Columns:");
scanf("%d",&c);
for(i=0;i
printf("\nThe Result is:\n");
for(i=0;i
printf("\n");
}
getch();
}
Syntactical errors may happened.
What are the example of turbo c with using scan and print function?
#include<stdio.h>
Void main()
{
int a,b;
printf("Enter a Number: "); // for print function as an out-put
scanf("%d",&a); //for scan function as in input
/* Here we can use print function once again as: */
a=a++;
printf("%d",a);
}
Bluej program-read a string and check if the given string is a palindrome?
import java.util.Scanner;
public class Palindrome{
public static void main(String[] args){
String front;
String back ="";
char[] failure;
String backwards;
Scanner input=new Scanner(System.in);
System.out.print("Enter a word: ");
front=input.next();
front=front.replaceAll(" ", "");
failure=front.toCharArray();
for (int i=0; i<failure.length; i++){
back=failure[i] + back;
}
if (front.equals(back)){
System.out.print("That word is a palindrome");
}else
System.out.print("That word is not a palindrome");
}}
What is the difference between implementation and algorithm?
An algorithm is a instruction for solving a problem. It is typically illustrated using prose, pseudo code or flowcharts, but other methods exist. The algorithm is the "here's how it's going to work" part of the solution.
An implementation (of an algorithm) is a specific expression of this algorithm, using a specific programming language or any other suitable means. The implementation is the "here's how I've done it" part of the solution.
What are the differences between puts and fputs?
All three functions output a single character, either to the console or to a FILE. putc() takes a character argument, and outputs it to the specified FILE. fputc() does exactly the same thing, and differs from putc() in implementation only. Most people use fputc(). putchar() writes the character to the console, and is the same as calling putc(c, stdout). puts() is a multicharacter function and putchar() is single character function
What is the difference between function calls and Interrupt Service routine?
An Interrupt is a feature of the processor hardware; eg, on an 8051, and interrupt can occur when the UART receives a character.
A Function is a construct of the 'C' programming language - it represents a piece of executable code that can be "called" by other parts of the program.
(other languages have similar constructs)
A real time operating system needs to be "event driven" and have the ability to perform certain tasks in a very timely manner.
Most true real-time operating systems use interrupts to handle events as they occur, such as a time-critical input message from a serial port or a digital I/O event from some peripheral hardware.
Next, there should be some kind of prioritization, meaning that one process may be time critical, such as controlling the rods at a nuclear reactor, but other processes might be a little less critical, such as dimming the hallway lights at the reactor facility after hours.
Third, there must be a mechanism in place for "multitasking", meaning that the computer must be able to switch between multiple active processes. Some operating systems create a process "stack" for each process, and if a high priority process is to be activated to handle an event, the operating system simply switches control to the higher priority process by loading the current data from the process stack. A true real time operating system can do that in just a couple clock ticks.
How do you write a C program to implement stacks through arrays?
#include<stdio.h>
#include<conio.h>
#define MAX 10
typedef struct stack
{
int item[MAX];
int Top;
}stk;
void createstack(stk *);
void push(stk *,int);
int pop(stk *);
int isempty(stk *);
int isfull(stk *);
int main()
{
int choice;
int value;
stk s;
createstack(&s);
do{
clrscr();
printf("\n\t Main Menu");
printf("\n1. Push");
printf("\n2. Pop");
printf("\n3. Exit");
printf("\nEnter your choice=");
scanf("%d",choice);
switch(choice)
{
case 1: printf("\nEnter the value to be inserted=");
scanf("%d",value);
push(&s,value);
getch();
break;
case 2: value=pop(&s);
if (value==0)
printf("\n Underflow: Stack is empty");
else
printf("\n Popped Element is %d",value)
getch();
break;
case 3: exit();
defualt: printf("\nInvalid choice");
}
}while(1);
return 0;
}
void createstack(stk *s)
{
s->Top=-1;
}
void push(stk *s,int element)
{
if(isfull(s))
{
printf("\nOverflow: Stack is full");
return;
}
s->Top++;
s->item[s->Top]=element;
printf("\nValue is pushed onto the stack");
}
int pop(stk *)
{
int popped;
if (isempty(s))
return 0;
popped=s->item[s-.Top];
s->Top-;
return popped;
}
int isempty(stk *)
{
return s->Top==-1;
}
int isfull(stk *)
{
return s->Top==MAX-1;
}
How do you write a simulation program in C?
Its quite easy to code an simulation program in c. An Sample Simulation program in c for Traffic Signal
#include<graphics.h> #include<conio.h> #include<dos.h> #include<stdlib.h> main() { int gd = DETECT, gm, midx, midy; initgraph(&gd, &gm, "C:\\TC\\BGI"); midx = getmaxx()/2; midy = getmaxy()/2; setcolor(RED); settextstyle(SCRIPT_FONT, HORIZ_DIR, 3); settextjustify(CENTER_TEXT, CENTER_TEXT); outtextxy(midx, midy-10, "Traffic Light Simulation"); outtextxy(midx, midy+10, "Press any key to start"); getch(); cleardevice(); setcolor(WHITE); settextstyle(DEFAULT_FONT, HORIZ_DIR, 1); rectangle(midx-30,midy-80,midx+30,midy+80); circle(midx, midy-50, 22); setfillstyle(SOLID_FILL,RED); floodfill(midx, midy-50,WHITE); setcolor(BLUE); outtextxy(midx,midy-50,"STOP"); delay(2000); graphdefaults(); cleardevice(); setcolor(WHITE); rectangle(midx-30,midy-80,midx+30,midy+80); circle(midx, midy, 20); setfillstyle(SOLID_FILL,YELLOW); floodfill(midx, midy,WHITE); setcolor(BLUE); outtextxy(midx-18,midy-3,"READY"); delay(2000); cleardevice(); setcolor(WHITE); rectangle(midx-30,midy-80,midx+30,midy+80); circle(midx, midy+50, 22); setfillstyle(SOLID_FILL,GREEN); floodfill(midx, midy+50,WHITE); setcolor(BLUE); outtextxy(midx-7,midy+48,"GO"); setcolor(RED); settextstyle(SCRIPT_FONT, HORIZ_DIR, 4); outtextxy(midx-150, midy+100, "Press any key to exit..."); getch(); closegraph(); return 0; }
How do you install CCS V4.088?
Install CCS V4 then install the following updates one after the other:
pcbupd.exe
pcmupd.exe
pchupd.exe
pcwhupd.exe
pcdupd.exe
pcwupd.exe
setup_icd.exe
Replace a character by another character in a given string?
To replace a single, specified character with another in a given string, one possibility is ...
char *pszString; /* pointer to string */
int offset; /* offset of desired character */
... initialize pszString and offset
*(pszString+offset) = 'A'; /* or whatever new value you want */
Obviously, this is a simple example, and it does not consider if offset is greater than the size of the array.
If you want to replace every occurence of a character with another, here is another possibility, one that also handles string length ...
char *pszString; /* pointer to string */
char* pszTemp; /* temporary scanning pointer */
char cOldChar; /* character to change */
char cNewChar; /* new character */
... initialize pszString, cOldChar, and cNewChar
for (pszTemp = pszString; *pszTemp != '\0'; pszTemp++) { /* scan */
if (*pszTemp == cOldChar) *pszTemp = cNewChar; /* conditionally replace */
}
Java Solution// Replace all 'e' characters with 'i' characters in String str
str.replaceAll("e", "i");
Ascending and descending oreder using functions in c language?
Well There is no "functions"
but there is a way:
#include
main()
{
int n,num;
printf("Enter Number");
scanf("%d",n);
num = n%2;
if(n==1)
{
printf("Your number is Odd");
}
else
{
printf("Your number is Even");
}
return 0;
}
How do you write flag status in program?
for example:
int flag= 0; /* 0/1 = unset/set */
...
printf ("flag=%d which means %s\n", flag, flag? "set": "unset");
What are the functions for Ubuntu?
Ubuntu is a free, supported debian/linux implementation of Unix. As such, you can do nearly anything that you can do in Unix in Ubuntu.
C program to calculate first symbol of given grammar?
#include"stdio.h"
#include<conio.h>
#define max 10
#define MAX 15
char array[max][MAX],temp[max][MAX];
int c,n,t;void fun(int,int[]);
int fun2(int i,int j,int p[],int key)
{
int k;
if(!key)
{
for(k=0;k<n;k++)
if(array[i][j]==array[k][0])
break;
p[0]=i;p[1]=j+1;
fun(k,p);
return 0;
}
else
{
for(k=0;k<=c;k++)
{
if(array[i][j]==temp[t][k])
break;
}
if(k>c)return 1;
else return 0;
}
}
void fun(int i,int p[])
{
int j,k,key;
for(j=2;array[i][j]!='\0';j++)
{
if(array[i][j-1]=='/')
{
if(array[i][j]>='A'&&array[i][j]<='Z')
{
key=0;
fun2(i,j,p,key);
}
else
{key=1;
if(fun2(i,j,p,key))
temp[t][++c]=array[i][j];
if(array[i][j]=='[at]'&&p[0]!=-1)
{ //taking ,[at], as null symbol.
if(array[p[0]][p[1]]>='A'&&array[p[0]][p[1]]<='Z')
{
key=0;
fun2(p[0],p[1],p,key);
}
else
if(array[p[0]][p[1]]!='/'&&array[p[0]][p[1]]!='\0')
{
if(fun2(p[0],p[1],p,key))
temp[t][++c]=array[p[0]][p[1]];
}
}
}
}
}
}
char fol[max][MAX],ff[max];int f,l,ff0;
void ffun(int,int);
void follow(int i)
{
int j,k;
for(j=0;j<=ff0;j++)
if(array[i][0]==ff[j])
return 0;
if(j>ff0)ff[++ff0]=array[i][0];
if(i==0)fol[l][++f]='$';
for(j=0;j<n;j++)
for(k=2;array[j][k]!='\0';k++)
if(array[j][k]==array[i][0])
ffun(j,k);
}
void ffun(int j,int k)
{
int ii,null=0,tt,cc;
if(array[j][k+1]=='/'array[j][k+1]=='\0')
null=1;
for(ii=k+1;array[j][ii]!='/'&&array[j][ii]!='\0';ii++)
{
if(array[j][ii]<='Z'&&array[j][ii]>='A')
{
for(tt=0;tt<n;tt++)
if(temp[tt][0]==array[j][ii])break;
for(cc=1;temp[tt][cc]!='\0';cc++)
{
if(temp[tt][cc]=='[at]')null=1;
else fol[l][++f]=temp[tt][cc];
}
}
else fol[l][++f]=array[j][ii];
}
if(null)follow(j);
}
void main()
{
int p[2],i,j;
clrscr();
printf("Enter the no. of productions :");
scanf("%d",&n);
printf("Enter the productions :\n");
for(i=0;i<n;i++)
scanf("%s",array[i]);
for(i=0,t=0;i<n;i++,t++)
{
c=0,p[0]=-1,p[1]=-1;
temp[t][0]=array[i][0];
fun(i,p);
temp[t][++c]='\0';
printf("First(%c) : [ ",temp[t][0]);
for(j=1;j<c;j++)
printf("%c,",temp[t][j]);
printf("\b ].\n");
getch();
}
/* Follow Finding */
for(i=0,l=0;i<n;i++,l++)
{
f=-1;ff0=-1;
fol[l][++f]=array[i][0];
follow(i);
fol[l][++f]='\0';
}
for(i=0;i<n;i++)
{
printf("\nFollow[%c] : [ ",fol[i][0]);
for(j=1;fol[i][j]!='\0';j++)
printf("%c,",fol[i][j]);
printf("\b ]");
getch();
}
}
What is percedence of arithmetic operators?
The precedence (not percedence!) is BIDMAS (UK) or PEMDAS (US)
The acronyms stand for:
Brackets (Parentheses)
Index (Exponent)
Division and Multiplication which have equal precedence and are evaluated from left to right.
Addition and Subtraction which have equal precedence and are evaluated from left to right.
Why there is no runtime checking in c language?
All variables in C are just memory references (excepting register variables, but there's no distinction in terms of this question). C makes no attempt to prevent developers from dynamically accessing any memory location of any memory size. It can only statically type-check during compile time to make sure that "excessively absurd" practices, such as placing an int into a char are generally obeyed, and that flimsy protection can be easily overridden with type casts, which basically assures the compiler that you know what you're doing.
Once a C program is running, all memory is treated as one large memory pool with pointers into it. The data itself has no notion of what it "is" or how it should behave, which is why C has always been claimed to be a "dangerous" language to use; a careless cast can crash a program or even an entire operating system in the case of a kernel programming error. That was a major motivation for most languages that have been developed since.
What does C in CCleaner stand for?
c= crap
i think they changed the name so that people would think the program is more proffeessoonnaall. i don't think "Crap-cleaner" sounds very professional, and might be a rouge .
Write a c program to print the given no is palindrome or not using for loop?
#include<stdio.h>
#include<conio.h>
void main()
{
int n,s=0,m;
clrscr();
printf("enter any no");
scanf("%d",&n);
m=n;
while(n>0)
{
r=n%10;
s=s*10+r;
n=n/10;
}
if(s == n) // This is important step
printf("the no is palindrome");
else
printf("no is not palindrome");
getch();
}
Write a program in c to find out the middle character of a word?
This kind of exercise requires a minimal amount of mathematics and logic.
In C, strings are character arrays, and the variables used to contain strings actually contain the location (or "address") of the first character. The last character in the string is ASCII 0 (NUL), which signals the end of the string.
This problem requires you first know how long the string is, and for this purpose you would use "strlen". Assuming you have an integer variable called "length" and a string called "str", this assignment would store the length of "str" into "length": length=strlen(str);
From there, the middle character is located at the halfway point in the array. So, if you had an integer variable called "halfpos", then this assignment would place the middle position of the string in "halfpos": halfpos=length/2;
Note that strings with an even number of character (2, 4, 6, 8, 10, etc.) actually have two middle characters. So "halfpos" would actually contain one character less than what's considered the "middle" of the string. Examples of this are:
- "Grape" contains five characters, ranged 0 to 4, so "halfpos" is 2, or "a" - although 5/2 is 2.5, because "length" and "halfpos" are integers that .5 is stripped off.
- "Tomato" contains six characters, ranged 0 to 5, so "halfpos" would be the point between the "m" and the "a".
To write the code for this exercise, you will need to know more about arrays. See the related links below for more help.