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

C program to read a text and count occurrence of a particular word?

#include<stdio.h>

main()

{

int i,words,spaces;

char a[30];

printf("enter the string") ;

scanf("%s",a);

for(i=0;a[0]!="\0";i++)

{

if (a[i]=' ')

spaces++;

}

printf("the no. of spaces in the string is %d",spaces);

printf("the number of words in the string is %d",spaces+1);

}

Program for dequeue in data structure?

Display function in de queue

void display()

{

int i;

if((front == -1) (front==rear+1))

printf("\n\nQueue is empty.\n");

else

{

printf("\n\n");

for(i=front; i<=rear; i++)

printf("\t%d",queue[i]);

}

}

What are nested structures?

Nested structures means we can have a structure inside another

eg:

struct A

{

...........

............

struct B

{

........

........

}b;

}a;

What is operator associativity in C?

Operator

Description

Associativity

()
[]
.
->
++ -- Parentheses (function call) (see Note 1)
Brackets (array subscript)
Member selection via object name
Member selection via pointer
Postfix increment/decrement (see Note 2)

left-to-right

++ --
+ -
! ~
(type)
*
&
sizeof Prefix increment/decrement
Unary plus/minus
Logical negation/bitwise complement
Cast (change type)
Dereference
Address
Determine size in bytes right-to-left * / % Multiplication/division/modulus left-to-right + - Addition/subtraction left-to-right << >> Bitwise shift left, Bitwise shift right left-to-right < <=
> >= Relational less than/less than or equal to
Relational greater than/greater than or equal to left-to-right == != Relational is equal to/is not equal to left-to-right & Bitwise AND left-to-right ^ Bitwise exclusive OR left-to-right | Bitwise inclusive OR left-to-right && Logical AND left-to-right Logical OR left-to-right ?: Ternary conditional right-to-left =
+= -=
*= /=
%= &=
^= |=
<<= >>= Assignment
Addition/subtraction assignment
Multiplication/division assignment
Modulus/bitwise AND assignment
Bitwise exclusive/inclusive OR assignment
Bitwise shift left/right assignment right-to-left

,

Comma (separate expressions) left-to-right

Write a program to accept two numbers and display their sum?

Assuming you're using the C programming language (as you did not specify any other), and that you're making some sort of arithmetic tester, a simple answer would be:

#include <stdio.h>

#include <stdlib.h>

#include <time.h>

int main()

{

time_t seconds;

time(&seconds);

srand((unsigned int)seconds);

int num1 = (rand()%100);

int num2 = (rand()%100);

int sum = num1 + num2;

int ans;

printf("What is %d + %d? ", num1, num2);

scanf("%d", &ans);

if(ans == sum) printf("Correct!");

else printf("Wrong, correct answer is %d", sum);

return 0;

}

Write a qbasic program to display the multiplication tables from 1 to 10?

Writing this QBASIC code purely on the fly...; without actually testing out if it works/or, not...

CLS

FOR tablesNo%=1 TO 10

FOR timesNo%=1 TO 10

PRINT timesNo%*tablesNo%; " ";

NEXT

PRINT

NEXT

END

NOTE: The numbers are not yet formatted to line up perfectly straight with one another.

Why do local variables lose their values between calls to the function in which they are defined?

They are designed to work that way - and it's actually quite useful to have variables that work that way. If you want to keep a value from one method call to the next, you have to use some other way to store the information. For example, you can store information in an object field.

Write a test program that prints a 3 by 3 matrix?

4.(Displaying matrix of 0s and 1s ) write a method that displays by n by n matrix using the following header : Public static void printMatrix(int n) Each element is o or 1,which is generated randomely. Write a test program that prints a 3 by 3 matrix that may look like this: 010 000 111 4.(Displaying matrix of 0s and 1s ) write a method that displays by n by n matrix using the following header : Public static void printMatrix(int n) Each element is o or 1,which is generated randomely. Write a test program that prints a 3 by 3 matrix that may look like this: 010 000 111

What does printf and scanf return?

Printf returned no. of character receive .

