answersLogoWhite

0

📱

C Programming

Questions related to the C Computer Programming Language. This ranges all the way from K&R to the most recent ANSI incarnations. C has become one of the most popular languages today, and has been used to write all sorts of things for nearly all of the modern operating systems and applications. It it a good compromise between speed, power, and complexity.

9,649 Questions

Write a C program to remove duplicate elements in an array?

#include

int main(){

int arr[50];

int *p;

int i,j,k,size,n;

printf("\nEnter size of the array: ");

scanf("%d",&n);

printf("\nEnter %d elements into the array: ",n);

for(i=0;i

scanf("%d",&arr[i]);

size=n;

p=arr;

for(i=0;i

for(j=0;j

if(i==j){

continue;

}

else if(*(p+i)==*(p+j)){

k=j;

size--;

while(k < size){

*(p+k)=*(p+k+1);

k++;

}

j=0;

}

}

}

printf("\nThe array after removing duplicates is: ");

for(i=0;i < size;i++){

printf(" %d",arr[i]);

}

return 0;

}

By Amandeep Singh :)

C program to calculate x to the power y without using operator and standard function?

void main()

{

int x=100,y=3;

//lets calculate x to the power of y now

int result=0,i,j,a=x;

for(i=0;i<(y-1);i++)

{

for(j=0;j<x;j++)

result=result+a;

a=result;

result=0;

}

printf("%d",a);

}

Swap of two numbers with xor?

void swap (int *a, int *b) {

*a ^= *b;

*b ^= *a;

*a ^= *b;

return;

}

What is machine language called and what numerals represent this language?

A machine language is called as machine code and it is represented as binary numbers 0 and 1

What are the Similarities between c and .Net?

Many syntaxs are very similar in both the languages C and C# .NET.

C++ supports Object Oriented Programming and .NET also supports that.

Infact C++ is derived from C language and C# .NET is derived from C++ language.

Differentiate c constant and c variables?

  • Differentiate between constants and variable

    Constants

    variables

    characteristics

    Value is not changeableduring the course of the program

    Value can be changedanytime during the course of the program

    usage

    Use constant when you want to declare something that won't change midway in your program execution.

    Use variable to store data thatmay or will change during the running of the program.

What advantages did salons have over earlier forms of communication in spreading ideas?

Philosophers, writers, artists, scientists, and other great intellects all gathered at salons to discuss ideas. With everyone gathered together, it would be much more effective than writing down ideas and discussing it over time or just by word-of-mouth.

What is extreme programming?

Extreme Programming:

Extreme Programming is when you design the test cases first, and then program backwards. This creates an easier to use programming flow.

Write a program in c plus plus to accept the string and then take the starting and ending point from the user and display the sub string through function?

#include<iostream>

#include<sstream>

unsigned input_num (std::string prompt, unsigned min, unsigned max)

{

unsigned num = 0;

while (1)

{

std::cout << prompt << " (range " << min << " - " << max << "): ";

std::string input = "";

std::getline (std::cin, input);

std::stringstream ss (input);

if (ss >> num)

{

if (num >= min && num <= max)

break;

else if (num<min)

std::cout << "Index must be greater than or equal to " << min << std::endl;

else

std::cout << "Index must be less than or equal to " << max << std::endl;

}

else

std::cout << "Invalid input." << std::endl;

}

return (num);

}

void print_substring (std::string input, unsigned left, unsigned right)

{

std::cout << input.substr (left, right - left + 1) << std::endl;

}

int main()

{

std::cout << "Input string:\t";

std::string input = "";

std::getline (std::cin, input);

unsigned left = input_num ("Enter the start index of the substring", 0, input.size()-1);

unsigned right = input_num ("Enter the end index of the substring", left+1, input.size()-1);

print_substring (input, left, right);

}

What is a location drawing used for?

This type of drawing explains where the buildings location is and tells you what other buildings are surrounding it.

What is Equivalence class?

An equivalence relation ~ on A partitions into pairwise disjoint subsets called equivalence classes so that 1. Within each class, every pair relates 2. Between classes there is no relation i.e. [x] = {a (element) A | a~x} and given two equivalence classes [a] and [b], either [a] = [b] or [a] intersect [b] = the empty set

Three times the sum of c and d?

Sum means to add.. so the equation would look like 3(c+d) or (c+d)*3. You could also add them separately. 3c+3d Hope that helps!

How can you dicribe array?

An array is when you store several data items with a single name. You only use a number to distinguish the individual items. Or two or more numbers, if you use a multidimensional array.

An array is when you store several data items with a single name. You only use a number to distinguish the individual items. Or two or more numbers, if you use a multidimensional array.

An array is when you store several data items with a single name. You only use a number to distinguish the individual items. Or two or more numbers, if you use a multidimensional array.

An array is when you store several data items with a single name. You only use a number to distinguish the individual items. Or two or more numbers, if you use a multidimensional array.

How do you do a backwards slash?

Since the backwards slash is the prefix of an escape character, in order to encode a backwards slash in a constant, simply use two of them.

char backslash = '\\';

If you need to know where it is look under the backspace key : ) // \\

Create a 5 by 5 matrix. Each element is randomly generated between 0 and 100.Output the matrix one by one and Output the sum of each row?

I dont know how to generate the nos. randomly.I think it should follow some logic.So the following prog is made upon the inputs given by a user.
#include
#include
void main()
{ int a[5][5],i,j,s;
printf("\nEnter elements of the 5X5 matrics:\n");
for(i=0;i<5;i++)
{ for(j=0;j<5;j++)
{ scanf("%d",&a[i][j]);
if(a[i][j]<0 a[i][j]>100)
{ printf("\nThe no. should be between 1 & 100\nEnter Again:");
scanf("%d",&a[i][j]);
}
}
}
printf("\nThe given matrix is:\n");
for(i=0;i<5;i++)
{ for(j=0;j<5;j++)
printf("%d",a[i][j]);
printtf("\n");
}
printf("\nThe sum of each row:");
for(i=0;i<5;i++)
{ for(j=0;j<5;j++)
s+=a[i][j];
printf("%d->%d\n",i+1,s);
}
getch();
}
Hope this would help you.

Write a c program to find the sum of the first 15 even numbers and calculate the square of the sum?

#include<stdio.h>

#include<conio.h>

void main()

{

int c=1,i;

unsigned int s=0;

clrscr();

for(i=1,(i<=15;i++))

{

if(i%2==0)

{

s=s+i;

c=c+i;

}

}

printf("/n sum of the first 15 even numbers is%d",s);

printf("/n square of the sum is: %d",(s*s));

getch();

}

What are the four major stages of compilation in programming?

This actually varies based upon the language as some have less than 4 or more than 4. However I believe you're looking for:

-Preprocessor

-Compile

-Assembler

-Linker

Is an array not suitable?

That depends on what you want to use it for. An array offers constant-time random access to any element in the array, but is restricted by the fact it must be re-allocated in order to cater for new elements or to remove redundancy. Linked lists overcome this limitation at the expense of random access, which is linear-time other than for the first and/or last nodes which remain constant-time.