Hi guys welcome to programming ram
In this article we are going to do get some knowledge about c programming and some problems In c Programming .
In This article we are going to discuss about the following topics
- what is c programming language
- what is identifiers
- what is variable
- what is keyword
- what is operator
- constants in c
- Escape sequence in c
- comments in c
- Problems on c programming
- Answers of the programs
Before moving forward let us know some important things about C Programming
what is c programming language
- C programming language is a general programming language and it is developed by Dennis .Ritchie
- It is a structured and middle level language
- It should be written into one or more text files with extension ( .c ) example hellow.c
- It can vary to 3 lines to millions
- The following software required for c environment
- (a) Text editor (b) The c compiler
what is identifiers
- It is nothing but a name that is assigned to an element in program , example name of variable functions etc.
Rules for identifiers
- Not contain whitespace
- can not use a keyword as Identifier
- first character must be alphabet or underscore
- names must be unique
what is variable
- A variable is nothing but a name given to a primary storage area that our programs can manipulate
- To indicate the storage area each variable should be given unique name
- Variable names are just the symbolic representation of memory location
Rules for naming variable
- A variable name only have letters ( Both upper case and lower case ) digits and underscore.
- The first letter of variable should be either a letter or an underscore
- There is no rule how long a variable name
Two Types of variable
1- Global Variable
visibility is applicable to entire program and can be access from any block of functions
2- Local Variable
It is declared in a block and visibility is only in that block , these variables scope is local to that function.
What is keyword
- keyword means this is a fixed meaning that can not be changed it is act as a block in the program
- we can not use a keyword as an identifier in our c program
- These are the reserve word in c programming
- There are totally 32 Keyword in c language
what is operator
- C operators are the symbols that are used to perform mathematical or logically manipulation
- The c programming language is rich with built - in operator
- operators take part in a program for manipulating data and variables
Types of operators (required and useful)
1-) Arithmetic operator
These are used to performing mathematical calculation like addition( + ) subtraction ( - ) multiplication( * ) , division ( / ) , modulus ( % ).
2-)Increment and decrement
These operators are used to generally minimize the calculation
i.e
- ++x -> Pre increment
- --x ->pre decrement
- x++ ->post increment
- x-- -> post decrement
3-) Relational operator
These operators are used to compare two variables
a) == ( equal to )
b) != (Not equal to )
c) <= (less than equal to)
d) >= (greater than equal to )
4-) Logical operator
c program provides three logical operators when we make more than one conditions
a-) && ( and and operator)
It performs logically conjunction of two expression ( If both evaluates true result is true ) (if both false result is false )
b-) | | (Or operator )
Or operator logically disjunction of two expression
c-) != (Not operator)
Logically not operator it performs logical negation of an expression
Constants in c
- This is the most fundamental and essential part of c programming language
- This is also called as literals
- can be any of the data type
SYNATAX
const type const-name
ex- const int s=10;
Escape sequence in c
- The c compiler interprets any char followed by a ' \ ' as an escape sequence .
- Escape sequence are not displayed on the screen
- Each escape sequence has its own predefined function
Comment Line in c
- The c compiler ignore the comment lines .
- The comment lines are used to for better understanding a program
two types of comments
a-) Single line comment ( // This is single line comment )
b-) Multi line comment ( /* This is multi line comment */ )
Problems on c programming
Q-1 ) write a program in c to print hello world.
Q-2) write a program to print programming Ram .
Q-3) write a program to print your name age and city in different line .
Hint ( Use escape sequence \n)
Q-4) Write a program to Take input from the user and print it .
Q-5) Write a program to take Two numbers as input and print it.
Q-6) Write a program to take input two numbers as an input and add them.
Hint ( Use '+' operator )
Q-7) Write a program to multiply two number .
Hint ( Use '*' operator )
Q-8) write a program to take input as two numbers and perform addition , subtraction ,multiplication, and division in one program .
Q-9) Write a program to take a number input from user and increment it.
Q-10) Write a program to take a number input from the user and decrement that.
Q-11) write a program to Use local and global variable in it.
Q-12) Write a program to print this
*
* *
* * *
* * * *
Q-13) Write a program to find out area of a square
Q-14) Write a program to find out area of circle
SOLUTIONS
Q-1 ) write a program in c to print hello world.
#include<stdio.h>
int main()
{
printf("Hello World");
return 0;
}
OUTPUT
Hello world
Q-2) write a program to print programming Ram .
#include<stdio.h>
int main()
{
printf("Programming Ram");
return 0;
}
OUTPUT
Programming Ram
Q-3) write a program to print your name age and city in different line .
#include<stdio.h>
int main()
{
printf("Name - Programming Ram \n");
printf("Age - 18\n");
printf("City - Jajapur");
return 0;
}
Output
Name - Programming Ram
Age - 18
City - Jajapur
Q-4) Write a program to Take input from the user and print it .
#include<stdio.h>
int main()
{
int n;
printf("Enter a number ");
scanf("%d",&n);
printf("\nYou entered %d ",n);
return 0;
}
Output
Enter a number - 14
You entered - 14
Q-5) Write a program to take to numbers as input and print it.
#include<stdio.h>
int main()
{
int n,m;
printf("Enter a number ");
scanf("%d",&n);
printf("Enter another number ");
scanf("%d",&m);
printf("\nYou entered %d %d ",n , m);
return 0;
}
Output
Enter a number - 14
Enter another number - 118
You entered - 14 118
#include<stdio.h>
int main()
{
int n,m,sum=0;
printf("Enter a number ");
scanf("%d",&n);
printf("Enter another number ");
scanf("%d",&m);
sum=n+m;
printf("After addition %d ",sum);
return 0;
}
FEEDBACK
If still you have any doubts please comment below and please share your approaches with us and if you get some knowledge from the post please comment below please .
Thank You !
Post a Comment
Post a Comment
Please do not spam in comment