int inputNum, i; printf("Enter a number: "); scanf("%d", &inputNum); i = inputNum; if(i <= 5){ printf("%d\n", i * i); i++; }
int inputNum, i; printf("Enter a number: "); scanf("%d", &inputNum); i = inputNum; while(i <= 5){ printf("%d\n", i * i); i++; }
int i; while (i < 100) { printf("%d\n", i); i = i + 1; }
int i = 0; int j = 0; while (j = 1 || i < 100) { printf("%d\n", i); i = i + 1; }
int i = 0; int n = 10; while (i < n) { printf("%d\n", i); n = n + i; i = i + 1; }
int i = 0; while (i < 10) printf("%d\n", i); i = i + 1;
while
loop.
./asterisks Please enter an integer: 5 * * * * *
./readInts Please enter some integers: 10 100 999 78 -3 You entered 4 integers ./readInts Please enter some integers: 1 2 3 4 5 6 7 8 9 10 11 12 -9 You entered 12 integers
multipleOfTen.c
which reads 2 integers and then prints all multiples of ten between those numbers.
Write a C program log10.c
which reads a positive integer, and calculates the integer part
of its base 10 logarithm.
Hint: repeatedly divide by 10.
#include <stdio.h> int main(void) { int number; int row, column; // Obtain input printf("Enter number: "); scanf("%d",&number); row = 1; while (row <= number) { column = 1; while (column <= number) { printf("*"); column = column + 1; } printf("\n"); row = row + 1; } return 0; }What is the output if the user types in the number 5? Modify the program so that it prints out a triangle that consists of
number
asterisks
eg
Enter number: 5 * ** *** **** *****
diagonal.c
that reads an integer and prints the following pattern:
./diagonal Enter an integer: 10 * * * * * * * * * *
cross.c
that reads an integer and prints the following pattern. You may assume your input is a positive integer >= 5
./cross Enter size: 5 *---* -*-*- --*-- -*-*- *---*
./rectangle Enter rectangle height and length: 3 5 ***** * * *****
./diamond Enter side length: 3 * * * * * * * * ./diamond Enter side length: 6 * * * * * * * * * * * * * * * * * * * *
./multiplicationTable Enter multiplication table size: 5 1| 1 2 3 4 5 2| 2 4 6 8 10 3| 3 6 9 12 15 4| 4 8 12 16 20 5| 5 10 15 20 25
void getSquare(void); int main(void){ int n; printf("Enter a number "); scanf("%d",&n); getSquare(); printf("The square of %d is %d\n", n, sqr); return EXIT_SUCCESS; } int getSquare(void) { int i; int count = 1; i = 0; while ( i < n ) { count *= n i = i + 1; } printf("\n"); }
It had the following compile time error:
getSquare.c:17:17: error: use of undeclared identifier 'n' while ( i < n ) {
What is wrong with the code? How can we fix it?