scanf return no of variable to be inputed according to format specifier . eg:

i=printf("thisisc") printf("%d",i); //i=7 j=scanf("dd",&a,&b,&c,&d); printf("%d",j);

IT IS MOST APPROPRIATE ANSWER FOR THIS Q .......... PLZ DO Practically............

What are basic features of c?

The C programming model is that the programmer knows exactly what they want to do and how to use the language constructs to achieve that goal. The language lets the expert programmer express what they want in the minimum time by staying out of their .

How are break points set using c plus plus?

Break points are a feature of the debugger and is implementation specific. For instance, in Visual C++, you place the cursor at the line where you want the breakpoint to be and hit the F9 key to toggle it on and off. When enabled, you can set the properties of the breakpoint, such as what condition(s) must be true in order for the program to break at that point.

What is the difference between a queue and a stack?

Queue is better than stack because jobs in a queue are processed on a first in first out order thereby reducing traffic and delay.

But jobs in a stack are processed in a last in first out order causing traffic and delay of jobs that arrived earlier

Give sample program?

class firstprog

{

public static void main (String args[])

{

System.out.pritnln("My first Program in Java ");

}

}

Simple Java Programe

Write the above program in Ms dos's edit or Notepad of Windows save it with "firstprog.java" run the commands given below in command prompt of Ms Dos to get the output Remamber Java is case sensative so mentain capital and small letter.

1. javac firstprog.java

2. java firstprog

What is main different between do while and while?

If you want to execute a statement which is in while loop at least one time you can use do- while loop.

this is why because initially first statements will be executed then condition will be checked. but in case of while first condition will be check then statements will be executed

Write a c programme to check whether given number is Fibonacci?

#include<iostream.h>

#include<conio.h>

void main()

{

long int n,a=0,b=1;

cout<<"dear user Enter number as u wish";

cin>>n;

while(n>0)

{

c=a+b;

cout<<"c<<"\t\t";

a=b;

b=c;

}

getch();

}

Can you merge nested for loop in one loop?

Yes, sometimes it is possible. It depends on what the nested loop actually does of course, but there are cases where a single loop can achieve the same end.

For instance, the following nested loop prints the product of each pair of values in the range 1 to 10:

for( int x=1; x<=10; ++x )

for( int y=1; y<=10; ++y )

printf( "%d * %d = %d\r\n", x, y, x*y );

This could be written as a single loop:

for( int z=0; z<100; ++z )

{

int x = z/10+1;

int y = z%10+1;

printf( "%d * %d = %d\r\n", x, y, x*y );

}

Note that the nested loop is easier to read and maintain and is also much more efficient than the merged loop.

Why do you write your code in a Notepad file?

Notepad is a text editor. What it saves is the source code of the programming language. Any source code is just a text file, so Notepad or any text editor can save a program's code.

Notepad is a text editor. What it saves is the source code of the programming language. Any source code is just a text file, so Notepad or any text editor can save a program's code.

Notepad is a text editor. What it saves is the source code of the programming language. Any source code is just a text file, so Notepad or any text editor can save a program's code.

Notepad is a text editor. What it saves is the source code of the programming language. Any source code is just a text file, so Notepad or any text editor can save a program's code.

Notepad is a text editor. What it saves is the source code of the programming language. Any source code is just a text file, so Notepad or any text editor can save a program's code.

Notepad is a text editor. What it saves is the source code of the programming language. Any source code is just a text file, so Notepad or any text editor can save a program's code.

Notepad is a text editor. What it saves is the source code of the programming language. Any source code is just a text file, so Notepad or any text editor can save a program's code.

Notepad is a text editor. What it saves is the source code of the programming language. Any source code is just a text file, so Notepad or any text editor can save a program's code.

Notepad is a text editor. What it saves is the source code of the programming language. Any source code is just a text file, so Notepad or any text editor can save a program's code.

Notepad is a text editor. What it saves is the source code of the programming language. Any source code is just a text file, so Notepad or any text editor can save a program's code.

Notepad is a text editor. What it saves is the source code of the programming language. Any source code is just a text file, so Notepad or any text editor can save a program's code.

