Question

In: Computer Science

Please code the program showing the output below. using C language 1. Using 'if' or 'while'...

Please code the program showing the output below. using C language

1. Using 'if' or 'while' or 'for' and 'break' statement / only using <stdio.h>

A

bC

dEf

GhIj

KlMnO

2. a program that identifies the largest number that can be expressed in short.

Using only loop (ex.for,if,while) and break statement

only using <stdio.h>

Solutions

Expert Solution

Part 1)

For this we take a character ch and initialize it to 'A'. Then using a for loop, we traverse 5 times for 5 lines of output.

Inside this loop, there is another for loop to print the characters, if conditions are used to determine the casing of the alphabets.

CODE:

#include <stdio.h>

int main()
{
int i,j,k=0,n;
char ch='A';

for(i=1;i<=5;i++)
{
for(j=1;j<=i;j++,k++,ch++)
{
if(k%2==0)
{
printf("%c",ch);
}
else
{
printf("%c",ch+32);
}
}
printf("\n");
}
}

OUTPUT:

2) For printing highest value of short(unsigned), we take the exponential approach. Since size of short is 2 bytes then their are 16 bits. So, 0 to 216-1 will be the range of this data type.

To calculate the exponential value, we use for loop, in which we multiply base value(2) with the product, "expo" number of times.

CODE:

int main()
{
int i, exponent = 16, base =2;
unsigned short power =1;
for(i=1; i<=exponent; i++)
{
power = power * base;
}
  
printf("%hu", power-1);
}

OUTPUT:


Related Solutions

C++ program. Please explain how the code resulted in the output. The code and output is...
C++ program. Please explain how the code resulted in the output. The code and output is listed below. Code: #include <iostream> #include <string> using namespace std; int f(int& a, int b) {    int tmp = a;    a = b;    if (tmp == 0) { cout << tmp << ' ' << a << ' ' << b << endl; }    b = tmp;    return b;    return a; } int main() {    int a...
1 for each of the problems listed below write the c++ program while using WHILE loop...
1 for each of the problems listed below write the c++ program while using WHILE loop structures A program will display each term in the following sequence 1 -10 100 -1000 10000 -100000 1000000 A program will calculate and display the corresponding celsius temperatures for the given Farenheit ones from 0f to 212 f (hint c=(f-32/1.8)
Using the python program language. Expand/EDIT the code below for all vowels (AEIOU). Please provide a...
Using the python program language. Expand/EDIT the code below for all vowels (AEIOU). Please provide a code and a screen shot of the code working with an output. the code should be able to take any name as an  input. The code should be able to pull out the vowels along with the count fo each vowel within that name for the output. #countVowels.py import sys s1 = str(sys.argv[1]) (a,e,i,o,u) = (0,0,0,0,0) print ("String length = ", len(s1)) for n in...
Please code in C language. Server program: The server program provides a search to check for...
Please code in C language. Server program: The server program provides a search to check for a specific value in an integer array. The client writes a struct containing 3 elements: an integer value to search for, the size of an integer array which is 10 or less, and an integer array to the server through a FIFO. The server reads the struct from the FIFO and checks the array for the search value. If the search value appears in...
Please use C language to code all of the problems below. Please submit a .c file...
Please use C language to code all of the problems below. Please submit a .c file for each of the solutions, that includes the required functions, tests you wrote to check your code and a main function to run the code. Q2. Implement the quick-sort algorithm.
1. Consider the program below. a. What would the output be in a language with static...
1. Consider the program below. a. What would the output be in a language with static scoping rules? Explain your answer. b. What would the output be in a language with dynamic scoping rules? Explain your answer. int x; //global int main() {    x = 11;    fun1();    fun2(); } void fun1() {    int x = 19;    fun3(); } void fun2() {    int x = 4;    fun3(); } void fun3() {    print(x); }
Write Lexical Analyzer program in C language. Below is the sample input and ouput. /* output...
Write Lexical Analyzer program in C language. Below is the sample input and ouput. /* output Enter the string: if(a<b){a=10;} Tokens are identifier :if punctuation mark : ( identifier :a operator:< identifier :b punctuation mark : ) punctuation mark : { identifier :a operator:= constant :10 punctuation mark : ; punctuation mark : } */
provide a C code (only C please) that gives the output below: ************************************ *         Menu HW...
provide a C code (only C please) that gives the output below: ************************************ *         Menu HW #4 * * POLYNOMIAL OPERATIONS * * 1. Creating polynomials * * 2. Adding polynomials * * 3. Multiplying polynomials. * * 4. Displaying polynomials * * 5. Clearing polynomials. * * 6. Quit. * *********************************** Select the option (1 through 6): 7 You should not be in this class! ************************************* *         Menu HW #4 * * POLYNOMIAL OPERATIONS * * 1. Creating polynomials...
Complete the following exercises using C programming language. Take screenshots of the code and its output...
Complete the following exercises using C programming language. Take screenshots of the code and its output where specified and paste them into in a well-labeled Word document for submission. Scenario Assume you are the CIO of an organization with three different IT department locations with separate costs. You want a program to perform simple IT expenditure calculations. Your IT expenditure target is $35,000 per site. Site expenditures: Site 1 – $35,000. Site 2 – $37,500. Site 3 – $42,500. Exercise...
Using C++, write a code that this program always stores text file output into a text...
Using C++, write a code that this program always stores text file output into a text file named "clean.txt". -The program should read one character at a time from "someNumbers.txt", and do the following. -If it is a letter, print that letter to the screen, AND also store it in the text file. All letters should be converted to lowercase beforehand. -If it is a number, print that number to screen, but do NOT store it in the text file....
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT