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

Three address code in compiler design?

prod=0;

i=1;

do

{

prod = prod +a[i] * b[i];

i=i+1;

} while(i<=20);

Write a program in c language to draw a diamond shaped if you give the number?

Hey, It is not the exact logic for a given program.

Here i m giving the code with minimum number of executing steps.

also i m sure that there doesn't exist any other way to print the same Diamond such that code executing steps will be less than mine.

It is not copied from any website, book etc.

#include

void main()

{

int n,i,s,k,flagReverce=0;

printf("Enter the no. of rows\n");

scanf("%d", &n);

for (i=1; i>=1; i++)

{

for (s=n; s>i; s-)

printf(" ");

for(k=1; k<(i*2)-1; k++)

printf("*")

printf("\n")

if (i == n)

flagReverce = 1

if (flagReverce = 1)

i-=2

}

}

How you use multiple programs in switch statement in c language?

program
#include
#include
#include
void main()
{
int a,b,ans,ch;
clrscr();
printf("enter the value of a and b");
scanf("%d%d",&a,&b);
printf("1.Addition");
printf("\n2.Subtraction");
printf("\n3.Multiplication");
printf("\n4. exit");
printf("enter your choice");
scanf("%d",&ch);
switch(ch)
{
case 1:
ans=a+b;
printf("\nAfter Addition:%d",ans);
break;
case 2:
ans=a-b;
printf("\nAfter Subtraction:%d",ans);
break;
case 3:
ans=a*b;
printf("\nAfter Multiplication:%d",ans);
break;
case 4:
exit(0);
break;
}
getch();
}

Java program to find compound interest?

public class SimpleInterest{

float principal,intRate, numOfYears;

public void setPrincipal(float principal){

this.principal = principal;

}

public void setIntRate(float intRate){

this.intRate = intRate;

} public void setNumOfYears(float numOfYears){

this.numOfYears = numOfYears;

} public float calculateSimpleInterest(){

return (this.principal * this.intRate * this.numOfYears) /100; } public static void main(String argv[]){

float principal,intRate, numOfYears;

SimpleInterest simpIntObj = new SimpleInterest();

principal = Float.parseFloat(argv[0]);

intRate = Float.parseFloat(argv[1]);

numOfYears = Float.parseFloat(argv[2]);

simpIntObj.setPrincipal(principal);

simpIntObj.setIntRate(intRate);

simpIntObj.setNumOfYears(numOfYears);

System.out.println ("Principal = "+principal);

System.out.println ("Interest Rate = "+intRate);

System.out.println ("Num of Years = "+numOfYears);

System.out.println ("Simple Interest Amount = "+simpIntObj.calculateSimpleInterest());

} }

Write an algorithm to print the factorial of given number and then draw the flowchart?

write an algorithm to print the factorial of a given number and then draw the flowchart.

This looks like someones homework, defiantly someone looking for the easy way. When it comes to programming, the more you do the better you get. Experience counts (making your own mistakes and learning from the mistake).

String reverse program with single string and without using library functions in java?

You can create a separate string initially empty. Then using a loop, start at the end of the string and add it to the end of the other string. At the end of the loop, the other string would contain the reverse.

Why stack is implemented by link list?

A Linked-List is basically a series of Nodes. Each Node contains two things: The contents, and the pointer to the next Node in the Linked-List. So you can traverse the Linked-List by following the "next" pointers in each Node, a bit like following road directions from city to city.

A stack is an abstract data type where you have two operations: "push" and "pop". Pushing means to put an item in the stack, Popping means to get the first element of the stack. When you push an item onto a stack, you put the item at the top: so its like cutting in line to the very front. The last one in is now first, and thus, the first one out. Another helpful image is a "stack" of trays at a cafeteria -- you can only get the tray from the top of the stack, or put a tray on top of the stack. The very first tray in the stack is actually the one at the very bottom, and thus, the last one to be used. "First in, Last Out."

A stack deals with what comes first/last, while a Linked-List describes how data is stored. A stack needs to store data, so a stack can be implemented as a Linked-List.

What is 49f in c?

C = (5F - 160°) ÷ 9, where C is the temperature in degrees Celsius and F is the temperature in degrees Fahrenheit.

C = (5 x 42° - 160°) ÷ 9

= (210° - 160°) ÷ 9

= 50° ÷ 9

≈ 5.6° C

What is a major advantage of licensing?

The person or body granting the license can get money for the license taken out.

Write an algorithm to find the numbers divisible by 3 but not by 6 and then draw the flowchart?

Start

Input a

if a%3 = 0 then

Print a

else

print" enter another number"

end

1. start

2. Input N

3. if N<3, go to step 6

4. if N%3 && N%6!=0 then

print N

5. N=N-3 go to step 3

6. end

Write a program that accepts a number and output its equivalent in words?

/*mycfiles.wordpress.com
program to convert digits to character*/
#include
#include
void main()
{
int a[5],i,n;
clrscr();
cout<<"Enter the Value";
cin>>n;
for(i=4;i>=0;i--)
{
a[i]=n%10;
n=n/10;
}
for(i=0;i<5;i++)
{
if(a[i]!=0)
{
switch(a[i])
{
case 0:cout<<"Zero";
break;
case 1:cout<<"One";
break;
case 2:cout<<"Two";
break;
case 3:cout<<"Three";
break;
case 4:cout<<"Four";
break;
case 5:cout<<"Five";
break;
case 6:cout<<"Six";
break;
case 7:cout<<"Seven";
break;
case 8:cout<<"Eight";
break;
case 9:cout<<"Nine";
break;
}
}
}
getch();
}


------------------------------------------------------------------------------------


Program to Convert Numbers into Words

#include

void pw(long,char[]);
char *one[]={" "," one"," two"," three"," four"," five"," six"," seven","
eight"," Nine"," ten"," eleven"," twelve"," thirteen"," fourteen","
fifteen"," sixteen"," seventeen"," eighteen"," nineteen"};
char *ten[]={" "," "," twenty"," thirty"," forty"," fifty"," sixty","
seventy"," eighty"," ninety"};


void main()
{
long n;
clrscr();
printf("
Enter any 9 digit no: ");
scanf("%9ld",&n);
if(n<=0)
printf("Enter numbers greater than 0");
else
{
pw((n/10000000),"crore");
pw(((n/100000)%100),"lakh");
pw(((n/1000)%100),"thousand");
pw(((n/100)%10),"hundred");
pw((n%100)," ");
}
getch();
}


void pw(long n,char ch[])
{
(n>19)?printf("%s %s ",ten[n/10],one[n%10]):printf("%s ",one[n]);
if(n)printf("%s ",ch);
}


// for any query visit
// "http://www.c.happycodings.com/Beginners_Lab_Assignments/code51.html"

Program to Convert Numbers into Words

#include

void pw(long,char[]);
char *one[]={" "," one"," two"," three"," four"," five"," six"," seven","
eight"," Nine"," ten"," eleven"," twelve"," thirteen"," fourteen","
fifteen"," sixteen"," seventeen"," eighteen"," nineteen"};
char *ten[]={" "," "," twenty"," thirty"," forty"," fifty"," sixty","
seventy"," eighty"," ninety"};


void main()
{
long n;
clrscr();
printf("
Enter any 9 digit no: ");
scanf("%9ld",&n);
if(n<=0)
printf("Enter numbers greater than 0");
else
{
pw((n/10000000),"crore");
pw(((n/100000)%100),"lakh");
pw(((n/1000)%100),"thousand");
pw(((n/100)%10),"hundred");
pw((n%100)," ");
}
getch();
}


void pw(long n,char ch[])
{
(n>19)?printf("%s %s ",ten[n/10],one[n%10]):printf("%s ",one[n]);
if(n)printf("%s ",ch);
}


// for any query visit
// "http://www.c.happycodings.com/Beginners_Lab_Assignments/code51.html"

How many bytes are required to store an address of an integer?

32 bits or 4 bytes.

This depends heavily on the processor architecture your computer uses, AND the programming language you are using.

Typically, an integer is 1 word in length, however that processor architecture defines "word". That could be 32-bits (4 bytes), 64-bits (8 bytes), 8-bits (1 byte), or even 9 bits (in certain old computers).

What is the format of the switch statement?

switch (expression) { case value 1 : [ statement-block 1] [break ;] case value 2 : [ statement-block 2] [break ;] ……. ……. case value N : [ statement-block N] [break ;] [default: [default block] [break;] ] } statement x;

What are the applications of double pointer in c?

insert or delete values both side.so use double pointer

What is convoluction?

Wikipedia has a section on this. Click the Wikipedia link below

Differences between if else and while loop?

Easy: if-else is not a loop; while, for and do-while are loops.

if-else just run once, but do-while run many times.

C programming to display a calendar?

hmmm. . .

string main () //NOTE you dont have to use the string main or return applepie = )

{

int month, days;

string month_name;

// also if you have to configure the Year i would go by coppying the number of days

//in each month by year and create a massive clause of if else trees by YEAR

// for instance (int year 9)

{

days= 30;

}

}

return applepie;

Is there any program that can run c but not in c plus plus?

== Yes. It may be funny. You cannot use keywords like newin c++ for variable declaration. But in C it is possible.

== The following definition is valid in C, invalid in C++: char str [3] = "ABC";

What are the limitations of the C programming language?

An algorithm simply describes the finite, procedural steps required to solve a problem. Algorithms are not specific to any one programming language, but without algorithms there would be no computer programs let alone programming languages. That is, you cannot program a computer to solve a problem unless you know how to solve the problem yourself and for that you need to know the algorithm. Once you have the algorithm, you can program the computer to implement it.

What do you understand by static memory allocation and dynamic memory allocation?

MEMORY ALLOCATION MODELS……

STATIC MEMORY ALLOCATION DYNAMIC MEMORY ALLOCATION

Memory is allocated before the execution of the program begins.

(During Compilation)

Memory is allocated during the execution of the program.

No memory allocation or deallocation actions are performed during Execution.

Memory Bindings are established and destroyed during the Execution.

Variables remain permanently allocated.

Allocated only when program unit is active.

Implemented using stacks and heaps.

Implemented using data segments.

Pointer is needed to accessing variables.

No need of Dynamically allocated pointers.

Faster execution than Dynamic.

Slower execution than static.

More memory Space required.

Less Memory space required.

What is the difference between an array of structures and an array within a structure?

The main differences between an array and a structure are:

An Array is a collection of similar data items.An array is derived data type.It behave like a built in data type. An array can be increased or decreased.

A structure is a collection of dissimilar data items.It is a user defined data types.It must be declared and defined.A structure element can be added if necessary.

A first-generation contact language is called a?

A first generation contact language is called a pigdin. The feature of human language that allows people to talk about the past and the future is referred to as displacement.

What is the difference between javascript and C programming language?

Mainly JavaSript is a low-level scripting language that differs from the high-level languages in its easiness. The core language is really simple, and is designed to be easier for beginners,

I.e. JS i loosly typed. Meaning that a variable can reference any kind of literal, array or object, which differs from the high-level C-languages where you have to declare if a variable i to reference an integer, floating-point, string, hash-map and so on.

Another major difference is that JS, like python or php isn't compiled to machine code, but interpreted at runtime, making programs run significantly slower than compiled programs.

Another difference which is good, and unique to JS is that it does not inherit the C class model when working in OOP. Objects in JavaScripts can be crated and altered as one want to, beeing more dynamic to work with. A classical model can however be adopted with use of functions and use of the 'new' keyword. Here the lack of private variables can be worked around by the use of a technique called 'closure'.

The major difference however is that programs written in JS to work with the HTML DOM tend to not follow the normal procedural 'step-by-step' executions as conventional programs, where one line of code is being executed at the time. In stead JS tend to follow a Event Loop model, where different parts of the programs are attached to different DOM events. The JS-program will then sleep until a event is fired, then wake up, do its job, then go back to sleep. And so on. All in all making JS a very dynamic and "fun to work with" language.

Difference between conventional OS and embedded OS?

Conventional OS aim to give users the ability to run other software that are interactive in nature to perform different tasks. On the other hand, embedded OS only run fixed set of tasks and deliver the expected results in real time.