What is a high level progrmming language?

It is a programming language with strong abstraction from the details of the computer.

What is a cusor?

A cursor is a moving space, line, arrow, or hand that indicates the position of a text point or GUI location on a computer monitor. Actions taken with the mouse or keyboard will be implemented at the current cursor location.

Which data structure would you most likely see in a nonrecursive implementation of a recursive algorithm?

Some sort of structure that lets you store a list of pending jobs - for example, an array, but it would have to be a resizable array. Some type of collection might be more appropriate. As you process one level of recursion, you add the "children" (which have yet to be processed) to the collection of pending jobs; once the "parent" is done processing, you remove it from the collection.

Write a program that accepts a word in uppercase and prints it in lowercase?

There are two functions in ctype.h: toupper() and tolower(). First one to make character into upper case and the second one for making lower case.

Here is a small program converting inputted character into lower case:

#include

#include

int main() {

char ch;

printf("Enter the char: ");

scanf("%c", &ch);

printf("Char in lowercase: %c\n", tolower(ch));

return 0;

}

Testing:

Enter the char: G

Char in lowercase: g

Enter the char: S

Char in lowercase: s

C program for newton's backward interpolation?

#include<stdio.h>

#include<conio.h>

#include<process.h>

#include<math.h>

void main()

{

int n;

int i,j;

float ax[10];

float ay[10];

float x;

float y=0;

float h;

float p;

float diff[20][20];

float y1,y2,y3,y4;

clrscr();

printf("\t\t!! NEWTON GRAGORY FORWARD INTERPOLATION FORMULA!!\n");

printf("\t\t By KRISHAN \t\t\n");

printf("\t\t enter the no of terms ->");

scanf("%d",&n);

printf("\n\t\t enter the value in form of x->");

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

{

printf("\n\t\t enter the value of x%d->",i+1);

scanf("%f",&ax[i]);

}

printf("\n\t\tenter the value in the form of y->");

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

{

printf("\n\t\tenter the value of y %d->",i+1);

scanf("%f",&ay[i]);

}

printf("\n\t\tenter the value of x for");

printf("\n\t\t which u want the value of y->");

scanf("%f",&x);

h=ax[1]-ax[0];

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

diff[i][1]=ay[i+1]-ay[i];

for(j=2;j<=4;j++)

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

diff[i][j]=diff[i+1][j-1]-diff[i][j-1];

do

{

i++;

}

while(ax[i]<x);

i--;

p=(x-ax[i])/h;

y1=p*diff[i-1][1];

y2=p*(p+1)*diff[i-1][2]/2;

y3=p*(p+1)*(p-1)*diff[i-2][3]/6;

y4=(p+2)*(p+1)*p*(p-1)*diff[i-3][4]/24;

y=ay[i]+y1+y2+y3+y4;

printf("\n\t\t when x=%6.4f,y=%6.8f",x,y);

printf("\n\n\n\t\t\t!! PRESS ENTER TO EXIT!!");

getch();

}

Write a simple program algorithms flow charts to find out how many of the numbers from 1 to 10 is greater than 4?

/* c program for how many of the numbers from 1 to 10 is greater than 4? */

#include

void main()

{

int i ,j=0; /* j is used for counting the nos greater than 4 from 1 to 10*/

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

if(i>4)

j++;

printf("\n The numbers greater than 4 , from 1 to 10 is %d",j);

}

Algorithm

step 1:start

step 2 :initialize j=0

step 3 :Initialize i=1,check whether i < 10 ,if true increment i else go to step 6

step 4: check whether i >4 If true go to step5 ,else go to step 3

step 5 :Increment j and then go to step 3

step 6:print the value of j

step 7 :Stop

Why do we avoid loops in programming?

We don't avoid loops in programming. Loops are a fundamental feature of many algorithms. If we need to iterate over a data sequence in order to perform the same set of operations upon each data element, we would use an iterative loop. If we need to repeatedly reduce a larger problem into one or more smaller instances of the same problem until the problem is small enough to be solved we'd use a recursive loop.