How do you write an output without using printf function in c?
Yes. However, C is a type-sensitive language thus PRINTF and printf would need to be defined as separate functions. However, names using all caps are conventionally used to denote macros in C thus you can easily define PRINTF as an alias for printf:
#define PRINTF printf;
int main (void) {
PRINTF ("%d", 42);
}
The C precompiler will substitute all instances of the symbol PRINTF with printf, thus the code seen by the compiler will become:
int main (void) { printf ("%d", 42);
}
Write a program in C language to find out the dot product of two vector quantities in Cartesian?
#include <stdio.h>
#include <ctype.h>
#define n[]
int main()
{
int n, result , answer;
int a[n], b[n];
printf("Enter number of terms you would like to use :");
scanf("%d", &n);
printf("Enter first vector:\n");
scanf("%d", &a[n]);
printf("Enter second vector:\n");
scanf("%d", &b[n]);
printf("The dot product is \n" );
return 0;
}
crash prob is at an elevated level
#include<iostream>
#include<map>
#include<string>
#include<sstream>
#include<conio.h>
struct Cellphone
{
std::string product_id;
std::string product_no;
std::string country;
std::string brand;
double cost;
};
std::ostream& operator<< (std::ostream& os, const Cellphone& phone)
{
os << "Product ID: " << phone.product_id << std::endl;
os << "Product No: " << phone.product_no << std::endl;
os << "Country: " << phone.country << std::endl;
os << "Brand: " << phone.brand << std::endl;
os << "Cost: " << phone.cost << std::endl;
return os;
}
// Global...
std::map<std::string, Cellphone> cellphones;
// forward declarations
size_t choice (std::string);
std::string get_string (std::string prompt);
double get_double (std::string prompt);
void add();
void remove();
void search();
void view();
int main()
{
while (1)
{
std::cout << "MAIN MENU\n=========\n\n";
std::cout << "[A] Add\n";
std::cout << "[V] View\n";
std::cout << "[S] Search\n";
std::cout << "[R] Remove\n";
std::cout << "[Q] Quit\n";
switch (choice ("AVSRQ"))
{
case 0: add(); break;
case 1: view(); break;
case 2: search(); break;
case 3: remove(); break;
default: return 0;
}
}
}
void add ()
{
std::cout << "\nAdd Cellphone\n\n";
Cellphone phone;
phone.product_id = get_string ("Product ID");
phone.product_no = get_string ("Product #");
phone.country = get_string ("Country");
phone.brand = get_string ("Brand");
phone.cost = get_double ("Cost");
cellphones[phone.product_id] = phone;
std::cout << std::endl;
}
void remove ()
{
std::cout << "\nRemove Cellphone\n\n";
std::string id = get_string ("Product ID");
cellphones.erase (id);
}
void search ()
{
std::cout << "\nSearch for Cellphone\n\n";
std::string id = get_string ("Product ID");
std::map<std::string, Cellphone>::const_iterator it = cellphones.find (id);
if (it choices.npos)
continue;
return pos;
}
}
All data is stored in a computer as 0s and 1s. In order to make this more efficient, certain sets of bits can mean different things depending on what the data type is. Some languages, such as Java, make sure the programmer doesn't confuse these types and mess up the data. However, other languages allow you to do things like multiply a string and an array. If you don't pay careful attention to data types, you can easily end up with useless data.
Example of area of rect inheritance program in java?
Let us first define a generic Shape class. This will be an abstract class, since the term "shape" is, itself, very abstract.
Let us also assume that this shape is defined in only two dimensions, for the sake of simplicity.
abstract class Shape {
/*
One of the properties of any 2D shape is the area it takes up. Since calculating the area depends on the shape, we'll make this method abstract - all subclasses should implement it differently.
*/
abstract int getArea();
}
Now that we have our base class defined, we can create a rectangle subclass.
class Rectangle extends Shape {
/*
While a rectangle has other properties, we are really only interested in the ones required to calculate the area - width and height.
*/
int width;
int height;
/*
What's the area of a rectangular shape?
area = width x height
*/
int getArea() {
return width*height;
}
}
What part of a function definition specifies the data type of the value that the function returns?
The function header. The return value is written before the name of the function. This return type must match the type of the value returned in a return statement.
You are probably referring to a resource leak, however a resource leak specifically relates to programs that allocate memory on the heap (the free store) but fail to keep track of it. If we lose track of a heap allocation, the programmer cannot release that memory back to the system until the program terminates. The following is an example of a resource leak:
void f (unsigned x) {
void* p = malloc (x); // allocate x bytes // ... use memory
}
Each time we call this function we allocate another s bytes on the heap. But the function never releases that memory and because p is local to the function, we have no way of knowing where that memory was allocated (p will fall from scope when we return from the function). If we call this function often enough, we will eventually run out of memory.
To fix the problem, we must release the memory as soon as we are finished with it:
void f (unsigned x) {
void* p = malloc (x); // allocate x bytes // ... use memory
free (p); // release the memory
p = NULL; // zero the pointer
}
It is not necessary to zero a pointer when the pointer will fall from scope anyway, but it is considered good programming practice. What is important is that we release the memory it refers to before it falls from scope. Keeping our scopes as narrow as possible helps us to manage our resources more easily; the larger the scope, the more easily we can inadvertently introduce resource leaks, particularly when our code is maintained by several different programmers.
The problem you describe isn't necessarily a resource leak but it is clearly wasteful to allocate memory that is left unused even if we don't create a resource leak. Good programming practice dictates that we release memory as soon as we no longer require it, however allocating memory on an as-required basis can impact upon performance so it is not unusual for a programmer to allocate more memory than he needs, thus creating a reserve that can be used as and when required. Not using a reserve isn't in itself a problem, however we should endeavour to keep our reserves to a minimum and return all reserved memory to the system in a timely manner -- as soon as we no longer require it.
Algorithm
Step1: Read A, B, C
Step2: If A > B is True, then check whether A > C, if yes then A is greatest otherwise C is greatest
Step3: If A > B is False, then check whether B > C, if yes then B is greatest otherwise C is greatest
Give the Flowchart Answer
How can you print percent d on the screen using printf?
printf("Your text here %d", your_data);
or maybe you want to see '%d' as output? Try one of these:
printf ("%%d");
printf ("%cd", '%');
printf ("%s", "%d");
fputs ("%d", stdout);
<float_literals> -> <digit> { <digit> } [ . ] [ { <digit> } ]
<digit> -> "0" | <digit excluding zero>
<digit excluding zero> -> "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9"
hi dude
i wish you are satisfied with my answer
LOL ^^
Define unary operator explain different unary operators used in c language?
A unary operator is one that requires only one operand. The unary operators are the prefix and postfix increment and decrement, positive and negative, logical and bitwise negation, and address and indirection operators, plus the words alignof, typeof, and sizeof.
The first two operators are increment "++", and decrement "--". Its position before or after the variable determines prefix or postfix. Incrementing increases the stored value by 1, and decrementing decreases the stored value by 1. If it is to the left of the variable, the operation occurs before the variable is used; if it is to the right, it occurs after the variable is used.
The positive operator "+" simply asserts the current value, and exists as acomplementto the negation operator "-". The negation operator returns the number with the opposing sign. If x is 5, then -x is -5, and if x is -5, then -x is 5.
The logical negation "!" and bitwise negation "~" operators perform actions on individual bits. C considers zero to be false, and all other values to be true. Using logical negation, it returns true if the value is zero, or false for any other value. The bitwise negation changes all 1 bits to 0 bits, and 0 bits to 1 bits. For an unsigned byte, ~0 becomes 255, and ~255 becomes 0. For signed variables, ~0 would become -1, and ~-1 would become 0. This is because of the two's complement method of signed numbers.
Address "&" and indirection "*" operators take the address or value of the operand. The address operator allows a variable to be passed by reference; modifying the reference will modify the original value. Using the indirection operator treats a variable as a memory address, which allows the programmer to access a specific spot in memory.
Alignof, sizeof, and typeof are all used to determine the alignment, size, and type of objects dynamically. This is necessary when trying to determine how data is laid out when there may be differences in memory accesses across platforms (e.g. when reading a ZIP file's directory contents).
2
To display string in a title case in c?
#include<stdio.h>
#include<conio.h>
#include<string.h>
int main()
{
int tmp,i;
char str[30];
printf("Enter any string: ");
gets(str);
for(i=0; str[i]!='\0'; i++) {
if(str[i-1]==' ' i==0)
{
if(str[i]>='a' && str[i]<='z')
str[i]=str[i]-32;
else
if(str[i]>='A' && str[i]<='Z')
str[i]=str[i]+32;
}
printf("%c",str[i]);
}
getch();
return 0;}
Is c language a secure programming language?
Today's C (C11) is more robust and offers new features, and is less likely to "trust the programmer" than older drafts, but it still allows inherently insecure actions. Other languages that are derivatives of C (such as C# or C++) are more secure. For example, C# is staticallyanalyzable-- the Common Language Runtime that underpins this and other .Net languages can assert that the program will not crash, handle memory references incorrectly, or otherwise perform in a way that could cause system instability. Even then, however, a programmer may mark code as "unsafe", which disables static analysis and requires the user to accept the risks of running the application.
C source code for poisson distribution?
/*************************************************************************/
/* POISSON3.C */
/* Calculate poisson statistics given average number of occurences */
/* and the value of interest. */
/* Uses the formula P(X=x) = mu^x * e^-mu/x!, for x = 1,2,3...x */
/* NOTICE: Factorial1() is copyrighted by author */
/* FURTHERMORE: Software is provided as is, with no promise of fitness */
/* for use. */
/* comments or questions: p_duke52@yahoo.com */
/* Have fun... */
/* PAD, May 25, 2008 */
/*************************************************************************/ #include <stdio.h>
#include <math.h> /* protype of "e", exp(x) == exp^x */
#include <conio.h> /* For clrscr() */ /*********************************************************\
// copyrighted by author
// Written by: Jaco van Staden
// Date: 13 July 2002
// Program: Maths Program
// from the file "A_maths_me1067647162002.zip"
// available at Planet Source Code:
// http://www.planet-source-code.com
// changed int to double for size issues
// -- PAD, 5/25/08
\**********************************************************/ double Factorial1 (double a)
{
double answer = 1.0;
while(a>1)
answer *= a--;
return answer;
} int main(void)
{
double result, res1, res2;
double i = 0.0, k = 0.00;
double answer = 0.0; result = res1 = res2 = 0.0; clrscr(); /* makes it easier to see input prompts */ printf("Enter mean: ");
scanf("%lf", &i); printf("Enter value of interest: ");
scanf("%lf", &k); /* factorial of value of interest */ answer = Factorial1(k); /* formula for k */
result = pow(i,k);
res1 = 1/(exp(k));
res2 = (result * res1) / answer; printf("answer is ... : %0.20lf", res2);
return 0;
} /*************************************************************************/
/* POISSON3.C */
/* Calculate poisson statistics given average number of occurences */
/* and the value of interest. */
/* Uses the formula P(X=x) = mu^x * e^-mu/x!, for x = 1,2,3...x */
/* NOTICE: Factorial1() is copyrighted by author */
/* FURTHERMORE: Software is provided as is, with no promise of fitness */
/* for use. */
/* comments or questions: p_duke52@yahoo.com */
/* Have fun... */
/* PAD, May 25, 2008 */
/*************************************************************************/ #include <stdio.h>
#include <math.h> /* protype of "e", exp(x) == exp^x */
#include <conio.h> /* For clrscr() */ /*********************************************************\
// copyrighted by author
// Written by: Jaco van Staden
// Date: 13 July 2002
// Program: Maths Program
// from the file "A_maths_me1067647162002.zip"
// available at Planet Source Code:
// http://www.planet-source-code.com
// changed int to double for size issues
// -- PAD, 5/25/08
\**********************************************************/ double Factorial1 (double a)
{
double answer = 1.0;
while(a>1)
answer *= a--;
return answer;
} int main(void)
{
double result, res1, res2;
double i = 0.0, k = 0.00;
double answer = 0.0; result = res1 = res2 = 0.0; clrscr(); /* makes it easier to see input prompts */ printf("Enter mean: ");
scanf("%lf", &i); printf("Enter value of interest: ");
scanf("%lf", &k); /* factorial of value of interest */ answer = Factorial1(k); /* formula for k */
result = pow(i,k);
res1 = 1/(exp(k));
res2 = (result * res1) / answer; printf("answer is ... : %0.20lf", res2);
return 0;
}
Why program consists more than one object file in c?
why does a program consists of more than one object file in c++
Grady Booch, Ivar Jacobson and James Rumbaugh.
Verify truth table of NAND gate using C programming?
I don't really know what this is supposed to mean, if you want to print the truth-table of the NAND-gate that will be something like this:
for (a=0; a<=1; ++a)
for (b=0; b<=1; ++b)
printf ("%d %d %d\n", a, b, !(a&&b))
Given an integer k write a procedure which deletes the kth element from a linked list?
this question is from the subject data structure and i need answer of this. data structure is the subject ot 3rd semester of bachelor's degree
Sum of 4digit of a number in c?
#include
#include
using std::cin;
using std::cout;
using std::endl;
using std::string
int main()
{
const int numberOfdigits = 5;
string myNumber = "0";
char myNumberChar[numberOfdigits] = {0};
cout << endl << "Enter 4 digit integer: ";
cin >> myNumber;
int sumOfDigits = 0;
int temp = 0;
for (int arrayIndex = 0; arrayIndex < (numberOfdigits - 1); arrayIndex++)
{
temp = atoi(&myNumber.substr(arrayIndex, 1)[0]);
sumOfDigits += temp;
}
cout << endl << "Sum of 4 digits is: " << sumOfDigits << endl;
system("PAUSE");
return 0;
}