Introduction to Java programming:
Java is a mostely used and one of the most popular programming languages, which is developed by sun Microsystems in 1991. Java is developed by James Gosling and Patrick Naughton.
Java is a mostely used and one of the most popular programming languages, which is developed by sun Microsystems in 1991. Java is developed by James Gosling and Patrick Naughton.
In this article I am going to share all C programming exercises and solutions. Here, you will find all C programming exercises and examples on this blog.
To start learning Programming first you need to know what is programming and why it is important to learn.
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
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...
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,
In these program we used two new header files one is <stdlib.h> and second is <time.h>. <stdlib.h> header file used because
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).
scanf() function is used to take input from user(keyboard).
printf() function is used to display output on the screen.
#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:
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:
In simple words:
gets() function is used to accept string from user.
puts() function is used to display the string.
#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: