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 program to find the sum of squares of the given number?

#include<stdio.h>

int main()

{

int count,i,j,k,n,*a,sum=0;

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

scanf("%d",&n);

a=malloc(n*sizeof(int));

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

{

count=0;

j=1;

while(j<=i)

{

if(i%j==0 && i!=2)

count++;

j++;

}

if(count==2 count==1)

{

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

a[k]=i;

}

}

for(k=0;k<=n;k=k+1)

printf("%d\t",a[k]);

for(k=0;k<=n;k=k+2)

sum+=a[k] * a[k];

printf("The sum of squares of alternative prime numbers is=%d",sum);

getchar();

return 0;

}

Write a program in c to print a mark sheet?

import java.util.*;

import java.lang.String;

import java.io.*;

import java.util.Date;

import java.util.Timer;

class project

{

public static void main(String args[]) throws IOException

{

String sub1,sub2,sub3,sub4,sub5,sub6;

String name,sem;

int m1,m2,m3,m4,m5,m6,m7;

//Date dt = new Date(now.getTime()

int prn_no,seat_no,total;

float per;

float temp;

String msg="*";

long currentTimeInMillis = System.currentTimeMillis();

Date today = new Date( currentTimeInMillis );

Scanner in=new Scanner(System.in);

BufferedReader b=new BufferedReader(new InputStreamReader(System.in));

System.out.println("Enter name of student=");

name=b.readLine();

System.out.println("Enter prn number =");

prn_no=in.nextInt();

System.out.println("Enter name of semester=");

sem=b.readLine();

System.out.println("Enter Roll number =");

seat_no=in.nextInt();

System.out.println("Enter first subject name =");

sub1=b.readLine();

System.out.println("Enter marks =");

m1=in.nextInt();

System.out.println("Enter second subject name =");

sub2=b.readLine();

System.out.println("Enter marks =");

m2=in.nextInt();

System.out.println("Enter third subject name =");

sub3=b.readLine();

System.out.println("Enter marks =");

m3=in.nextInt();

System.out.println("Enter fourth subject name =");

sub4=b.readLine();

System.out.println("Enter marks =");

m4=in.nextInt();

System.out.println("Enter fifth subject name =");

sub5=b.readLine();

System.out.println("Enter marks =");

m5=in.nextInt();

System.out.println("\t\t\t\t\t\t DR.BABASAHEB AMBEDKAR MARATHWADA UNIVERSITY");

System.out.println("\t\t\t\t\t\t\tAurangabad-431004");

System.out.println("STUDENT NAME:"+name+"\t\t\tprn :"+prn_no+"\t\t\tSEAT NO:"+seat_no+"\t\t\tSEMESTER:"+sem);

System.out.println("------------------------------------------------------------------------------------");

System.out.println("\n\n| SUBJECTS"+"\t\t\t\t|\tMAXIMUM MARKS"+"\t|\t min marks"+"\t|\tOBTAINED MARKS");

System.out.println("------------------------------------------------------------------------------------");

if(m1>40)

msg="";

else

msg="*";

System.out.println("|"+sub1+"\t\t\t\t\t\t|\t100\t\t\t\t|\t40\t\t\t|\t"+m1);

if(m2>40)

msg="";

else

msg="*";

System.out.println("|"+sub2+"\t\t\t\t\t\t|\t100\t\t\t\t|\t40\t\t\t|\t"+m2);

//System.out.println(+sub2+"\t\t\t"+"|"+"\t\t100"+"\t\t\t"+"|"+"\t\t40"+"\t\t\t\t"+"|"+"\t\t"m2+msg+"\t|");

if(m3>40)

msg="";

else

msg="*";

System.out.println("|"+sub3+"\t\t\t\t\t\t|\t100\t\t\t\t|\t40\t\t\t|\t"+m3);

//System.out.println(+sub3+"\t\t\t"+"|"+"\t\t100"+"\t\t\t"+"|"+"\t\t40"+"\t\t\t\t"+"|"+"\t\t"m3+msg+"\t|");

if(m4>40)

msg="";

else

msg="*";

System.out.println("|"+sub4+"\t\t\t\t\t\t|\t100\t\t\t\t|\t40\t\t\t|\t"+m4);

//System.out.println(+sub4+"\t\t\t"+"|"+"\t\t100"+"\t\t\t"+"|"+"\t\t40"+"\t\t\t\t"+"|"+"\t\t"m4+msg+"\t|");

if(m5>40)

msg="";

else

msg="*";

System.out.println("|"+sub5+"\t\t\t\t\t\t|\t100\t\t\t\t|\t40\t\t\t|\t"+m5);

//System.out.println(+sub5+"\t\t\t"+"|"+"\t\t100"+"\t\t\t"+"|"+"\t\t40"+"\t\t\t\t"+"|"+"\t\t"m5+msg+"\t|");

System.out.println("------------------------------------------------------------------------------------");

total=m1+m2+m3+m4+m5;

System.out.println("\t\t\t\t\t\t\t\t\t\t\t\t\t"+"|"+"\t\t TOTAL ::"+total+"/500");

temp=(float)total/500;

per=temp*100;

System.out.println("\t\t\t\t\t\t\t\t\t\t\t\t\t"+"|"+"\t\t PERCENTAGE ::"+per+"%");

System.out.println("------------------------------------------------------------------------------------");

if(m1<40&&m2<40&&m3<40&&m4<40&&m5<40)

{

System.out.println("\t\t\t\t\t\t\t\t\t\t\t\t\t"+"|"+"\t\t RESULT ::DROPPED");

System.out.println("------------------------------------------------------------------------------------");

}

else if(m1<40&&m2<40m3<40&&m4<40&&m5<40)

{

System.out.println("\t\t\t\t\t\t\t\t\t\t\t\t\t"+"|"+"\t\t RESULT ::A.T.K.T.");

}

else if(per<35)

{

System.out.println("\t\t\t\t\t\t\t\t\t\t\t\t\t"+"|"+"\t\t RESULT ::FAILED");

}

else if(per>=35&&per<40)

{

System.out.println("\t\t\t\t\t\t\t\t\t\t\t\t\t"+"|"+"\t\t RESULT ::passed");

}

else if(per>=40&&per<59)

{

System.out.println("\t\t\t\t\t\t\t\t\t\t\t\t\t"+"|"+"\t\t RESULT :::passed with SECOND CLASS");

}

else if(per>=60&&per<75)

{

System.out.println("\t\t\t\t\t\t\t\t\t\t\t\t\t"+"|"+"\t\t RESULT :passed with first class");

}

else if(per>=75)

{

System.out.println("\t\t\t\t\t\t\t\t\t\t\t\t\t"+"|"+"\t\t RESULT :passed with DISTINCTION class");

}

System.out.println( today );

}

}

What is the relationship between high level language code and low level language code?

All types of programming languages have one property in common: all languages, ultimately and in some manner, lead to machine instructions upon which the processor operates.

Some higher programming languages, especially those of a traditional design such as the C programming language, might generate code in a low level language (i.e. assembly language) as an intermediate step during compilation. However, most modern designs do not implement or expose this as an explicit step, and transcoding of higher to lower level languages is certainly not required.

The fact that all programming languages lead to executed machine code, however, does not mean that all language lead to a translation which results in executable code; interpreted languages, which include popular modern languages such as Java and the .NET family of languages, will generally execute machine code which interprets the language instructions, while compiled languages (which includes most forms of C) generally generate directly executable machine code.

Program to find sum of two numbers in VB.NET language?

Option Explicit

Dim a as integer

Dim b as integer

Dim c as integer

Dim result as integer

a=val(text1.text)

b=val(text2.text)

c=val(text3.text)

result=a+b+c

'now we want to push the result to another text box ,below code insert into the button click event

text4.text=result

text1.text=""

text2.text=""

text3.text=""

Rename the cmd button

As sum.

And run the program by pressing F5 key.

Static variable in c plus plus?

There are two uses for a static variable in C++. When declared outside of a class, a variable is regarded as being global. However a static variable is deemed local to the file in which it is declared. That is, the variable is scoped to the file, and cannot be accessed by code outside of that file. This aspect was inherited from C.

C++ also allows static variables to be declared inside a class. In this case, the variable is local to the class. By contrast, instance variables (non-static member variables) are local to each instance of the class. With static variables, there is only one instance of each variable which can be shared by all instances of the class. It is not unlike a global but it is scoped to the class.

Since all static variables are instantiated at compile time, they exist for the entire duration a program runs. Even if they fall from scope, they never lose their value. Static variables defined within a class are also available even when no instances of the class are instantiated. Their visibility outside of the class is dependent upon whether they are declared public, protected or private.

Why use static variable in programming language?

For C programming, the use of a static variable has two uses:

One reason is to hide the variable from other modules. The scope of the static variable is limited to the compilation unit that it is described in.

The second use of a static variable is to keep the value of the variable intact through the entire program execution unit.

What is 420F in C?

Start by taking the number in Fahrenheit and subtracting 32. Then divide the number by 9, and then multiply it by 5. This is how you convert Fahrenheit to Celsius or use the equation C = (F - 32) × 5/9
In this case, the answer is about 215.56 degrees Celsius.

Complexity of sequential search?

The simplest and slowest searching method; the only possible method when the data is unsorted and/or only sequential access is possible (eq. processing a tape file).

I think he's looking for time complexity which I believe is just n

Why static variables in a function have global extent?

A variable declared static outside of a function has a scope the of the source file only. It is not a global variable. A variable declared outside of a function and without the static qualifier would be a global variable.

Who is the author of Borland Turbo C?

A company called Borland. (Actually it was based on the former product Wizard C of Bob Jervis.)

Why the built in pointer a useful feature of the microscope?

It gives users a better way to identify and point out certain parts of the slide. The feature also highlights special aspects Êor characteristics found among the selection.

What is difference constructor and function in programming C plus plus?

A Constructor is called when you are making a new instance of a class and member functions are functions that you can call within your class or else call using the instance of that class.

for example


class Foo {


public:

int bar;

Foo(int bar) {this->bar = bar;}

inc_bar(); {this->bar++;}

};


Foo instance(10); // Constructor is called and bar is set to 10

cout << instance.bar << endl;

instance.inc_bar(); // call the member function to increment bar

cout << instance.bar << endl;

What is difference between source programm and an abject module?

Source code is the "source" of a program. This means that this is the code provided by a programmer in a human readable and modifiable form. When a programmer writes a program, he/she will develop source code in a programming language such as C, C++, maybe Pascal among others.

An object module can mean two different things depending on the context. An object module generally is an intermediate step between source code and an executable file like a .EXE on Windows. An executable file is actually what is generated by a compiler (like GCC or Visual C++) from source code and is effectively "machine language". It is not human readable and to a certain extend is not even machine readable as a whole. The way it works is that part of an executable file contains information to tell the operating system how to read the file into memory and where to start running it. The operating system will then tell the CPU where to start reading the program while it is in memory. The executable is a series of instructions understandable by the CPU and it performs them one by one as the program defines. Consider this overall process of compiling as someone writing a recipe for a certain type of food and then another person will compile a list of instructions in way that a resturant kitchen staff can follow it over and over. A different compiler might even translate the recipe to a different spoken language. In a similar fashion, one compiler might translate from C to Intel x86 while another would translate to IBM PowerPC.

An object file often is an intermediate step between source and executable. This file is the result of compiling a single source file as opposed to all the source files of an entire program. Some programs fit in a single source file, but others can be hundreds or even thousands of source files. To compile the Linux kernel in it's full form as a single static executable can require compiling tens of thousands of files. Once each file is mostly translated to machine language and stored as an object file, a program called a linker is used to merge those files together into a single executable. This process might be seems as taking the recipe for and English muffin, another for hollandaise sauce and a final one for Eggs Benedict and merging all the steps together into a single recipe which a kitchen staff can execute in a given order to start with raw ingredients and produce the final product.

What is the difference between preprocessor directives and header files?

Preprocessor: All the preprocessor commands written in a high level language are processed by the preprocessor before compiler takes over.

Example: "#define MAX_ROWS 10"

Preprocessor finds all the places and replaces MAX_ROWS with 10 in the files of the project.

Compiler: This software, converts the code written in high-level language into object file. Compiler converts all the files of a given project at once.

Is c procedural or structural language?

Structural language is a language in which a particular structure is defined. It is used to make execution and understanding easier.

Ex : COBOL

Structural language does not have function calls.

Procedural language is a language in which function calls are allowed.

Ex : C

In this a particular procedure is followed every time.

IMB.

What are the rules of creating identifier?

Identifiers refers to the names of variables, functions and array. These are user defined names and consist of a sequence of letters and digits, with a letters as a first character.Both uppercase and lowercase letters are permitted, although lowercase letters are commonly used. The underscore character is also permitted in identifiers. It is usually used as a link between two words in long identifiers.

In C, identifiers may contain any alphanumeric characters (a-z, A-Z, 0-9) as well as underscores (_), but must not begin with a number.

Why should you indent the statement in the body of a loop?

In some programming languages like Python, the indentation of the text indicates how nested it is and is required for a loop to function properly. However, for most languages, indenting the body of the loop is simply for style and readability.

Is there anything similar between C and C plus plus with reference to data hiding?

No. Data hiding is a feature of object oriented programming. C does not support OOP, and therefore has no private member access. All members are public in C.

What is the importance of data sturture in a programming language?

According to Wikipedia-"In computer science, a data structure is a particular way of storing and organizing data in a computer so that it can be used efficiently.Data structures are used in almost every program or software system. Data structures provide a means to manage huge amounts of data efficiently, such as large databases and internet indexing services. Some formal design methods and programming languages emphasize data structures, rather than algorithms, as the key organizing factor in software design."

What are the properties of binary tree?

  • A binary tree of n elements has n-1 edges

  • A binary tree of height h has at least h and at most 2h - 1 elements

  • The height of a binary tree with n elements is at most n and at least ?log2 (n+1)?

What time of loop is used when you know how many times the loop instructions should be processed?

It's best to use a for loop.

For example, if you want 10 iterations:

for (int i = 1; i <= 10; i++)
{
// Any commands you write here will repeat 10 times.

}