#include <stdio.h>
#include <stdlib.h>
#define TOTAL_ROWS 15
int main() {
int row, col, numstars=1;
int half, rate = 1;
// Loop through each row.
for (row=1; row<=TOTAL_ROWS; row++) {
half= TOTAL_ROWS/2;
// Draw the blanks before the stars
for (col=0; col< half + 1 -numstars; col++)
printf(" ");
// Draw the stars
for (col=1; col<= 2*numstars - 1; col++)
printf("*");
// If we hit the middle of the diamond, negate the rate.
if ((numstars == (half + 1)))
rate = -rate;
// Change numstars by the rate
numstars = numstars + rate;
// Go to the new line.
printf("\n");
}
system("pause");
return 0;
}
This code creates a diamond. Change the code around to replace the middle row with dots(".") instead of stars("*").#include <stdio.h>
#include <stdlib.h>
#define TOTAL_ROWS 15
int main() {
int row, col, numstars=1;
int half, rate = 1;
// Loop through each row.
for (row=1; row<=TOTAL_ROWS; row++) {
half= TOTAL_ROWS/2;
// Draw the blanks before the stars
for (col=0; col< half + 1 -numstars; col++)
printf(" ");
// Draw the stars
printf("*");
for (col=2; col<= 2*numstars; col++)
printf(".");
printf("*");
// If we hit the middle of the diamond, negate the rate.
if ((numstars == (half + 1)))
rate = -rate;
// Change numstars by the rate
numstars = numstars + rate;
// Go to the new line.
printf("
");
}
system("pause");
return 0;
}


#include <stdio.h> #include <stdlib.h> #define TOTAL_ROWS 15 int main() { int row, col, numstars=1; int half,...
computers. 1. How many times will this loop repeat? include <stdlib.h> #include <stdio.h> void main(void) int 10 for(= 0; i < 101) printf("d", 1); A. 10 times B. 1 time C. It will run forever D. 0 times 2. What will be the output of this program? #include <stdlib.h> #include <stdio.h> int main() int a = 100, b = 200, C = 300; if(!a >= 500) b = 300; C = 400; printf("%d, 8d, &d", a, b, c); return 0;...
What is the output? #include <sys/types.h> #include <sys/wait.h> #include <stdio.h> #include <stdlib.h> #include <unistd.h> int main() { int x = 5; int y = 2; int z = 30; x = fork(); y = fork(); if (x != 0) printf("Type 1\n"); if (y != 0) printf("Type 2\n"); z = fork(); if (x > 0 || y > 0 || z > 0) printf("Type 3\n"); if (x == 0 && y == 0 && z != 0) printf("Type 4\n"); if (x...
Can someone please complete the "allTheQueensAreSafe" function? #include <stdio.h> #include <stdlib.h> void printBoard(int *whichRow, int n) { int row, col; for (row = 0; row < n; row++) { for (col = 0; col < n; col++) { printf("%c", (whichRow[col] == row) ? 'Q' : '.'); } printf("\n"); } printf("\n"); } int allTheQueensAreSafe(int *whichRow, int n, int currentCol) { // TODO: Write a function that returns 1 if all the queens represented by // this array are safe (i.e., none...
sort.c
#include <stdlib.h>
#include <stdio.h>
#include "libsort.h"
int main()
{
int* array;
int size, c;
float median;
printf("Enter the array size:\n");
scanf("%d", &size);
array = (int*) malloc(size *
sizeof(int));
printf("Enter %d integers:\n", size);
for (c = 0; c < size; c++)
scanf("%d",
&array[c]);
sort(array, size);
printf("Array sorted in ascending
order:\n");
for (c = 0; c < size; c++)
printf("%d ",
array[c]);
printf("\n");
median = find_median(array,...
#include <stdio.h> #include <string.h> #include <ctype.h> #include <stdlib.h> int main(void) { /* Type your code here. */ int GetNumOfNonWSCharacters(const char usrStr[]) { int length; int i; int count = 0; char c; length=strlen(usrStr); for (i = 0; i < length; i++) { c=usrStr[i]; if ( c!=' ' ) { count++; } } return count; } int GetNumOfWords(const char usrStr[]) { int counted = 0; // result // state: const char* it = usrStr; int inword = 0; do switch(*it)...
Debug to print output "2 3 5 6 8 11": #include <stdio.h> #include <stdlib.h> int main() { int i, j, n; int A[] = {2, 3, 5, 5, 5, 6, 8, 11, 11, 11}; n = sizeof(A) / sizeof(int); for (i = 0; i < n - 1; i++){ if (A[i] != A[i + 1]) { for (j = 1; j < n - 1; j++) { A[j]...
#include <stdio.h> #include <stdlib.h> #include <string.h> #include<ctype.h> #define MAX_LEN 255 int numWords(char *str); int numDigit(char *str); int numUppltr(char *str); int numLwrltr(char *str); int punChar(char *str); char*readString(char *str); int main() { char givString[MAX_LEN]; puts("Enter your string(Max 255 characters):"); //readString(givString); gets(givString); printf("\nnumber of words :%d",numWords(givString)); printf("\nnumber of uppercase letters %d",numUppltr(givString)); printf("\nnumber of lowercase letters %d",numLwrltr(givString)); printf("\nnumber of punctuations %d\n",punChar(givString)); printf("\nnumber of digits:%d\n",numDigit(givString)); system("pause"); return 0; } char *readString(char *str) { int ch, i=0; while((ch=getchar())!=EOF && ch!='\n') { if(i) { str[i]=ch; i++; }...
#include <stdio.h> #include <stdlib.h> int aaa(); int main() { int ddd,eee = aaa (ddd,eee); printf("new num 1 = %d, new num2 = %d.\n", ddd,eee); return 0; } int aaa(int bbb,int ccc) { bbb = 111; ccc = 222; printf("num 1 = %d, num 2 = %d.\n", bbb,ccc); return bbb ,ccc; } Output: num 1 = 111, num 2 = 222. new num 1 = 0, new num2 = 222. ************************************************************** I am learning function in C....
#include <stdio.h> #include <stdlib.h> #include <math.h> int count,i, tracker = 0; int main() { scanf("%d\n", &count); int numbers[count]; //GEtting the numbers and satisfy BS conditions for (i = 0; i < count; i++) { if (scanf("%d", &numbers[i]) != EOF) { tracker++; } if (numbers[i] < 0 || numbers[i] > 99) { printf("%d is not in the [0, 99] range.\n",numbers[i]); exit(i); } } if( tracker != count) { printf("%d numbers are required, but only %d were provided.\n", count, tracker); exit(1); }...
#include <stdio.h> int main(int argc, char *argv[]) { int i; for (i = argc - 1; i > 0; i--) printf("%s ", argv[i]); printf("\n"); return 0; } can you explain this code in c and why use this function