Program in 'c' to find the LCM of any given five numbers?
Just write a method or function that calculates the LCM for two numbers at a time. Then calculate the LCM for the first two numbers, get the LCM of the result with the third number, etc.
Just write a method or function that calculates the LCM for two numbers at a time. Then calculate the LCM for the first two numbers, get the LCM of the result with the third number, etc.
Just write a method or function that calculates the LCM for two numbers at a time. Then calculate the LCM for the first two numbers, get the LCM of the result with the third number, etc.
Just write a method or function that calculates the LCM for two numbers at a time. Then calculate the LCM for the first two numbers, get the LCM of the result with the third number, etc.
What is the name of the C compiler used by Linux?
gcc is the most common C-compiler for GNU/Linux platform.
What is use of user defined data in c?
to create user defined functions the user defined data is needed nd its useful to the programmer to create its own data.
C++ is general-purpose and portable, which is common to many high-level languages, but it excels in terms of performance, comparable to that of assembly language. This is not surprising given the amount of work that goes into optimising the native machine code that the C++ compiler produces.
Java is arguably more popular today (especially with amateur programmers), but it doesn't perform well when compared to C++. This is largely due to the much higher level of abstraction which requires compiled programs to be executed and interpreted by the Java virtual machine. The main advantage of Java is that the abstraction allows Java programs to be run on any platform that supports the JVM without the need to modify the source code and recompile, which is the main disadvantage of C++. However, in terms of performance alone, few languages can compete with C++, hence its huge popularity in the community.
Who is the father is c language?
Sorry to disappoint you, but you cannot father a programming language. But you can invent one, like Dennis Ritchie did with C forty years ago.
What type of a program is used in order to enter c source code?
What type of a program is used in order to enter C source code
Write a c plus plus program to find the largest and second largest number from an array?
#include <iostream.h>
#include <conio.h>
class largest
{
public:
int a[10],i,b,s;
void get();
};
void largest :: get()
{
cout<<"Enter the numbers"<<endl;
for(i=0;i<10;i++)
{
cin>>a[i];
}
b=0;
for(i=0;i<10;i++)
{
if(b>=a[i])
b=b;
else
b=a[i];
}
cout<<"Largest No-"<<b<<endl;
s=0;
for(i=0;i<10;i++)
{
if((s>=a[i])&&(s!=b))
s=s;
else
s=a[i];
}
cout<<"Second Largest No-"<<s<<endl;
}
void main()
{
clrscr();
largest l;
l.get();
getch();
}
How many bytes are allocated to an int in C?
16 bit and 32 bit are the most common values. See sizeof.
// macros for simplicity
#define MAX(x,y) (x>y?x:y)
#define MIN(x,y) (x<y?x:y)
/*
** drawLine
**
** Draw a line from vertex (x0,y0) to vertex (x1,y1) using
** the midpoint line algorithm, implemented using OpenGL.
**
*/
void drawLine( GLint x0, GLint y0, GLint x1, GLint y1 ) {GLint dE, dNE, x, y, d, dx, dy;
// check if we need to switch the points
if( x0 > x1 ) {
x0 = x0 + x1;
x1 = x0 - x1;
x0 = x0 - x1;
y0 = y0 + y1;
y1 = y0 - y1;
y0 = y0 - y1;}
// calculate deltas
dy = y1 - y0; dx = x1 - x0;
// special cases
if( dx -1 - diag down-right
glBegin(GL_POINTS);
for( x = x0, y = y0; x <= x1; x++, y-- ) {
glVertex2i(x,y);}
glEnd();}else { // general cases
// midpoint algorithm
if( abs(dy) < dx ) { // small slope
dE = 2 * abs(dy);
dNE = 2 * (abs(dy) - dx);
d = dE - dx;
glBegin(GL_POINTS);
for( x = x0, y = y0; x <= x1; x++ ) {
glVertex2i(x,y);
if( d <= 0 ) {
d+= dE;}else {
y += (dy>0?1:-1);
d += dNE;}}// for x = x0 to x1
glEnd();}else { // large slope
dE = 2 * dx;
dNE = 2 * (dx - abs(dy));
d = dE - abs(dy);
glBegin(GL_POINTS);
for( x = x0, y = y0; (y0 < y1 && y <= y1)
(y0 > y1 && y >= y1); y+=(y0 < y1?1:-1) ) {
glVertex2i(x,y);
if( d <= 0) { x ++;
d+= dE; }else { d += dNE; }}// for y = y0 to y1
glEnd();}}
}// drawLine()
Where the local variables will be stored?
When you declare a variable and it's data type in a function, it is stored in the specific space for memory allocated by the variable type identifier known as the "stack."
Who makes and where can you get the best laser pointer?
amazon.com has a wide variety of laser pointers.
C program for knapsack algorithm?
#include<stdio.h>
#include<conio.h>
int w[10],p[10],v[10][10],n,i,j,cap,x[10]={0};
int max(int i,int j)
{
return ((i>j)?i:j);
}
int knap(int i,int j)
{
int value;
if(v[i][j]<0)
{
if(j<w[i])
value=knap(i-1,j);
else
value=max(knap(i-1,j),p[i]+knap(i-1,j-w[i]));
v[i][j]=value;
}
return(v[i][j]);
}
void main()
{
int profit,count=0;
clrscr();
printf("\nEnter the number of elements\n");
scanf("%d",&n);
printf("Enter the profit and weights of the elements\n");
for(i=1;i<=n;i++)
{
printf("For item no %d\n",i);
scanf("%d%d",&p[i],&w[i]);
}
printf("\nEnter the capacity \n");
scanf("%d",&cap);
for(i=0;i<=n;i++)
for(j=0;j<=cap;j++)
if((i==0)(j==0))
v[i][j]=0;
else
v[i][j]=-1;
profit=knap(n,cap);
i=n;
j=cap;
while(j!=0&&i!=0)
{
if(v[i][j]!=v[i-1][j])
{
x[i]=1;
j=j-w[i];
i--;
}
else
i--;
}
printf("Items included are\n");
printf("Sl.no\tweight\tprofit\n");
for(i=1;i<=n;i++)
if(x[i])
printf("%d\t%d\t%d\n",++count,w[i],p[i]);
printf("Total profit = %d\n",profit);
getch();
}
What is the C program for byte stuffing with the output?
//Sender
#include<string.h>
#include<stdio.h>
#include<unistd.h>
#include<fcntl.h>
#define SIZE 40
struct frame
{
char str[SIZE+1];
char tmp[2*SIZE];
char flag;
char e;
char final[2*SIZE];
}s;
main()
{int fd,len1;
int i,j,len;
fd=open("b1",O_WRONLY);
printf("\nEnter flag character and escape character for byte-stuffing:");
scanf("%c %c",& s.flag,&s.e);
printf("\nEnter string:");
scanf("%s",s.str);
len=strlen(s.str);
for(i=0,j=0;i<len;i++,j++)
{
if(s.str[i]==s.flag)
{
s.tmp[j]=s.e;
s.tmp[j+1]=s.flag;
j++;
continue;
}
else if(s.str[i]==s.e)
{
s.tmp[j]=s.e;
s.tmp[j+1]=s.e;
j++;
continue;
}
else
{
s.tmp[j]=s.str[i];
}
}
printf("\nAppended string is==>%s \n",s.tmp);
len1=strlen(s.tmp);
for(i=0,j=0;i<=len1;i++,j++)
{
if((i==0)(i==len1))
{
s.final[j]=s.flag;
s.final[j+1]=s.tmp[i];
j++;
continue;
}
else
{
s.final[j]=s.tmp[i];
}
}
printf("\nFianal string is==>%s\n",s.final);
write(fd,&s,sizeof(s));
}
//Reciver
#include<string.h>
#include<stdio.h>
#include<unistd.h>
#include<fcntl.h>
#define SIZE 40
struct frame
{
char str[SIZE+1];
char tmp[2*SIZE];
char flag;
char e;
char final[2*SIZE];
}r;
main()
{
int fd,len1;
int i,j,len;
mknod("b1",010666,0);
fd=open("b1",O_RDONLY);
read(fd,&r,sizeof(r));
printf("\nFlag character is==>%c\n",r.flag);
printf("\nEscape character is ==>%c\n",r.e);
printf("\nAnd actual message was ==>%s\n",r.str);
printf("\nReceived message is %s\n\n",r.final);
}
/*****************
[mca222@rcclinux mca222]$ cc -os byte_s.c
[mca222@rcclinux mca222]$ cc -or byte_r.c
[mca222@rcclinux mca222]$ ./r&
[1] 1570
[mca222@rcclinux mca222]$ ./s
Enter flag character and escape character for byte-stuffing:#
@
Enter string:sim#andh@ar
Sending message is==>#sim@#andh@@ar#
Flag character is==>#
Escape character is ==>@
And actual message was ==>sim#andh@ar
Received message is #sim@#andh@@ar#
What is a complier in computer language?
A compiler is a program that translates a programming language (like c++, java, pascal, php etc...) to a language that computers can "understand" (i.e. "1001010110101010...")
How do you write a c program that reads a six digit integer and prints the sum of its six digits?
int sum_digits (int num) {
int sum;
sum =0;
while (num) {
sum += num % 10;
num /= 10;
}
return sum;
}
Example usage:
int main (void) {
int i;
printf ("Input a 6-digit number: ");
scanf ("%6d", &i);
printf ("The sum of the digits in %d is: %d\n", i, sum_digits (i));
return 0;
}
Why can't we perform binary search in linked lists?
The binary search algorithm depends on equal (or direct) access time for any selected element of a list. A linked list, however, does not provide that, so a binary search is inappropriate for a linked list.
Write an algorithm find out the sum of first n odd numbers?
Algorithm: sum_even
Input: an integer, n, such that n>0
Output: the sum of all even integers within the open range (1:n)
sum := 0
val := 2
while (val < n) do
{
sum := sum + val
val := val + 2
}
return sum
Note that you explicitly specified between 1 and n, which literally means both 1 and n should be excluded from the sum. 1 would be excluded anyway since it is not an even number, however if we wish to include n, then use the following algorithm instead:
Algorithm: sum_even
Input: an integer, n, such that n>0
Output: the sum of all even integers within the half-open range (1:n]
sum := 0
val := 2
while (val <= n) do
{
sum := sum + val
val := val + 2
}
return sum
Write a program in C language to implement the apriori algorithm?
JavaScript is one program that has been written in C to implement the Apriori algorithm. There are also several other known programs available on the Internet that implement it as well.
Write a c program to find smallest among three using function with pointers?
Please visit http://talentsealed.blogspot.com/2009/10/to-find-smallest-among-three-using.htmlfor answer.
Explain the differences between C Language and C plus plus Language?
i want a c programme....if i have a collection of alphabhate appox 2000 or
more...alphabates r repeted...
i want to write a prograam such that first 7 terms r wrriten in first
line then next 7 alphabets r writen in next line..
not fully clear ??
i would give u an example: TTCATCATTCCTAATATTTTTCTTGTAGTTGTTTTAAAAAAGGAATTAAC
ATCCAATATTCTGTATTACATACTGTACACCAGATTTTGATTTCAGAAAA
CAATATTTGATGTATAACTTCCACTTAATTTAAATTTAATAAACTTTTAT
TTCAGAGATATTTGATTAGTTTACAATCTAAGAGTTATTCTTAAGAGTTT
CAGTGGAATTTTCTTAATTTTTCTAAAGATATTCCTACTCTCTTGATCAT
ATTCTAAGTACATATGAGTACATGTACATTCTTATACAATGTCTAAATGG
GTTAGAAAATTATTATACCTATAGAAGCGAAACTTGGAAATTAATAGAAT
CACTTAAACCAAAATCTTTATAAGACACAATTCTATTGATTTTAAAGCTT
CTGCTTTCCAGGCTCTGTTTTCCAGAGTTTATAATTACGTAGTTTTTAGT
AGATGAAAATAATGGATTCTTGTACCTAACATTTTATCCTCTTAGATCTA
AGAGCCGAAGCTATAGAACTTTGTTAGACTATTTGGCAAGCAAAATATAT
GACAGTAAATATCAGAATTTTATGGTTTGACCAGCGCTTATCACATTCCC
AATTCAGTGAGAAAAATTCATCTGGGACACAACAGGGTACTCTTCTCTGT
TTGCCCAGAATCAGCTCTGGATTTTAAGCCCAGACTTCAGTGGACCCAGA
TAGAAAATATAAAGTCTCTGATCTATAGGCCACATCAGGATGTTATTTTA
TGAAGAGTTCTAGAGCAAGGTTGCGGAAATCGGGGTGGAGATGGGGAGCA
GTGACTCCTCCAAATATTCATTGCTAACAGGCCATTCTATGCAGTTTGTT
TTAACAAATCCTGGGTTAAACTGAGGCCACAGGACATGATGGGCTGTTCT
ATAAAGCATTCTAAGTGGAGAGGAGACGATAGGGCATATGAAATTCACTA
AACTCTCTGGAAAAAAAATATGTATATATTAAAAACCAAGACTGGAATCA
GTGCAACAGTGGGAACTACCTTTTACAAGTATCCATTGCTTCATAAACTC
CATTTGTTTGGACCAATCCCTTAAACAAAAGCAAGGCAAATTTTACATGG
ATTTAGAGCCTAGGTCAGGTTATTAGGATTATAAATTTTCCACTGGTATG
TCATTGTGATTATCTTTGTTTTTGTCTTTCTGAAAGATTGGATTTTCTAT
AACACCTTGTGTAAGAAAATAAAAAACTTGATCTAACTGAA suppose this is a sequence...
i want to write first 7 alphabets in first line...(1st to seventh)
TTCATCA
next 7 in next line...(2nd to ...8th)
TCATCAT
next 7(3rd to 9th)....and so on.... can u help me to write this programm.... if u write this programm u get a treat from me....
Explain the term Recursion with example?
Recursion is when a function (procedure) calls itself.
Example:
int Fib (int n)
{
if ((n==1)(n==0))return 1;
else return Fib(n-1) + Fib(n-2);
}