C Exercises
- 'C' Exercises ▼
- Basic C Programming
- If-else Statements in C
- Loops in C
- Arrays in C
- Pattern Programs in C
- Series Programs in C
- String in C
- Switch-case in C
- Functions in C
- Pointers in C
- Bitwise operators in C
- File handling in C
- Tricky Programs in C
- Projects in C ▼
- C Project-1
- C Project-2
- Core Java
- Interview Questions
- Java Introduction
- Basic Java Examples
- Arrays in Java
- Generics in Java
- Constructor in Java
- Courses
- Tools
- Alternatives
Oct 15, 2020
How Can Be Good write correct coding in C programming and how can be start?
Oct 8, 2020
C program to print 2 15 41 80 132 197 275 366 numbers series
Ex: Write a C program to print 2 15 41 80 132 197 275 366 numbers series. How to write a C program to print 2 15 41 80 132 197 275 366 numbers series. C program to print 2 15 41 80 132 197 275 366 numbers series.
Input from user:
Enter the number: 8
Expected output:
2 15 41 80 132 197 275 366
Oct 7, 2020
C Program to Print 1 3 8 15 27 50 92 Number Series
C Program to Print Natural Numbers Series
Ex: Write a C program to print natural number series. How to write a C program to print natural number series. C program to print natural number series.
Input from user:
Enter the number: 8
Expected output:
1 2 3 4 5 6 7 8...
Step by Step logic of the given program:
1. Accept input number from user declare variable say no.
2. Run for loop from 1 to no to print series from 1 to n:
3. Inside that loop print value of i.
Program to print natural numbers series :
#include<stdio.h>
void main()
{
int no;
int i;
printf("Enter the number:\n");
scanf("%d",&no);
/*Run loop from 1 to no*/
for(i=1;i<=no;i++)
{
/*Print value of i with one space*/
printf("%d ",i);
}
}
Above program shows the following output:
Share your thoughts in the comments below...
Series Programs in C Exercises and Solutions
Guess the Number Game in C (Project 2)
Guess the number game Program in C:
Quick links:
In these program we used two extra header files one is <stdlib.h> and second is <time.h>. <stdlib.h> header file used because,
Oct 5, 2020
Rock-Paper-Scissor Game In C (Project-1)
Rock-Paper-Scissor Game Project using C Language:
In these program we used two new header files one is <stdlib.h> and second is <time.h>. <stdlib.h> header file used because
Oct 1, 2020
Data Input and Output Functions in C Programming
Data Input and output functions in C:
The C programming language supports many library functions which includes a number of input/output functions. These functions are used to transfer the information between the computer and device(user).
Some basic input/output functions are:
- scanf() and printf(): These two functions are used to transfer the single characters, strings and numerical values.
- getchar() and putchar(): These two functions are used to transfer single characters.
- gets() and puts(): is used to input and output strings.
1. How to use scanf and printf functions:
scanf() function is used to take input from user(keyboard).
printf() function is used to display output on the screen.
Example Program:
#include<stdio.h>
void main()
{
int num;// variable definition
/*Display message and ask user to enter some number... using printf()*/
printf("Enter the number:");
/*Read the number entered by user... using scanf()*/
scanf("%d",&num);
/*Display the number with message...using printf() */
printf("You entered number is: %d",num);
}
In above program %d is used to scan the intiger value.
If value is char then we use %c.
If value is float then we use %f and so on...
Above program shows the following output:
2. How to use getchar and putchar functions in our program:
getchar() function reads a single character from the terminal and returns it as an intiger.
putchar() function is used to display these single character.
Example program:
#include<stdio.h>
void main()
{
int a;
printf("Enter a character:");
/*Here, getchar function is used to store the accepted character in variable a*/
a = getchar();
/*Display the character stored in variable a using putchar function*/
putchar(a);
}
Above program shows the following output:
3. How to use gets() and puts() function in C:
In simple words:
gets() function is used to accept string from user.
puts() function is used to display the string.
Example program:
#include<stdio.h>
void main()
{
//Declare character array to store string
char str[100];
printf("Enter a string: ");
/*store string in array str*/
gets(str);
/*Display string on the output screen*/
puts(str);
}
Above program shows the following output: