Please use C programming to write a code segment as an answer. Instead of using an while-loop like the following code, please implement a code segment by using a do-while loop. What is the output of the code?
#include <stdio.h>
void main()
{
int i = 0;
while (i < 5);
{
printf(“%d ”, ++i);
}
}
Actually the given code has an infinite loop.
Because the while statement ends with a semi column.
If we remove the semi column at the end of while statement then it will produce "1 2 3 4 5" as its output.
Code with do-while loop:
--------------------------
#include <stdio.h>
void main()
{
int i = 0;
do
{
printf("%d ", ++i);
}while (i < 5);
}
Please use C programming to write a code segment as an answer. Instead of using an...
Hello, I have my piece of C programming code and I have a pointer initialized to point to my array and I need help to display the contents of my array using a while loop or do-while loop. The stop condition should be when the pointer reaches '\0'. The code is below: #include <stdio.h> int main () { char array[80]; printf("Enter a string: "); scanf("%[^\n]", &array); printf("%s\n", array); char * p; p = array; }
I need the programming to be in language C. I am using a program called Zybook Prompt: Write a statement that outputs variable numObjects. End with a newline. Given: #include <stdio.h> int main(void) { int numObjects; scanf("%d", &numObjects); return 0; } What I did so far. I am not sure if its right tho? #include <stdio.h> int main(void) { int numObjects; scanf("%d", &numObjects); printf(" num Objects is "); printf("%d\n", userAge); return 0; }
Please answer the above queston (in terms of C programming) and
explain answer
Semester 2 & Trimester 3B, 2015 COMP1004 Engineering Programming Question 3 - Repetition (20 marks) Q3(a) What will be printed when the following code is executed? (5 marks] #include <stdio.h> int main() int i, j; for(i=1;i<17;i=i+2) { printf("%d==", i); for(j=i; j>0;j--) printf("#"); printf("\n"); return 0; == # 3 = = # # # 5 == ### ## 7 #### #
I am trying to write C programming code and output will be as
below
but I donno how to get the result analysis part.
help me to add the 2nd part with my code:
here is my code below:
#include <stdio.h>
#define MAX 100
struct studentMarkVariable{
int id;
float marks;
};
void getData(struct studentMarkVariable arrs[]);
void show(struct studentMarkVariable arrs[]);
int main()
{
printf ("####### Marks Analyzer V3.0 ####### \n");
struct studentMarkVariable
arrs[MAX];
getData(arrs);
show(arrs);
return 0;
}...
C program. Using do-while loop for this question. Question: write a program to calculate the average of first n numbers. output: Enter the value of n : 18 The sum of first 18 numbers =171 The average of first 18 numbers = 9.00 my code couldn't give me the right avg and sum. Please help. #include<stdio.h> int main() { int num; int count =0; int sum=0; float avg; printf("Enter the value of n: "); ...
Programming C....... function code is clear but compile is wrong .. I input 8 and compiled 2 0 1 1 2 3 5 8 13.. look first number 2 is wrong. The correct answer 8 is 0 1 1 2 3 5 8 13 21.. Need fix code to compile correctly.. Here code.c --------------------------------------------------------------------------------------------------------------------- #include <stdio.h> #include <math.h> int fibonacciIterative( int n ) { int fib[1000]; int i; fib[ 0 ] = 0; fib[ 1 ] = 1; for (...
5. PracticalC Programming a. (4 Points) Why should we use snprintf () instead of sprintf(), strncpy () instead of strcpy (), etc.? Seriously, how bad can using sprintf(), strcpy ), etc. be? b. (4 Points) What does extern mean? What does it tell the compiler to do? c. (8 Points) The program below will compile well but run poorly. Please make it do error checking and fix it to make it proper: #include #include <stdlib.h> <stdio.h> <sys/types.h> <sys/stat.h> #include #include...
How do I make this program run the same using a do while loop instead of the for loop? I'm supposed to replace the for loop with a do-while. Also, how would i replace it with a while loop? #include void main(void) { int n, sum, product, i; printf("n?\n"); scanf("%i", &n); printf("You entered %i\n", n); sum = 0; product = 1; for (i=1; i<=n;i++) { if((i%3!=0) && (i%5!=0)){ sum = sum + i; product = product * i;} ...
Using C programming Using the supplied example code as a starting point, add 3 more conversions using strtod(). Make sure you change the output conversion for type double. Use the same input strings and base codes as the strtol() function example but notice how the numbers are now represented. Manipulate the width and precision as needed for a good presentation. Supplied code: #include <stdio.h> #include <string.h> int main(void) { long num; char* ptr; num = strtol("12345 Decimal Constant: ", &ptr,...
please explain very well.Thanks
Question 3) What is the output of the following code? (4 marks) #include <stdio.h> int main(void) Output: int i; for (i = 0;i<4; i++) static int a = 0; int b = 0; a++; b++; printf("%d %d", a,b); 11213141