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 .


           image credit


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

  1.  A variable name only have letters ( Both upper case  and lower case ) digits and underscore.
  1. The first letter of variable should be either a letter or an underscore
  1. 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


Q-6) Write a program to take input two numbers as an input and add them.


#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;
}


Output

Enter a number 3
Enter another number 7
After addition 10 


Q-7) Write a program to multiply two number .

#include <stdio.h>
int main()
{
    int n, m, multiply;
    printf("Enter a number ");
    scanf("%d", &n);
    printf("Enter another number ");
    scanf("%d", &m);
    multiply = n * m;
    printf("After Multiply %d ", multiply);
    return 0;
}


Output

Enter a number 2
Enter another number 3
After Multiply 6 



Q-8) write a program to take input as two numbers and perform addition , subtraction ,multiplication, and division in one program .


#include <stdio.h>
int main()
{
    int n, m, sum = 0, subtraction, multiply, division;
    printf("Enter a number   : ");
    scanf("%d", &n);
    printf("Enter another number :");
    scanf("%d", &m);
    sum = n + m;
    subtraction = n - m;
    multiply = n * m;
    division = n / m;
    printf("After addition %d ", sum);
    printf("\nAfter subtraction %d ", subtraction);
    printf("\nAfter Multiply %d ", multiply);
    printf("\nAfter division %d ", division);
    return 0;
}

OUTPUT


Enter a number   : 8
Enter another number :4
After addition 12   
After subtraction 4 
After Multiply 32   
After division 2 

Q-9) Write a program to take a number input from user and increment it.


#include <stdio.h>
int main()
{
    int n;
    printf("Enter a number :");
    scanf("%d",&n);
    n++;
    printf("After increment the number is %d",n);
    return 0;
}

Output

Enter a number :3
After increment the number is 4


Q-10) Write a program to take a number  input from the user and decrement that.

#include <stdio.h>
int main()
{
    int n;
    printf("Enter a number :");
    scanf("%d",&n);
    n--;
    printf("After decrement the number is %d",n);
    return 0;
}

Output

Enter a number :4
After decrement the number is 3


Q-11) write a program to Use local and global variable in it.


#include <stdio.h>

int G; //global variable
int main()
{
    int n; //local variable
    printf("Enter the local variable number :");
    scanf("%d",&n);
    printf("\nThe local variable is  %d",n);
    printf("\nEnter the global var no ");
    scanf("%d",&G);
    printf("\nThe global variable is  %d",G);
    return 0;
}


Output

Enter the local variable number : 5

The Local Variable is - 5

Enter the global variable number : 9

The local variable is - 9


Q-12) Write a program to print this 


#include <stdio.h>
int main()
{
   printf("*\n");
   printf("*  *\n");
   printf("*  *  *\n");
   printf("*  *  *  *\n");
   printf("*  *  *  *  *\n");
    return 0;
}

Output

*
*  *
*  *  *      
*  *  *  *   
*  *  *  *  *

Q-13) Write a program to find out area of a square.


#include<stdio.h>
int main()
{
int length , breath;
int area;
printf("enter the value of length: ");
scanf("%d",&length);
printf("enter the value of breadth:");
scanf("%d",&breath);
area=length*breath;
printf("area of the triangle is %d",area);
return 0;
}

Output

enter the value of length: 3
enter the value of breadth:4
area of the triangle is 12


Q-14) Write a program to find out area of circle

#include <stdio.h>
int main()
{
    float area, radius;
    float pi=3.14;
    //formula for area is pi*r*r;
    printf("enter the value of the radius:");
    scanf("%f", &radius);
    area = pi * radius * radius;
    printf("area of the circle is :%f", area);
    return 0;
}


Output 

enter the value of the radius:4
area of the circle is :50.240002

Check Out OUR Home page for more information about practice problem

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 !