Download as pdf or txt
Download as pdf or txt
You are on page 1of 14

int

printf_s scanf_s

printf_s scanf_s
scanf scanf
scanf_s

scanf
scanf_s

{ }

product *=
product = *
count
"Count is greater than 10"
quotient divisor
quotient
123.4567
3.14159
x int 1
sum int 0
x sum sum
"The sum is: " sum

while
x

x scanf %d
y scanf %d
i 1
power 1
power x power
i 1
i y while
power printf

x y while

while (c <= 5) {
product *= c;
++c;
scanf("%.4f", &value);
if (gender == 1) {
puts("Woman");
}
else; {
puts("Man");

while z

while (z >= 0) {
sum += z;
}

if else while
x = x + 1;
x += 1;
++x;
x++;

product *= 2;
product = product * 2;
if (count > 10) {
puts("Count is greater than 10.");
}
quotient %= divisor;
quotient = quotient % divisor;
printf("%.2f", 123.4567);
123.46
printf("%.3f\n", 3.14159);
3.142

int x = 1;
int sum = 0;
sum += x; sum = sum + x;
printf("The sum is: %d\n", sum);

// Calculate the sum of the integers from 1 to 10


#include <stdio.h>

int main(void) {
int x = 1; // set x
int sum = 0; // set sum

while (x <= 10) { // loop while x is less than or equal to 10


sum += x; // add x to sum
++x; // increment x
} // end while

printf("The sum is: %d\n", sum); // display sum


} // end main function

scanf("%d", &x);
scanf("%d", &y);
i = 1;
power = 1;
power *= x;
++i;
while (i <= y)
printf("%d", power);

// raise x to the y power


#include <stdio.h>

int main(void) {
printf("%s", "Enter first integer: ");
int x = 0;
scanf("%d", &x); // read value for x from user
printf("%s", "Enter second integer: ");
int y = 0;
scanf("%d", &y); // read value for y from user

int i = 1;
int power = 1; // set power

while (i <= y) { // loop while i is less than or equal to y


power *= x; // multiply power by x
++i; // increment i
} // end while

printf("%d\n", power); // display power


} // end main function

while
++c;
scanf
.4
else if else
puts
else
z while
z
0

if (age >= 65); {


puts("Age is greater than or equal to 65");
}
else {
puts("Age is less than 65");
}
int x = 1;
int total;

while (x <= 10) {


total += x;
++x;
}
While (x <= 100)
total += x;
++x;
while (y > 0) {
printf("%d\n", y);
++y;
}

#include <stdio.h>

int main(void) {
int x = 1;
int total = 0;

while (x <= 10) {


int y = x * x;
printf("%d\n", y);
total += y;
++x;
} // end while

printf("Total is %d\n", total);


} // end main
"Enter two numbers"
x y z p
if else
m v
s r t

-1

+ - * / %

scanf

Enter the gallons used (-1 to end):


Enter the miles driven:
The miles/gallon for this tank was 22.421875
Enter the gallons used (-1 to end):
Enter the miles driven:
The miles/gallon for this tank was 19.417475

Enter the gallons used (-1 to end):


Enter the miles driven:
The miles/gallon for this tank was 24.000000
Enter the gallons used (-1 to end):
The overall average miles/gallon was 21.601423

scanf

Enter account number (-1 to end):


Enter beginning balance:
Enter total charges:
Enter total credits:
Enter credit limit:
Account: 100
Credit limit: 5500.00
Balance: 5894.78
Credit Limit Exceeded.

Enter account number (-1 to end):


Enter beginning balance:
Enter total charges:
Enter total credits:
Enter credit limit:
Enter account number (-1 to end):
Enter beginning balance:
Enter total charges:
Enter total credits:
Enter credit limit:

Enter account number (-1 to end):

scanf
Enter sales in dollars (-1 to end):
Salary is: $650.00
Enter sales in dollars (-1 to end):
Salary is: $311.11
Enter sales in dollars (-1 to end):

interest = principal * rate * days / 365;


rate
scanf principal rate
days

Enter loan principal (-1 to end):


Enter interest rate:
Enter term of the loan in days:
The interest charge is $100.00

Enter loan principal (-1 to end):


Enter interest rate:
Enter term of the loan in days:
The interest charge is $51.40

Enter loan principal (-1 to end):

scanf

Enter # of hours worked (-1 to end):


Enter hourly rate of the worker ($00.00):
Salary is $390.00
Enter # of hours worked (-1 to end):
Enter hourly rate of the worker ($00.00):
Salary is $400.00

Enter # of hours worked (-1 to end):


Enter hourly rate of the worker ($00.00):
Salary is $415.00

Enter # of hours worked (-1 to end):


--

scanf

counter

number
largest

\t printf

N 10*N 100*N 1000*N


1 10 100 1000
2 20 200 2000
3 30 300 3000
4 40 400 4000
5 50 500 5000
6 60 600 6000
7 70 700 7000
8 80 800 8000
9 90 900 9000
10 100 1000 10000

A A+2 A+4 A+6

3 5 7 9
6 8 10 12
9 11 13 15
12 14 16 18
15 17 19 21
#include <stdio.h>

int main(void) {
int count = 1; // initialize count

while (count <= 10) { // loop 10 times


// output line of text
puts((count % 2) ? "****" : "++++++++");
++count; // increment count
} // end while
} // end function main

#include <stdio.h>

int main(void) {
int row = 10; // initialize row

while (row >= 1) { // loop until row < 1


int column = 1; // set column to 1 as iteration begins

while (column <= 10) { // loop 10 times


printf("%s", (row % 2) ? "<": ">"); // output
++column; // increment column
} // end inner while

--row; // decrement row


puts(""); // begin new output line
} // end outer while
} // end function main

x 9 y 11 x 11 y 9
else if
{}
if else

if (x < 10)
if (y > 10)
puts("*****");
else
puts("#####");
puts("$$$$$");
if (x < 10) {
if (y > 10)
puts("*****");
}
else {
puts("#####");
puts("$$$$$");
}

if (y == 8)
if (x == 5)
puts("@@@@@");
else
puts("#####");
puts("$$$$$");
puts("&&&&&");

x=5 y=8

@@@@@
$$$$$
&&&&&

x=5 y=8

@@@@@

x=5 y=8

@@@@@
&&&&&

x=5 y=7

#####
$$$$$
&&&&&

****
****
****
****
*****
* *
* *
* *
*****

while

* * * * * * * *
* * * * * * * *
* * * * * * * *
* * * * * * * *
* * * * * * * *
* * * * * * * *
* * * * * * * *
* * * * * * * *
printf("%s", "* ");
printf("%s", " ");
puts(""); // outputs a newline

double

printf("%d", ++(x + y));

! ! !

! ! !

You might also like