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

What are forked sockets?

A forked socket relates to two or more processes using the same socket. When a process terminates, it should close the socket, however the socket remains open until the final process terminates. This is typically achieved through reference counting.

How do you design an applicatoin that accepts 10 numbers and displays?

Simply: design an application, that accept one number, then put it in a loop that repeat is ten times.

What is the difference between procedure-oriented and problem-oriented in C language?

C is neither procedure-oriented nor problem-oriented. C is a structured, general purpose programming language.

Procedure-oriented programs are distinct in that code jumps around -- a lot. They do not have structured loops nor do they have procedure calls (subroutines, functions or procedures), but they do make prevalent use of jump or goto statements. As a result, procedure-oriented programs are often called "spaghetti code" due to the difficulty in both reading and maintaining the program. Machine code and assembly language are both examples of procedure-oriented languages.

Although you could theoretically write a C program using nothing but procedural programming methods, the resultant spaghetti code will be extremely difficult to read and maintain. Imagine if you couldn't use for(), while() and do..while() loops, and couldn't call any functions, not even the built-in functions. You would basically have nothing more than a single main() function with all code contained therein. Even multiple statements enclosed in braces would not be permitted in procedural-programming.

Problem-oriented programming languages are languages tailored to a particular application. Although it is possible to create a problem-oriented language within C, as a superset of C for instance, C itself is general purpose.

Write a calendar program to find out the day of a given date in a particular year?

Here is the complete program. Mind you, the code doesn't mind if you input invalid dates like 29th February 1981 or 42 March 1983, etc. So if you input such stupid dates, you will get stupid answers. Adding further code to take care of such childish inputs would only convolute it, right?

#include

#include

main()

