Skip to main content

All Questions

Tagged with
0 votes
2 answers
77 views

Why doesnt it print the array in the second loop like it does in the first one?

The programme below prints the array hello correctly in the first loop. But in the second one all it prints is o. Of course the integer k is pointless but I used it because I thought that the reason ...
JOHN BOURAS's user avatar
1 vote
1 answer
131 views

Uninitialized value error when accessing array bytes via pointer arithmetic in C

I'm working on a C program where I need to display the byte values of an integer array. Here's the code I'm using: #include <stdio.h> int main(void) { int arr[] = {67305985, 134678021, ...
Mateusz Mróz's user avatar
-3 votes
1 answer
148 views

How do I print the results of the code below into 2 separate lines of sequences?

I'm currently on some basic exercises on HackerRank (It's my 3rd day with Java). I just finished writing the code: import java.io.*; import java.util.*; import java.lang.Math; public class Solution { ...
Anh Tu Pham's user avatar
2 votes
4 answers
355 views

Print numbers of a matrix in a wave pattern

I want the output to be 7 4 1 2 5 8 9 6 3 but it's coming out to be 1 4 7 2 5 8 3 6 9. How can I fix it, and what's the logic behind it so that I can print the reverse wave pattern, too? #include<...
Samarth Talreja's user avatar
1 vote
1 answer
87 views

Trouble with getting a function to calculate and loop correctly in C

I am needing to make a program to take user input of iterations to the formula : PI=4(1/1 -(1/3)+(1/5) ... repeating a number of times. MY problems so far is that it is not taking my input accurately. ...
Spongebuild's user avatar
0 votes
1 answer
54 views

How many times will each number be printed if the execvp() fails? I get C 3 times when running but my logic says C 2 times

the code: int main(int argc, char *argv[]) { int i; for (i = 1; i < 3; i++) { if (fork() == 0) { printf("A"); execvp("./prog2", &argv[...
Mike Balts's user avatar
0 votes
4 answers
118 views

C Dynamic Array Size

Hello I am new to coding and was just wondering why the below code: #include <stdio.h> int main() { for(int i = 0; 1 ; i++) { char x; char z[1+i]; x=getchar(); if (x == '\n'){ ...
soda2718's user avatar
-3 votes
1 answer
234 views

ternary operator inside printf()

Suppose there is an array of n integers named a. we want to print the elements of this array with the following for loop. for (int i = 0; i < n; i++) { printf("%d%c", a[i], &...
imtiaz's user avatar
  • 17
0 votes
1 answer
53 views

How to make the strings have the same content?

I have two strings and I am using sprintf in both cases to pass from one format to another from an array or string but in one of the cases it does it well and in the other it does not. char ...
Geko66's user avatar
  • 1
-1 votes
4 answers
195 views

Printf inside a For Loop

What will this C code print? for(printf(“1”);!printf(“0”);printf(“2”)) printf(“Sanchin”); return 0; I was expecting this code to result in an infinite loop but instead nothing was printed. Should the ...
Rai's user avatar
  • 1
1 vote
3 answers
103 views

why does this not print the string?

#include<stdio.h> #include<stdlib.h> int main(){ const char *adj[] = {"swag","nice","asparagus","ugly"}; for (int i=0;i<sizeof(adj); i++)...
casimaister's user avatar
0 votes
2 answers
118 views

How to print a pyramidal pattern

#include<stdio.h> int main() { int n,i,j,k,m; printf("Enter the number of lines "); scanf("%d",&n); for(i=1;i<=n;i++) { for(j=1;j<=n-i;...
Vedant Laad's user avatar
0 votes
2 answers
281 views

C program for a reverse triangle pattern

I want to draw a pattern like this: 567898765 4567654 34543 232 1 But I can't seem to figure it out, because this is the output I'm currently getting: 567898765 45678987654 3456789876543 ...
Mohammad Ali's user avatar
1 vote
1 answer
48 views

Why the code is not giving the expected output here?

This code is for declaring and printing a string using pointer concept char *strPtr = "HelloWorld"; // temporary pointer to iterate over the string char *temp = strPtr; while (*temp != '\0')...
user avatar
0 votes
2 answers
200 views

Generate 4 digit sequential numbers keeping leading 0's starting form a given number

I am trying to generate 4 digit sequential numbers starting from any given number. Where I am stuck is keeping the leading 0's as I'll need 4 digits all the time. Here is my code. $start = '0520'; for(...
Abhik's user avatar
  • 674

15 30 50 per page
1
2 3 4 5
12