WRITE THIS PROGRAM IN C LANGUAGE. Description This programming assignment will h
ID: 3595170 • Letter: W
Question
WRITE THIS PROGRAM IN C LANGUAGE.
Description This programming assignment will have you write two programs. These two programs are problems 3 and 6 of Chapter 9 with some additions: Write a function that takes three arguments: a character and two integers. The character is to be printed. The first integer specifies the number of times that the character is to be printed on a line, and the second integer specifies the number of lines that are to be printed. Write a program that makes use of this function. Call the program charblock.c Write and test a function that takes the addresses of three double variables as arguments and that moves the value of the smallest variable into the first variable, the middle value to the second variable, and the largest value into the third variable. Write a program that reads in 3 double values, and then prints the values in sorted order using the function you just created. Call the program dsort.c 1. 2.Explanation / Answer
1) First code
#include<stdio.h>
//Function declaration
void repeat_print(char input,int char_repeat,int lines_repeat);
//Main function
void main()
{
//Variable declaration and initialize
char input;
int char_repeat=0,lines_repeat=0;
int i=0,j=0;
//Take input from user
printf(" Enter a character ");
scanf("%c",&input);
printf(" Enter the number of times character has to be repeated ");
scanf("%d",&char_repeat);
printf(" Enter the number of times line has to be repeated ");
scanf("%d",&lines_repeat);
//Call function
repeat_print(input,char_repeat,lines_repeat);
}
//Function to repeat the character
void repeat_print(char input,int char_repeat,int lines_repeat)
{
int i=0,j=0;
//Outer loop for lines and inner loop for character repeatation
for(i=0;i<lines_repeat;i++)
{
printf(" ");
for(j=0;j<char_repeat;j++)
{
printf("%c",input);
}
}
}
2) Second program
#include<stdio.h>
//Function declaration
void sort_double(double a,double b,double c);
//Main function
void main()
{
//Variable declaration and initialize
double a=0,b=0,c=0;
int i=0,j=0;
//Take input from user
printf(" Enter first double number ");
scanf("%f",&a);
printf(" Enter second double number ");
scanf("%f",&b);
printf(" Enter third double number ");
scanf("%f",&c);
//Call function
sort_double(a,b,c);
}
//Function to repeat the character
void sort_double(double a,double b,double c)
{
int big=0,mid=0,small=0;
if(a>b && a>c)
{
if(b>c)
{
big=a;
mid=b;
small=c;
}
else
{
big=a;
mid=c;
small=b;
}
}
else if(b>a && b>c)
{
if(a>c)
{
big=b;
mid=a;
small=c;
}
else
{
big=b;
mid=c;
small=a;
}
}
else
{
if(b>a)
{
big=c;
mid=b;
small=a;
}
else
{
big=c;
mid=a;
small=b;
}
}
printf(" The digits after sorting are %f , %f , %f ",big,mid,small);
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.