C/C++ :: Using Printf Statement To Print Certain Number Of Spaces
Sep 1, 2014
is there a to use printf to print certain number of blank spaces, where the number is derived from the output of a function?
for(m=low; m<=high;m++)
{
printf("t=%2d %'f(m)-1's %3c
", m, ' ',*);
}
this is suppose to output
t=-3 *
t=-2 *
t=-1
.
.
.
This is supposed to output t=m and then m is plugged into a function say for -3, plugging it into function f gives 23, well i want 22 blank spaces and then a asterik and go to next line. that is why i put -1 after %'f(m)-1's i
The asterisk appear right next to the t value here but they are way to the right of it when i made this post.
View 2 Replies
ADVERTISEMENT
Sep 1, 2014
is there a to use printf to print certain number of blank spaces, where the number is derived from the output of a function?
for(m=low; m<=high;m++)
{
printf("t=%2d %'f(m)-1's %3c", m, ' ',*);
}
This is suppose to output
t=-3 *
t=-2 *
t=-1
.
.
.
View 2 Replies
View Related
Apr 13, 2013
i am trying to write a program to print a statement without spaces in it.For example, if the statement is "Hello, i am Solidsnake", then it should print it as "Hello,iamsolidsnake".
View 4 Replies
View Related
Oct 29, 2012
Here is the code:
int unsigned long a,b;
scanf("%lu",&a);
scanf("%lu",&b);
printf("%lu",a*b);
suppose we input a very large number on a and b (no more than 1000 digit)
like a = 1234567890123456789012345678901234567890
and b = 9876543210987654321098765432109876543210
it outputs 1, why is it?
It is probably the answer is too big, is there any way to show a*b?
View 1 Replies
View Related
Jul 1, 2012
I would like the following code to print: "Why doesn't this print?" and "I would like to print the sum of nc: 5". What am I doing wrong.
#include <stdio.h>
//Use to test ideas and formats//
main() {
int c, nc;
nc = 0;
[code]....
My result as compiled by gcc -o testing testing.c
This prints.
test
t1,e2,s3,t4,
5,
I have not figured out how to sum and print as the above code indicates, which complicates my ability to do many of the exercises in "The C Programming Language". I am using a MacBook gcc compiler and X code as well. I cannot get the last two printf functions to work. I did the temperature example with "while (fahr <= upper)" and the printf printed.
View 7 Replies
View Related
May 23, 2013
This code runs. However, when I run it, the text from printf doesn't appear until after I type in the two numbers.
I use Wascana, will it run correctly on other compilers?
Code:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main() {
fflush(stdout);
[Code].....
And this is how it turns out on the screen:
Code:
6
3
What size is the die:
how many dice to roll:
Numbers are 3d6
Rolling die no.1...
RolledDie: 4 DieTotal: 4
Rolling die no.2...
RolledDie: 5 DieTotal: 9
Rolling die no.3...
RolledDie: 5 DieTotal: 14
The total is: 14
View 4 Replies
View Related
Jun 26, 2013
how to print the result on screen without using printf in C...?
View 6 Replies
View Related
Feb 26, 2014
I am having some trouble tokenizing some strings in C. I am trying to take in a string dynamically and spit print it to the console tokenized using the spaces as delimiters. I have tried using frets() and scant() as well as playing around with pointer values to no avail.
#include <stdio.h>
#include <unistd.h>
#include<string.h>
#include <stdlib.h>
#define MAX_LINE 80
//function prototypes
void printArgs(int argc, char* args[]);
[Code] .....
View 7 Replies
View Related
Feb 17, 2015
How does one read the number of characters in a .txt file excluding the spaces? Here is my code so far. I am getting 67, which is the correct number including spaces but can't find out how to exclude them. Here's my code!
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
/////////------------------/////////
//Function Prototypes//
int fileLength();
[Code] .....
View 6 Replies
View Related
Jul 17, 2013
I wanted to take the averages of the whole week and output a print statement. I've tired few ways this like assigning "temp" a pointer, or in each if statement assigning temp to a new variable like a, b , c etc. Then adding them all up at the end and dividing by 7. My issue is I am unclear how to store the number typed for each if statement while the program is running, then have it compute the simple equation. The code in question is below:
Code:
#include <stdio.h>
int main(int argc, const char * argv[]) {
int i, j = 0, temp = 0;
for (i=1; i<=7; i++) {
j++;
[Code] ....
View 1 Replies
View Related
Jan 21, 2012
I have an exercise that asks me to print numbers at random from the following set (using only a single statement):
2, 4, 6, 8, 10
Here's my statement:
Code:
cout << (2 + rand() % 9) << " ";
which prints numbers at random between 2 and 10, now I can use the modulus operator in an if...else statement to print only even numbers but the exercise specifically requires using only one statement, can that be done using the conditional operator? and if not then how?
View 10 Replies
View Related
Oct 17, 2013
Community Hospital needs a program to compute and print a billing statement for each patient. Charges for each day are as follows:
a. room charges: private (P) room = $125.00; semi-private (S) room = $95.00; or ward (W) = $75.00
b. telephone charge = $1.75
c. television charge = $3.50
Write a program to get data from the keyboard, compute the patient’s bill, and print an appropriate statement. Typical input (nut yours do not have to be identical to this) is the following:
How many days was the room occupied? 5
What type of room? P
Telephone used during the stay? N
Television used during the stay? Y
Keep in mind that the user needs to know that the input can be any integer number of days for the length of stay, either (P, S, or W) for the room type, and either (Y or N) for both telephone and television options.
A statement (which yours MUST be identical to) for the data given follows:
Community Hospital Patient Billing Statement
Number of days in hospital: 5
Type of room: Private
Room charge:$ 625.00
Telephone charge:$ 0.00
Television charge:$ 17.50
TOTAL DUE = $642.50
View 3 Replies
View Related
Feb 19, 2014
I am working on a small simple program my program fills up a air plane with customers there is 2 levels 1 and 2 and it will put that person in the spot depending on being picked.
So far i made a boolean airplane with 10 spots I can enter 1 person into the airplane with no problem but then after he sits down i get a infinite loop? I assume i maybe have to use the continue statement I feel like there is something simple that im missing i want to add more people. here is what i have
class Program
{
static void Main(string[] args)
{ bool[] planeSeats = {false, false, false, false, false, false, false, false, false, false };
[Code]......
View 1 Replies
View Related
Apr 21, 2013
Write a for loop statement to print the numbers from 1 to 10 in reverse order separated by star :
10*9*8*7*6*5*4*3*2*1
i try to do it but it show me like this :
10*9*8*7*6*5*4*3*2*1*
how do i write to show me like the first one ?
View 10 Replies
View Related
Feb 12, 2014
I have a problem who must print the sentences who have lenght more than 20 characters. I dont know why, but it prints just the first words. Look what i made.
#include<stdio.h>
#include<conio.h>
int main()
[Code]....
For instance :
Give the number of sentences : 3
First sentence : I like the website bytes.com
Second sentence : I like more the website bytes.com
Third sentence : bytes.com
After I compile the program it should print the first two sentences.
View 2 Replies
View Related
Nov 3, 2013
I need to write a program that will allow the user to enter a number "n" and the program tell you that the nth prime number is .....
EXAMPLE
user enters 55
printf("The 55th prime number is %i", variable");
View 1 Replies
View Related
Nov 24, 2013
How to reserved int number and print as float number ?
View 1 Replies
View Related
Jul 4, 2014
The program I am stuck on is used to generate random numbers, then sort them (found in Chapter 23, p. 212). When I compile it, I get an error stating "break statement not within loop or switch. I'm finding that there is an issue with a break statement, but I don't know enough yet.
Code:
/* Will generate random numbers, then sort them.*/
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
main() {
int ctr, inner, outer, didSwap, temp;
int nums[10];
time_t t;
[Code] ....
View 4 Replies
View Related
Nov 10, 2014
So I tried creating a test code for reading a negative number and positive number but whenever I enter a negative number it read it as being positive.
#include <stdio.h>
#include <iostream>
#include <iomanip>
[Code].....
PS: I am using char over int because the program that I am testing for requires me to use 8 bit variable.
View 2 Replies
View Related
Jan 26, 2014
I am writing for loop with a switch so that scores can be inputted in by a judge. The issue that I am running into is that I will put out an the text then the test happens and the code puts out the switch statement 5 times with random number. Here is what I have written.
Code:
int main() {
int diver;
int option;
int Judge;
cout << "Enter Divers Name:";
[Code] ....
View 4 Replies
View Related
Oct 13, 2014
How can i print out the SECOND MIN number and MAX number without using array?
cout << "Please input a positive integer: ";
cin >> input;
min = input, max = input, secondmin = input;
do {
cout << "Please input a positive integer: ";
cin >> input;
[Code] .....
View 7 Replies
View Related
Apr 10, 2013
#include<stdio.h>
#define TRUE 1
int formOddInt(int n);
[Code]....
View 5 Replies
View Related
Oct 26, 2013
i just started learning programming and i just wanna know how come when i try to print the last digit of a number the output always become 6?
View 4 Replies
View Related
Sep 26, 2013
i want to print Largest number from any 5 rows.Th number printed should be any one of the largest in the five rows of 2d arrays.I have created code for largest number in each row but how to pick and print them randomly?.
Code:
#include<conio.h>
main( )
{
int a,b,c,d,e,x;
int arr[] = {a,b,c,d,e};
int Matrix[5][5] ={ /*Initializing array*/
2,4,3,5,9,
6,8,2,2,10,
[Code]...
View 9 Replies
View Related
Dec 25, 2014
Print the inverse number. Ex: 2178*4=8712
Write down a program which can satisfy the prerequisite and print out the screen.
The answer is:
Code:
void inverse2 ()
{
int i,j;
for (i=1000;i<=9999;i++)
for (j=1;j<=9;j++)
if (i*j==inverse (i))
printf("%5d%2d",i,j);
}
I can't understand the double for loop.
for (i=1000;i<=9999;i++)
for (j=1;j<=9;j++)
And The meaning for
i*j==inverse (i)
View 2 Replies
View Related
Jan 12, 2015
when i compile and run it it gives me the number 0 and not the proper number stored in array.
Code:
#include <stdio.h>
int main()
{
int myArray[11] = { 5, 5, 5, 5, 5, 5, 5, 5, 5, 5 };
}
[code]....
View 4 Replies
View Related