Found 1401 Articles for C

Write a program to print ‘Tutorials Point’ without using a semicolon in C

sudhir sharma
Updated on 15-Jul-2020 06:40:59

153 Views

In this problem, we have to write a program that will print ‘Tutorials Point ’ without using a semicolon.We all know that to end a statement in c semicolon is necessary. And print statement will be executed when a semicolon is added at the end.So, for printing ‘Tutorials point’ without a semicolon, we will have to first learn about the printf method in c. in actually returns an integer which is the count of total number of characters that are required to be printed.Syntaxint printf(constant char *format, ...)The method can accept n number of arguments. The first will be the ... Read More

Write a C program to print ‘ABCD’ repeatedly without using loop, recursion and any control structure

sudhir sharma
Updated on 15-Jul-2020 06:31:02

146 Views

In this problem, we have to write a program in c that will print a string ‘ABCD’ repeatedly without using loop, recursion and any control structure.So, we will have to call or run the same block of code infinite time but without using loop, recursion or control structure which are the most common methods to perform the task. For this, we will run the same program multiple times instead of looping. This will perform our task within the given constraints. The system() method can be employed inside the code that will call the program infinite times.We will pass the file ... Read More

Difference between scanf() and gets() in C

Nitin Sharma
Updated on 09-Jun-2020 08:53:21

9K+ Views

In C language both scanf() and gets() functions are defined to get input from external source and pass to system as input. Now there is some characteristics difference between both the functions.Following are the important differences between scanf() and gets() in C −Sr. No.Keyscanf() functiongets() function1DefinitionThe scanf() function can read input from keyboard and stores them according to the given format specifier. It reads the input till encountering a whitespace, newline or EOF.On other hand gets() function is used to receive input from the keyboard till it encounters a newline or EOF. The whitespace is considered as a part of ... Read More

Difference between while(1) and while(0) in C language

Nitin Sharma
Updated on 09-Jun-2020 08:11:26

1K+ Views

As we know that in C language 'while' keyword is used to define a loop which works on the condition passed as argument to the loop. Now as condition can have two values either true or false so the code inside while block will be executed repeatedly if condition is true and if condition is false the code will not be executed.Now passing the argument to the while loop we can distinguish between while(1) and while(0) as while(1) is the loop where the condition is always treated as true and so the code inside the block start executing repeatedly. Additionally, ... Read More

Count number of binary strings without consecutive 1's in C

Sunidhi Bansal
Updated on 06-Jun-2020 11:40:23

228 Views

Given the task is to count the number of all the binary strings of length n without any consecutive 1’s.Binary Number System is one the type of Number Representation techniques. It is most popular and used in digital systems. The binary system is used for representing binary quantities which can be represented by any device that has only two operating states or possible conditions. For example, a switch has only two states: open or close.In the Binary System, there are only two symbols or possible digit values, i.e., 0 and 1.Represented by any device that only has 2 operating states ... Read More

Functions in C/C++(3.5)

Sunidhi Bansal
Updated on 24-Apr-2020 11:55:57

174 Views

Functions are like a machine as they perform some functionality and produces a result of some type. Like, machine takes some input, process that input and produce an output similarly, function takes some value, operates on those value and produces the output. Manually a person passes the input to the machine then only the machine will start its functionality in the same manner when the programmer calls the function it will start executing.Functions can be different in name in various languages, but they share two common characteristics like −They contain sequence of instructions that needs to be processedThose instructions are ... Read More

rand() and srand() in C/C++

Sunidhi Bansal
Updated on 22-Apr-2020 12:32:02

10K+ Views

In this article, we will be discussing the working, syntax, and examples of rand() and srand() function in C++ STL.What is rand()?rand() function is an inbuilt function in C++ STL, which is defined in header file. rand() is used to generate a series of random numbers. We use this function when we want to generate a random number in our code.Like we are making a game of ludo in C++ and we have to generate any random number between 1 and 6 so we can use rand() to generate a random number.The random number is generated by using an ... Read More

Write a program that produces different results in C and C++ programming

sudhir sharma
Updated on 20-Apr-2020 11:24:53

80 Views

Write a program that compiler and runs both in c and c++ and produces different results.There are multiple types of programs that give different results when compiled in c and c++.i. Using character literals− c and c++ both treat characters differently. In C, they are treated as integer literals whereas, in C++, they are treated as characters.Example Live Demo#include int main(){    printf("%d", sizeof('a'));    return 0; }OutputC : 4 C++: 1ii. Use of binary number − binary values are not considered as binary in c, instead treat it as integer. But in c++, they are treated as binary.Example Live Demo#include int ... Read More

Writing C/C++ code efficiently in Competitive programming

sudhir sharma
Updated on 17-Apr-2020 13:17:18

271 Views

In competitive programming, the most important thing is an effective code. Optimized and faster code is important and can make a difference in the ranks of the programmer.To write an effective c/c++ code in competitive programming, here are some effective tools for writing c/c++ code efficiently, First, let’s recall some basic terms, Template is writing code that does not depend on a particular type.Macro is a named code fragment.Vectors are like automatically resizable dynamic arrays that update size with insertion and deletion of the element.Now, let’s see some basic updates in code that can make in increasing efficiency of code, ... Read More

Writing OS Independent Code in C/C++

sudhir sharma
Updated on 17-Apr-2020 12:42:29

295 Views

A program that can interact with the operating system irrespective of the OS on which it runs.Most of the compilers of c/c++ have the power to define macros that detect OS.Some Macros of GCC compiler are −_WIN32: macros for 32 bit and 64-bit Windows OS._WIN64: macros for 64-bit Windows OS._UNIX: macros for UNIX OS._APPLE_: macros for macOS.Based on these macros defined, let’s create a program that will work irrespective of the OS −Example Live Demo#include using namespace std; int main() {    #ifdef _WIN32     system("dir");    #else     system("ls");    #endif     ... Read More

Advertisements