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

8086 program to arrange a string of bytes in ascending order?

Mov ax,data

mov ds,ax

mov dl,05h

up2: lea si,ser1

mov cl,05h

up1: mov al,ds:[si]

mov ah,al

inc si

cmp al,ds:[si]

jc down

mov ah,ds:[si]

mov ds:[si],al

dec si

mov ds:[si],ah

inc si

down:dec cl

jnz up1

dec dl

jnz up2

int 3h

Write a C program to generate following sequence eg when 5 is pressed the sequence should be 0 1 1 2 3 5 and if 3 is pressed 0 1 1 2 the sequence should be according to the number pressed?

/* the sequence printed is Fibonacci's sequence, each element is calculated as a sum of two previous elements */
#include
int main()
{
int i;
int n;
int a0=0;
int a1=1;

printf("How many elements do you want to print? ");
scanf("%d",&n);

printf("0 ");
if (n > 0)
printf("1 ");


for (i = 2; i <= n; i++)
{
printf("%d ", a0+a1);

a1 = a0 + a1;
a0 = a1 - a0;

}
return 0;

}

Heap sort program in C language?

#include <stdlib.h>

#include <stdio.h>

#define uint unsigned int

typedef int (*compare_func)(int, int);

void heap_sort(int This[], compare_func func_pointer, uint len)

{

/* heap sort */

uint half;

uint parents;

if (len <= 1)

return;

half = len >> 1;

for (parents = half; parents >= 1; --parents)

{

int tmp;

int level = 0;

uint child;

child = parents;

/* bottom-up downheap */

/* leaf-search for largest child path */

while (child <= half)

{

++level;

child += child;

if ((child < len) &&

((*func_pointer)(This[child], This[child - 1]) > 0))

++child;

}

/* bottom-up-search for rotation point */

tmp = This[parents - 1];

for (;;)

{

if (parents child)

break;

if ((*func_pointer)(tmp, This[child - 1]) <= 0)

break;

child >>= 1;

--level;

}

/* rotate nodes from parents to rotation point */

for (;level > 0; --level)

{

This[(child >> level) - 1] =

This[(child >> (level - 1)) - 1];

}

This[child - 1] = tmp;

} while (--len >= 1);

}

#define ARRAY_SIZE 250000

int my_array[ARRAY_SIZE];

void init()

{

int indx;

for (indx=0; indx < ARRAY_SIZE; ++indx)

{

my_array[indx] = rand();

}

}

int cmpfun(int a, int b)

{

if (a > b)

return 1;

else if (a < b)

return -1;

else

return 0;

}

int main()

{

int indx;

init();

heap_sort(my_array, cmpfun, ARRAY_SIZE);

for (indx=1; indx < ARRAY_SIZE; ++indx)

{

if (my_array[indx - 1] > my_array[indx])

{

printf("bad sort\n");

return(1);

}

}

return(0);

}

What is the program for snake and ladder game in c plus plus?

#include<iostream>

#include<array>

#include<string>

#include<random>

#include<ctime>

using player_t = std::array<unsigned, 2>;

using pair_t = std::pair<unsigned, unsigned>;

using snake_t = std::array<pair_t, 10>;

using ladder_t = std::array<std::pair<unsigned, unsigned>, 9>;

const std::string player (const bool human)

{

return std::string {human ? "You" : "I"};

}

int main()

{

std::default_random_engine generator ((unsigned) time (0));

std::uniform_int_distribution<unsigned> distribution (1, 6);

player_t players = {0,0};

const snake_t snakes = {pair_t {98,78}, {95,75}, {93,73}, {87,24}, {64,60}, {62,19}, {56,53}, {49,11}, {47,26}, {16,6}};

const ladder_t ladders = {pair_t {1,38}, {4,14}, {9,31}, {21,42}, {28,84}, {36,44}, {51,67}, {71,91}, {80,100}};

std::cout << "Snakes and Ladders\n";

std::cout << "==================\n\n";

std::cout << "First to land exactly on square 100 wins.\n";

bool human = (distribution (generator) % 2)==0 ? true : false;

std::cout << player (human) << " will go first.\n\n";

for (;;human=!human)

{

std::cout << (human ? "Your" : "My") << " turn:\n";

unsigned dice = distribution (generator);

std::cout << '\t' << player (human) << " rolled a " << dice << ".\n";

unsigned& pos = players [human?0:1];

if (pos+dice>100)

{

std::cout << '\t' << player (human) << " cannot move";

goto next_player;

}

pos+=dice;

std::cout << '\t' << player (human) << " landed on square " << pos;

for (auto snake : snakes)

{

if (snake.first==pos)

{

pos = snake.second;

std::cout << " with a snake; return to square " << pos;

goto next_player;

}

}

for (auto ladder : ladders)

{

if (ladder.first==pos)

{

pos = ladder.second;

std::cout << " with a ladder; climb to square " << pos;

goto next_player;

}

}

next_player:

std::cout << ".\n\n";

if (pos==100)

{

std::cout << player (human) << " won!\n";

break;

}

}

}

What is the meaning of fall through in java language?

A "fall through" is what we call it when a case in a switch statement doesn't end in a break, return, throw, or any other control-breaking statement. In these cases, program execution continues to the next case block (regardless of the value in the switch), and so control "falls through" to the case below it.

Here is an example of a typical switch block:

switch(n) {

case 0:

System.out.println("zero");

break;

case 1:

System.out.println("one");

case 2:

System.out.println("two");

break;

}

Notice the break statements in cases 0 and 2. These are used to break out of the switch block so that only one value is printed out. If n is set to 1 before executing this code, "one" would be printed out and then the program would continue to the next statement and print out "two" as well. That is a fall through.

Why the background colour of turbo c plus plus is blue?

I want my C++ program become interesting

How can I change the color of background and color of font even size of font.........

I will always use

system("cls")

to clear there screen.....

so I want do C++ DOS into something we call presentation like powerpoint

Haha........

Any tutorial?

That all

Thank you

How get input form keyboard?

Retrieving keyboard input depends partly upon whether you're writing a console or graphical application. If you're writing a console application, you have the following functions available:

- sscanf() in the stdio.h header

- getchar() in the stdio.h header

- getch() in conio.h and curses.h (plus kbhit() if it's available)

For Win32 applications, which are event-driven, you'll want to intercept the WM_CHAR event that's passed to your window handler (WndProc). The wParam parameter will contain the character on the keyboard that's pressed.

For other APIs, you'll want to check the documentation, or look on the Web for tutorials describing how to get keyboard input using whichever API you're using.

C performs bound checking for array?

Never. For example argv[-1] (or -1[argv]) is perfectly legal.

Write a C program to find all emirp numbers between 1 and 1000 1 and 1000 inclusive?

/* emirp_1000.c j. adams

*

* Program to generate prime numbers that are emirps

*

*

* compile with $> gcc -o emirp_1000 emirp_1000.c -lm

*

*

*/

#include <stdio.h>

#include <string.h>

#include <stdlib.h>

#include <math.h>

#define MAX_RANGE 1000

int main(void)

{

int p = 11;

int p2 = 0;

int itr = 0;

int cnt = 0;

int rev = 0;

int skip_val[]= {2, 4, 2, 2, 2, 4, 2, 2, 2, 4, 2, 2, 2, 4, 2, 2};

while(p < MAX_RANGE)

{

cnt = 16;

itr = 0;

while(cnt--)

{

// check p for primeness.

if(isit_prime(p))

{

p2 = p;

// reverse p

while(p2 > 0)

{

rev = rev * 10 + (p2 % 10);

p2 = p2/10;

}

// If rev != p (palindrome) and rev is prime

if((rev ^ p)&&(isit_prime(rev)))

printf("\n%d", p);

}

rev = 0;

p = p += skip_val[itr++];

}

}

printf("\n");

return 0;

}

int isit_prime(int n)

{

int k = 0;

if (n 0)

return 0;

return 1;

}

What operators in C were modeled on similar operators in ALGOL 68?

The short answer is probably these C operators +=, -=, *=, /= * %= are from Algol68′s +:=, -:=, *:=, /:= & %:=.

c.f. usenet: Ada and C and Algol 68

BTW: The best quote about C's ancestry comes from Dennis Ritchie himself:

"The scheme of type composition adopted by C owes considerable debt to Algol 68, although it did not, perhaps, emerge in a form that Algol's adherents would approve of. The central notion I captured from Algol was a type structure based on atomic types (including structures), composed into arrays, pointers (references), and functions (procedures). Algol 68′s concept of unions and casts also had an influence that appeared later." Apr 1993 c.f. Dennis Ritchie (April 1993). "The Development of the C Language" (PDF)

Note that the /= and /:= are subtly different. Also C's %= is the same as Algol's %*:= operator.

Note also that the majority of C's operators came from Algol (+ - * / = ≠ etc ). However the "%" operator is notability different.

* Wikipedia: Monadic_operators

* Wikipedia: Dyadic_operators_with_associated_priorities

C has the "return" and "sizeof" operator, whereas Algol68 has syntax "EXIT" (or "□") and operator "UPB" (or "⌈") that achieve a similar function.

Algol 68 also has some related constants: "max int", "max real", "int width", "real width" etc to determine sizes of things. These are not the same a C's sizeof, but similar.

The most peculiar operators of C's are /\ & \/, these come from Algol's ∧ & ∨ operators. These "C originals" were replaced by the current && and operators. c.f. What _did_ the C operators /\ and \/ do?

Algol68 further allows operators to be define using non-ASCII characters:

×, ÷, ≤, ≥, ¬, ∨, ∧, , ↓, ↑, ⌊, ⌈, ⎩, ⎧ and ⊥;

And used the characters →, ○, □, ␣ and ¢ for other purposes. It is kind of like Algol68 was taking the liberty of using unicode some 20 years before Unicode characters were defined. {Earlier Algol60 used non-ASCII ⊂ and ≡}

* C's: int i = b ? a : b; /* pick maximum */

* A68′s: INT i := ( a > b | a | b );

c.f. Wikipedia: ?: - a ternary operator

The assignment ":=" looks like an operator, but in terms of "Algol68″ OPerators it isn't. I believe they are called "Units associated with names" c.f. Array, Procedure, Dereference and coercion operations

(Or - if you are a language lawyer c.f. Algol 68 r1 report.html#52)

Similarly: Left assign, right assign and compare ( :=, =:, =) are also not "Algol68" Operators.

Pointers are not operators per se. There are a few "identity relations" associated with pointers: e.g. :=:, :/=:, IS & ISNT

c.f. Assignation and identity relations etc.

(Or - if you are a language lawyer c.f. Algol 68 r1 report.html#5221)

What ismeant by MAR MDR in computer?

MAR is memory address register. MDR is memory data register. These are registers part of the control unit (CU) in your cpu.

What does kentahten mean in iroquois?

The word kentahten means in future land in Iroquois. The Iroquois lived in New York State. The Iroquois were farmers.

What are the problems with computers and how do solve them?

AnswerThere are billions of problems that can happen with your computer. If something on your computer breaks call the maker of the computer: Dell, HP, Gateway, and so on: or reformat your hard drive. NOTE IF YOU DO THIS YOU WILL LOSE EVERYTHING AND WILL HAVE TO REINSTALL NOT ONLY WINDOWS BUT THE DRIVERS FOR ALL YOUR ACC, SUCH AS YOUR SOUND CARD AND VIDEO CARD. The best thing to do is make sure that you do not try to do it yourself if you dont know what your doing. You will only make it worse. Make sure someone who knows computers well works on it.

i also faced the same issues which you are facing and my friend told me about "ijinni technician" i contacted them at WWW. Ijinni. Com for any issues Just open the website and you can chat with the experts who are Microsoft certified technicians and will fix the issue itself on the spot or u can call them through Skype or contact and for more visit their website as it is very user friendly website. Just click on the chat as the response rate will be very fast from them and they have fixed my issues in no time.

There are 4 ways to reach them.

1. Once you open the website just click on the live chat where one of the IJINNI technicians will be in touch with you.

2. If you have Skype installed in your machines just add the contact "ijinni.com" (free call).

3. You can email at support@ijinni.com.

4. You can dial at +1 512 879 3546.

For any issue you are facing with the computer just call IJINNI

How do you replace a vowel into asterisk using java program loops?

If you want to do it neat and effortless, you may use enums.

public class MyClass {

private enum VOWELS { A,E,I,O,U,a,e,i,o,u; }

public static void main(String []ar) {

String s = "Hello World";

for(VOWELS c : VOWELS.values())

s = s.replace(c.name(), "*");

System.out.println(s);

}

}

.

Ram

What has the author Nguye n Lo c Bi nh written?

Nguye n Lo c. Bi nh has written:

'Ta m trang ho ng'

Mini project in c language with coding?

C Program to find factorial of a numberSimple C Programint main()

{

int n,i,f=1;

printf("enter any num \n");

scanf("%d",&n);

for(i=1;i<=n;i++)

{

f=f*i;

}

printf("factorial is %d ",f);

system("pause");

}

What is the program for echo server using message queues?

// File 1: mesg.h

#include

#include

#include

#include

#define MKEY1 4164L

#define MKEY2 4266L

#define PERMS 0666

typedef struct

{

long mtype;

char mdata[50];

}

mesg;

// File 2: Client.c

#include "mesg1.h"

mesg msg1,msg2;

main()

{

int mq_id1,mq_id2;

int n;

if((mq_id1=msgget(MKEY1,PERMS|IPC_CREAT))<0)

{

printf("Client:error creating queue");

exit(1);

}

if((mq_id2=msgget(MKEY2,PERMS|IPC_CREAT))<0)

{

printf("Client:error creating queue");

exit(1);

}

msg1.mtype=10L;

n=read(0,msg1.mdata,50);

msg1.mdata[n]='\0';

msgsnd(mq_id1,&msg1,50,0);

msgrcv(mq_id2,&msg2,50,10L,0);

write(1,msg2.mdata,50);

}

// File 3: Server.c

#include "mesg1.h"

mesg msg;

main(){

int mq_id1,mq_id2;

int n;if( ( mq_id1=msgget(MKEY1,IPC_CREAT|0666) ) < 0){printf("Server:error openenig queue");exit(1);}msgrcv(mq_id1,&msg,50,10L,0);if((mq_id2=msgget(MKEY2,IPC_CREAT|0666))<0){printf("sender:error creating queue");exit(1);}msgsnd(mq_id2,&msg,50,0);}

Write program using c programig to convert uppercase to lower case?

#include <stdio.h>

int main()

{

int n;

char ch;

scanf("%d", &n);

{

scanf("%c", &ch);

ch-=32;

}

printf("%c", ch);

return 0;

}