{

long int t=0,id=15,im=10,iy=1582,iy1=1582,id1,im2=9,im1=9,dr,dc=0,td,tm,ty;

long int smc[12];

smc[0]=smc[2]=smc[4]=smc[6]=smc[7]=smc[9]=smc[11]=31,smc[3]=smc[5]=smc[8]=smc[10]=30;

printf("Enter the date (Date Month Year): ");

scanf("%ld %ld %ld",&td,&tm,&ty);

id1=td;

while (iy

{

if (((((iy)%4)==0) && (((iy)%100)!=0)) ((((iy)%100)==0) && (((iy)%400)==0)))

smc[1]=29;

else

smc[1]=28;

while (im1<=11)

{

if (t==0)

dr=smc[im-1]-id,++t;

else

dr=smc[im1];

while (dr>0)

++dc,--dr;

++im1;

}

im1-=12,++iy;

}

if (((((iy)%4)==0) && (((iy)%100)!=0)) ((((iy)%100)==0) && (((iy)%400)==0)))

smc[1]=29;

else

smc[1]=28;

while (im1

{

dr=smc[im1];

while (dr>0)

++dc,--dr;

++im1;

}

if ((iy1==ty) && (im2=(tm-1)))

id1=td-id;

while (id1>0)

++dc,--id1;

if ((dc%7)==0)

printf("\nFriday.");

if ((dc%7)==1)

printf("\nSaturday.");

if ((dc%7)==2)

printf("\nSunday.");

if ((dc%7)==3)

printf("\nMonday.");

if ((dc%7)==4)

printf("\nTuesday.");

if ((dc%7)==5)

printf("\nWednesday.");

if ((dc%7)==6)

printf("\nThursday.");

}

What do you mean by object oriented programming?

Methods in many programming languages is actually the Functions or Subroutines, themselves. These are often referred to as 'methods'. * Function - a function is a sequence of commands or programming code that returns a value (sends a result back). Think of it as "What method would you use to add to numbers together?" * Subroutine (often referred to as a Sub) - a SUB is a sequence of commands or programming code, but it does NOT return a value. Think of this as "Save this file to the Hard Disk", or "Update the database". These two code sequences complete a series of task, but don't necessarily need to send anything back to the user (caller). These are both referred to as Methods. They are the method to the madness of a program, in many ways!

C code to encrypt monoalphabetic cipher?

//Monalphabetic Cipher

/**Created by:Mihir Vadalia*/

#include

#include

FILE *source,*dest,*kf;

void encrypt();

void decrypt();

void main()

{

int choice;

do

{

clrscr();

printf("\n\n\t\tMonoalphabetic Cipher\n\nEnter your chice:\n");

printf("1.Encryption\n2.Decryption\n3.Exit.\n\nYour Choice:");

scanf("%d",&choice);

switch(choice)

{

case 1:

encrypt();

break;

case 2:

decrypt();

break;

default:

exit(0);

}

getch();

}while(choice);

}

void encrypt()

{

char k[26]={'/0'},fname[15],ch;

int i,n;

printf("\n\nEnter the name of file to be encrypted:\n");

flushall();

gets(fname);

flushall();

source = fopen(fname,"r");

dest = fopen("Dest.txt","w");

kf = fopen("key.txt","r");

i=0;

while((ch=getc(kf))!=EOF)

{

k[i]=ch;

i++;

}

while ((ch=getc(source))!=EOF)

{

n=(int)ch-97;

for (i=0;i!=n;i++);

putc(k[i],dest);

}

fclose(dest);

fclose(source);

fclose(kf);

printf("\n\nThe file has been encrypted...\n\nThe contents are:\n");

dest=fopen("Dest.txt","r");

while((ch=getc(dest))!=EOF)

printf("%c",ch);

}

void decrypt()

{

char k[26]={'/0'},fname[15],ch;

int i,n;

printf("\n\nEnter the name of file to be decrypted:\n");

flushall();

gets(fname);

flushall();

dest = fopen(fname,"r");

kf = fopen("key.txt","r");

i=0;

while((ch=getc(kf))!=EOF)

{

k[i]=ch;

i++;

}

printf("\nDecrypted contents are : ");

while ((ch=getc(dest))!=EOF)

{

for (i=0;ch!=k[i];i++);

putchar(97+i);

}

fclose(source);

fclose(kf);

}

Which traversal of a binary search tree produces a descending sequence?

Use depth-first traversal. By convention, binary trees place lower values in the left branch and larger or equal values in the right branch. Given any node in the tree (starting from the root), output all the values to the right of that node, then output the node's value, and finally output all the values to the left of that node. The algorithm can be implemented recursively as follows:

void print_descending (node* n) {

if (n->right) print_descending (n->right); // recursively output all values greater than or equal to n->data

printf ("%d\n", n->data); // output the data (assumes an integral type)

if (n->left) print_descending (n->left); // recursively output all values less than n->data

}

What is chain of pointers?

A pointer can point to address of another pointer. consider the example

int x=456, *p1, **p2;p1 = &x;p2 = &p1;

Copyright Einstein College of EngineeringDepartment of Civil Engineering

TOP

printf("%d", *p1); will display value of x 456.printf("%d", *p2); will also display value of x 456. This is because p2 point p1, and p1 points x.Therefore p2 reads the value of x through pointer p1. Since one pointer is points towards anotherpointer it is called chain pointer. Chain pointer must be declared with ** as in **p2

MOV D IN Microprocessor means?

MOV D,reg means: move content of the specified register (or M=memory addressed with HL) into register D

C programming example source code?

This is a very wide question, which could have many different answers, from the simple to the complex.

However, as a start, an example of a program in C where you enter distance and time and calculate speed might look something like this:

(PLEASE NOTE: I CAN'T GET THIS TO FORMAT PROPERLY - THERE SHOULD BE A BLANK LINE AFTER "stdio.h" and after each semi-colon)

#include "stdio.h"

int main(void) {float distance, speed, timetaken;

printf("Enter distance in miles:");

scanf("%f", &distance);

printf("Enter time taken in seconds:");

scanf("%f", &timetaken);

speed = distance / timetaken;

printf ("\nSpeed = %10.2f (miles per second)\n", speed);

return 0;

}

This a prewritten function that is built into a programming language?

Library Function

Starting out with Programming Logic and Design by Tony Gaddis Page 218

Write a program to illustrate the concept of extern variable?

#include

extern int errno;

int main (void)

{

fopen ("nosuchfile", "r");

fprintf (stderr, "error code=%d\n", errno);

return 0;

}

REGARD

Dheeraj Kumar

From S.M.U Hajipur (Bihar)

Fibbomacci series using recursion shell programming?

Here is a good answer for recursion Fibonacci series.

#include <stdio.h>

#include <conio.h>

long Fibonacci(long n);

int main()

{

long r, n,i;

printf("Enter the value of n: ");

scanf("%ld",&n);

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

{

printf(" Fibonacci(%ld)= %ld\n", i,Fibonacci(i));

}

getch();

return 0;

}

long Fibonacci(long n)

{

if(n==0 n==1)

return n;

else

{

return (Fibonacci(n-1)+Fibonacci(n-2));

}

}

for n=5;

Output: Fibonacci(0)=0

Fibonacci(1)=1

Fibonacci(2)=1

Fibonacci(3)=2

Fibonacci(4)=3

Fibonacci(5)=5

Why do you need two types of coding in one programming language?

It would be easier to answer, if you explained what the 'two types of coding' were.

How you can store a class variables in array list?

An (non generic) arrayList in java can save any type of object (in this case your class variable) in this straightforward way:

MyClass myClassVar = new MyClass();

ArrayList myArrayList = new ArrayList();

myArrayList.add(myClassVar);

Program in c language that acceps a file as input and prints the number of lines in it?

#include <iostream> #include <fstream> using namespace std; int number_of_lines = 0; void numberoflines(); int main(){ string line; ifstream myfile("textexample.txt"); if(myfile.is_open()){ while(!myfile.eof()){ getline(myfile,line); cout<< line << endl; number_of_lines++; } myfile.close(); } numberoflines(); } void numberoflines(){ number_of_lines--; cout<<"number of lines in text file: " << number_of_lines << endl; }