#include<stdio.h> main() { int a,b,c,d; // The four integers to be asked printf("Give the first integer: "); //asks for the first integer scanf("%d",&a); // puts the user input in the address of the integer "a" printf("Give the second integer: "); //same explanations scanf("%d",&b); printf("Give the third integer: "); scanf("%d",&c); printf("Give the fourth integer: "); scanf("%d",&d); printf("1. The sum of the four integers is: %d",a+b+c+d); //prints the sum of the four integers given by the user, notice the "a+b+c+d" at the end) printf("2. The sum of the first two numbers minus the sum of the last: %d",a+b-c-d); //prints the second condition by putting the correct operations return 0; //ends the program } I never tested this program though, but i think it would work.
How do you write negative numbers on a calculator?
Enter the number, then press the button marked with +/-
Draw a flowchart that will add all integers from 1 to 50?
A Sample java method that can do this sum of all numbers between 1 to 50
public int sumNumbers(){
int retVal = 0;
for(int i = 0; i <=50; i++){
retVal = retVal + i;
}
return retVal;
}
How do you implement Pascal's Triangle in C plus plus?
There are many ways to implement Pascal's Triangle in C++. One of the easiest ways is to use a vector of vectors, which is essentially a two-dimensional dynamic array. Although you could use a static 2D array, the matrix would need to be sparse because the first row has only one value, while the second has two values, and so on. Unused elements would need to store the value zero, but unused elements are wasteful. You could improve upon this by creating a 1D array of dynamic arrays, however C++ vectors are much easier to work with and achieve the same thing.
The following program asks the user to enter the top value of the triangle and the number of rows in the triangle. The range of acceptable values has been limited to ensure all printed triangles will fit comfortably within an 80-character console window.
The program employs a simple class definition to encapsulate the triangle and its methods. The default constructor builds the triangle using the top value and the number of rows supplied from the user-input, while the print function displays the triangle's values in a symmetric triangle formation.
#include<iostream>
#include<iomanip>
#include<vector>
#include<string>
#include<sstream>
// Some typdefs to simplify coding.
typedef unsigned int uint;
typedef std::vector<uint> row;
// Simple class definition.
class pascal_triangle
{
public:
pascal_triangle(uint top=1, uint rows=10);
void print();
private:
const uint get_width();
std::vector<row> m_triangle;
};
// Default constructor:
pascal_triangle::pascal_triangle(uint top, uint rows)
{
for(uint i=0;i<rows;++i)
{
row r;
uint x=top;
for(uint k=0;k<=i;++k)
{
r.push_back(x);
x=x*(i-k)/(k+1);
}
m_triangle.push_back(r);
}
}
// Return the width required for the largest value.
const uint pascal_triangle::get_width()
{
// Reference the last row of the triangle.
row& r=m_triangle[m_triangle.size()-1];
// Determine the largest value in that row.
uint largest=0;
for(uint i=0;i<r.size();++i)
if(r[i]>largest)
largest=r[i];
// Determine required width plus one space.
uint width=1;
do
{
largest/=10;
++width;
} while( largest );
// Return an even width.
return(width+width%2);
}
// Print the given triangle:
void pascal_triangle::print()
{
// Call private method to determine width.
const uint width=get_width();
// Repeat for each row...
for(uint i=0;i<m_triangle.size();++i)
{
// Insert half-width padding spaces.
std::cout<<std::setw((m_triangle.size()-i)*(width/2))<<' ';
// Print the row values.
row& r=m_triangle[i];
for(uint j=0;j<r.size();++j)
std::cout<<std::setw(width)<<r[j];
std::cout<<std::endl;
}
std::cout<<std::endl;
}
// Print the given range:
void print_range(const uint min,const uint max)
{
std::cout<<'['<<min<<".."<<max<<']';
}
// Return a natural number in the given range from user input:
uint enter_natural(const std::string& prompt,const uint min,const uint max)
{
uint result=0;
while(!result)
{
std::cout<<'\n'<<prompt<<' ';
print_range(min,max);
std::cout<<": ";
std::string in;
std::getline(std::cin,in);
std::stringstream(in)>>result;
if(result<minresult>max )
{
std::cout<<"The valid range is ";
print_range(min,max);
std::cout<<"\nPlease try again.\n"<<std::endl;
result=0;
}
}
std::cout<<std::endl;
return(result);
}
int main()
{
std::cout<<"Pascal's Triangle\n"<<std::endl;
uint top=enter_natural("Enter top value",1,10);
uint rows=enter_natural("Enter number of rows",2,10);
pascal_triangle t(top,rows);
t.print();
return(0);
}
#include<iostream.h>
#include<conio.h>
main()
{
int i,j;
i=0;
j=0;
for(i=1;i<=5;i++)
{
if(i>j){
cout<"the value of i is="<<i;
}
else
{
cout<<"the value of j is="<<j;
}
}
getch();
}
How do you find the quartile in an even array of values?
Divide the array in half and get the median of each half
When ur not gonna use it after all.
This video helps you figure it out, quick and simple: http://www.howcast.com/videos/284366-How-To-Void-a-Check
What is the salary of a java programmer and a c plus plus c programmer?
Java programmers earn an average of £52,500.
C++ programmers earn an average of £57,500.
See sources and related links, below, for more information.
What is Max airspeed in Class C and D airspace?
Sec. 91.117 - Aircraft speed.
(a) Unless otherwise authorized by the Administrator, no person may operate an aircraft below 10,000 feet MSL at an indicated airspeed of more than 250 knots (288 m.p.h.).
(b) Unless otherwise authorized or required by ATC, no person may operate an aircraft at or below 2,500 feet above the surface within 4 nautical miles of the primary airport of a Class C or Class D airspace area at an indicated airspeed of more than 200 knots (230 mph.). This paragraph (b) does not apply to any operations within a Class B airspace area. Such operations shall comply with paragraph (a) of this section.
Program to perform binary search operations using dynamic memory allocation?
#include<iostream>
#include<iomanip>
#include<vector>
#include<algorithm>
#include<random>
#include<time.h>
void initialise (std::vector<unsigned>& data)
{
// Pseudo-random number generator (range: 1 to 99).
std::default_random_engine generator;
generator.seed ((unsigned) time (NULL));
std::uniform_int_distribution<unsigned> distribution (1, 99);
data.clear();
unsigned max_elements(50);
while (max_elements--)
data.push_back (distribution (generator));
}
int linear_search(std::vector<unsigned>& data, unsigned value, unsigned& comparisons)
{
int index(-1);
for( comparisons=0; comparisons<data.size() && index<0; ++comparisons)
if (data[comparisons] -1)
{
std::cout << "not found. ";
}
else
{
std::cout << "found at index " << binary_index << ". ";
}
std::cout << "Comparisons: " << binary_comparisons << std::endl;
}
}
What is the difference between a data file and a program file?
Technically they're BOTH "data" files, it's just that one is organized in a way that it can be "executed" by the computer.
Write an algorithm to find the transpose of a matrix?
-Algorithm-
1.START
2.Take m1 and m2 as integer matrix.
3.Input the values for original matrix and store it in m1.
4.Convert each row of the matrix ma in to column of matrix m2.
5.Display both matrix m1 and m2.
6.STOP.
'C' program
#include<stdio.h>
void main()
{
int m1[3][3],m2[3][3];
int i,j;
for (i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
printf("\n Enter value of%d rows and %d cols: ",i+1,j+1);
scanf("%d",&m1[i][j]);
}
}
for(i=0;i<3;i++);
{
for(j=0;j<3;j++)
{
m2[j][i]=m1[i][j];
}
}
printf("\n Original Matrix");
printf("\n ---------------\n");
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
printf("%d\t",m1[i][j]);
}
printf("\n") ;
}
printf("\n Transpose Matrix");
printf("\n ----------------\n");
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
print("%d\t",m2[i][j]);
}
printf("\n")
}
If the array is static you can simply point at the first element. For dynamic arrays you can allocate a contiguous block to a single pointer which can then be subdivided using a one-dimensional array of pointer to pointers, each of which points to a one-dimensional array of pointers, each of which points to a separate object within the array. For extremely large arrays, however, it is better to split the elements into separate one-dimensional arrays, by creating a one-dimensional array of pointer to pointers first, then allocating each of those pointers to a separate one-dimensional array of pointers, each of which points to a separate one-dimensional array of objects. Either way, you must destroy all the individual arrays in the reverse order of creation.
#include<stdio.h>
#include<conio.h>
void main(void)
{
FILE *fp;
char ch;
int count=0;
clrscr();
fp=fopen("seo.c","r");
while((ch=fgetc(fp))!=EOF)
{
if(ch=='\n')
{
count++;
printf("%d\n",count); }
else
printf("%c",ch);}
fclose(fp);
getch();
}
How to declare scalar variable in ASP .Net?
you must have forgotten to add parameters , in sql and asp.net when u want some queries u must add parameter to your query like cmd.Parameters.AddWithValue("@student_name", txtName.Text); if u dont add @student_name it will show u a error needing to declare sclar variable
Meaning of signed integer in c language?
signed integer means that it has a sigh (+ or -). Using another words you say that signed variable can be positive as well as negative. unsigned variables can be only positive.
# include <stdio.h>
# include <conio.h>
int main ()
{
char a;
printf("Enter the number");
scanf("%c", &a);
(a>=97 && a<=122)?
printf("\n\nIt is a lower case alphabet"):printf("\n\nIt is not a lower case alphabet");
getch();
getch();}
Longest common subsequence problem program in c?
#include<stdio.h>
#include<string.h>
int max(int a,int b)
{
return a>b?a:b;
}//end max()
int main()
{
char a[]="xyxxzxyzxy";
char b[]="zxzyyzxxyxxz";
int n = strlen(a);
int m = strlen(b);
int i,j;
for(i=n;i>=1;i--)
a[i] = a[i-1];
for(i=m;i>=1;i--)
b[i] = b[i-1];
int l[n+1][m+1];
printf("\n\t");
for(i=0;i<=n;i++)
{
for(j=0;j<=m;j++)
{
if(i==0 j==0)
l[i][j]=0;
else if(a[i] == b[j] )
l[i][j] = l[i-1][j-1] + 1;
else
l[i][j] = max(l[i][j-1],l[i-1][j]);
printf("%d |",l[i][j]);
}
printf("\n\t");
}
printf("Length of Longest Common Subsequence = %d\n",l[n][m]);
return 0;
}
How function can be used as reusability?
You mean reusable? Well it can be serially or parallel reusable.
How do you do matrix multiplication in c using structure?
You took an example of The Product AB is determined as the dot products of the ith row in A and the jth column in B,placed in ith row and jth column of the resulting m x p matrix C.
so: this may help you.
#include <stdio.h>
#include <stdlib.h>
// function prototypes
void Matrix_Mult( int a1[][3], int a2[][4], int a3[][4] );
void Matrix_MultAlt( int a1[][3], int a2[][4], int a3[][4] );
int dot3(const int a1[][3], const int a2[][4], int row, int col);
void PrnNx4 (int ar[][4], int n);
//---------------------------------------------------------------------------------
// Function: main(void)
// Description:
// demonstration of Matrix Multiplication
//
// Programmer: Paul Bladek
//
// Date: 10/31/2001
//
// Version: 1.0
//
// Environment: Hardware:IBM Pentium 4
// Software: Microsoft XP with .NET framework for execution;
// Compiles under Microsoft Visual C++.Net 2005
//
// Calls: Matrix_Mult(int a1[][3], int a2[][4], int a3[][4])
// Matrix_MultAlt(int a1[][3], int a2[][4], int a3[][4])
// PrnNx4(int ar[][4]
//
//
// Parameters: int a1[][3] -- left matrix
// int a2[][4] -- right matrix
// int a3[][4] -- answer matrix
//
// Returns: EXIT_SUCCESS
// ------------------------------------------------------------------------------
int main(void)
{
int A[2][3] = {{1, 3, 4},
{2, 0, 1}},
B[3][4] = {{1, 2, 3, 1},
{2, 2, 2, 2},
{3, 2, 1, 4}},
C[2][4] = {{0, 0, 0, 0},
{0, 0, 0, 0}};
Matrix_Mult(A, B, C);
PrnNx4(C, 2);
Matrix_MultAlt(A, B, C); // alternate form that calls dot3
PrnNx4(C, 2);
return EXIT_SUCCESS;
}
//---------------------------------------------------------------------------------
// Function: Matrix_Mult(int a1[][3], int a2[][4], int a3[][4])
// Description:
// multiplies a 2X3 matrix by a 3X4 matrix
//
// Programmer: Paul Bladek
//
// Date: 10/31/2001
//
// Version: 1.0
//
// Environment: Hardware:IBM Pentium 4
// Software: Microsoft XP with .NET framework for execution;
// Compiles under Microsoft Visual C++.Net 2005
//
// Calls: None
//
// Called By: main()
//
// Parameters: int a1[][3] -- left matrix
// int a2[][3] -- right matrix
// int a3[][3] -- answer matrix
// ------------------------------------------------------------------------------
void Matrix_Mult(int a1[][3], int a2[][4], int a3[][4])
{
int i = 0;
int j = 0;
int k = 0;
for(i = 0; i < 2; i++)
for( j = 0; j < 4; j++)
for( k = 0; k < 3; k++)
a3[i][j] += a1[i][k] * a2[k][j];
}
//---------------------------------------------------------------------------------
// Function: Matrix_MultAlt(int a1[][3], int a2[][4], int a3[][4])
// Description:
// multiplies a 2X3 matrix by a 3X4 matrix -- Alternate Form
//
// Programmer: Paul Bladek
//
// Date: 10/31/2001
//
// Version: 1.0
//
// Environment: Hardware:IBM Pentium 4
// Software: Microsoft XP with .NET framework for execution;
// Compiles under Microsoft Visual C++.Net 2005
//
// Calls: dot3(const int a1[][3], const int a2[][4], int row, int col)
//
// Called By: main()
//
// Parameters: int a1[][3] -- left matrix
// int a2[][3] -- right matrix
// int a3[][3] -- answer matrix
// ------------------------------------------------------------------------------
void Matrix_MultAlt(int a1[][3], int a2[][4], int a3[][4])
{
int i = 0;
int j = 0;
for( i = 0; i < 2; i++)
for( j = 0; j < 4; j++)
a3[i][j] = dot3(a1, a2, i, j);
}
//---------------------------------------------------------------------------------
// Function: dot3(const int a1[][3], const int a2[][4], int row, int col)
// Description:
// dot product of a1 row and a2 col
//
// Programmer: Paul Bladek
//
// Date: 10/31/2001
//
// Version: 1.0
//
// Environment: Hardware:IBM Pentium 4
// Software: Microsoft XP with .NET framework for execution;
// Compiles under Microsoft Visual C++.Net 2005
//
// Calls: None
//
// Called By: Matrix_MultAlt(int a1[][3], int a2[][4], int a3[][4])
//
// Parameters: int a1[][3] -- left matrix
// int a2[][3] -- right matrix
// int row -- the row number
// int col -- the column number
//
// Returns: the dot product
// ------------------------------------------------------------------------------
int dot3(const int a1[][3], const int a2[][4], int row, int col)
{
int k = 0;
int sum = 0;
for( k = 0; k < 3; k++)
sum += a1[row][k] * a2[k][col];
return sum;
}
//---------------------------------------------------------------------------------
// Function: PrnNx4(int ar[][4], int n)
// Description:
// prints out an NX4 matrix
//
// Programmer: Paul Bladek
//
// Date: 10/31/2001
//
// Version: 1.0
//
// Environment: Hardware:IBM Pentium 4
// Software: Microsoft XP with .NET framework for execution;
// Compiles under Microsoft Visual C++.Net 2005
//
// Called By: main()
//
// Parameters: int ar[][4] -- matrix to print
// int n -- number of elements
// ------------------------------------------------------------------------------
void PrnNx4 (int ar[][4], int n)
{
int i = 0;
int j = 0;
for(i = 0; i < n; i++)
{
for( j = 0; j < 4; j++)
printf("%4d", ar[i][j]);
putchar('\n');
}
}
How many bytes are read in pointers by pointers dereferencing?
When you dereference a pointer you "read" the number of bytes determined by the pointer's type. That is, a char pointer dereferences a single byte while an int pointer dereferences 4 bytes (assuming a 32-bit int) -- regardless of the type actually stored at that address. However, note that a pointer can only actually point at a single byte since it only has storage for a single memory address. How many additional bytes are dereferenced is entirely dependant on the type of the pointer.
To determine how many bytes are actually allocated to an address, use the sizeof operator, passing a dereferenced pointer (the pointer must point at the start of the allocation). If the pointer points at several elements of the same type (an array), then divide the total bytes by the size of the pointer's type to determine the number of elements in the array.
Functions except gets and puts in c?
printf , scanf , getchar, putchar, getc are the other operators in C except gets and puts..