C programming
3. Write a do-while loop that displays: 0,10,20,30,40
4.Write nested for loops that displays three rows of asterisks:
*****
*****
*****
5. Write a complete program that reads a set of integers using scant() until a sentinel value of -99 is read. Once that value is read, display the sum of the value read, exclusive of the -99.
6.Write a procedure(function, method named times10() that accepts an integer argument and displays the result of multiplying the argument by 10.
7.Write a function prototype for a min3() function that accepts three integer parameters and returns an integer value.
8.Write the function implementation for the min3() function. Return the minimum value of the three.
3.
#include <stdio.h>
int main(void) {
int x = 0;
do
{
printf("%d",x);
if(x < 40)
printf(",");
x = x+ 10;
}while(x<= 40);
return 0;
}
Output:
0,10,20,30,40
4.
#include <stdio.h>
int main(void) {
int i,j;
for(i=1;i<=3;i++)
{
for(j=1;j<=5;j++)
{
printf("*");
}
printf("\n");
}
return 0;
}
Output:
***** ***** *****
5.
#include <stdio.h>
int main(void) {
int x, sum;
sum = 0;
do
{
scanf("%d",&x);
if(x == -99)
break;
sum = sum + x;
}while(x != -99);
printf("\nSum = %d",sum);
return 0;
}
Output:
8 -5 7 6 -99
Sum = 16
6.
#include <stdio.h>
int times10(int x)
{
return 10*x;
}
int main(void) {
printf("%d",times10(4));
return 0;
}
Output
40
7.
int min3(int x,int y,int z);
8.
#include <stdio.h>
int min3(int x,int y,int z)
{
if(x < y)
{
if(x < z)
return x;
else
return z;
}
else
{
if(y < z)
return y;
else
return z;
}
}
int main(void) {
printf("%d",min3(54,66,12));
return 0;
}
Output:
12
Do ask if any doubt. Please upvote.
Get Answers For Free
Most questions answered within 1 hours.