Computer Language Course | Basic Of C Programming Problem Examples ?

 // Hello world example



#include<stdio.h>

#include<conio.h>

void main()

{

clrscr();

printf("Hello World"); 

getch();

}


Output:


 Hello World


..............................


// simple printf example

#include<stdio.h>

#include<conio.h>

void main()

{

   clrscr();

printf("\tMy Introduction\n");

printf("Hey Friends I m Shukla\n");

printf("I am student of Be supportbihar.com");

printf("\nC programming is best for me.");

printf("\t");

   getch();

}


Output:


          My Introduction

        Hey Friends I am shukla

        I m student of Be supportbihar.com

        C programming is best for me.

............................

// print integer example

#include < stdio.h > 


int main()

{

  int a;


  printf("Enter a integer number\n");

  scanf("%d", &a);


  printf("You have Entered number %d\n", a);


  return 0;

}


Output:

Enter a integer number

1001

You have Entered number 1001

...............................


// simple addition of static value

#include<stdio.h>

#include<conio.h>

void main()

{

int a=12,b=4,c;

  clrscr();

c=a+b;

printf("c::%d",c);

  getch();

}


Output:

c::16


............................


// simple division example

#include<stdio.h>

#include<conio.h>

main()

{

int a=10,b=5,c;

clrscr();

      c=a/b;

      printf("c::%d",c);

getch();

}


Output:

c::2


........................


// sum sub mul and div example

#include<stdio.h>

#include<conio.h>

void main()

{

int a=10,b=3,c,r;

float d;

clrscr();

 printf("The value of A is %d",a);

 printf("\nThe value of B is %d",b);

  c=a+b;

  printf("\nSum is %d\n",c);


  c=a-b;

  printf("Subtration is %d\n",c);


  printf("Multipliction is %d",a*b);


  d=a/b;

  printf("\nDivision is %.4f",d);


  r=a%b;

  printf("\nRemaindr is %d",r);

getch();

}


Output:


    The value of A is 10

    The value of B is 3

    Sum is 13

    Subtraction is 7

    Multiplication is 30

    Division is 3.3333

    Remainder is 1


....................


// Global and local variable example

#include <stdio.h> 

#include <conio.h>

 

int  x = 14;  /* Global Variable */


int  main() 

int y = 23;  /* Local Variable */

clrscr();


printf( "\n x = %d, y = %d", x,  y );

getch();

return 0;

}  


Output:

  

 x = 10, y = 20


..........................


// Program to introduce scanf function.

#include<stdio.h>

#include<conio.h>

void main()

{

  int a,b;

  float c;

  clrscr();

  printf("Enter the value of A\n");

  scanf("%d",&a);


  printf("Enter the value of B\n");

  scanf("%d",&b);


  printf("Enter the value of C\n");

  scanf("%f",&c);


  printf("\n\nA:%d\nB:%d\nC:%f",a,b,c);

getch();

}


Output:


    Enter the value of A

    10

    Enter the value of B

    20

    Enter the value of C

    14.02


    A:10

    B:20

    C:14.02


.....................


// addition using scanf

#include<stdio.h>

#include<conio.h>

void main()

{

int a,b,c;

  clrscr();

    printf("enter the value a:\n");

    scanf("%d",&a);

    printf("enter the value b:\n");

    scanf("%d",&b);

    c=a+b;

    printf("c::%d",c);

    getch();

}


Output:

enter the value a:

10

enter the value b:

20

c::30

......................


//subtract two numbers without using subtraction operator

#include<stdio.h>

int main(){

    int a,b,sum;

    printf("Enter any two integers: ");

    scanf("%d%d",&a,&b);

    sum = a + ~b + 1;

    printf("Difference of two integers: %d",sum);

    return 0;

}


Output:


 Enter any two integers: 10 4

 Difference of two integers: 6


.........................


// find square root of number example

#include<stdio.h>

#include<math.h>


int main(){

    int num;

    scanf("%d",&num);


    printf("Square root: %f",sqrt(num));

    return 0;

}


Output:

 25

 Square root: 5


.....................


/*Program to find gross salary.*/

#include<stdio.h>

void main()

{

  int gs,bs,da,ta;

  printf("Enter basic salary:");

  scanf("%d",&bs);

  da=(10*bs)/100;

  ta=(12*bs)/100;

  gs=bs+da+ta;

  printf("gross salary=%d",gs);

}


Output:


 Enter basic salary:10000

 gross salary=12200


............


// Find area of circle using #define

#include<stdio.h>

#include<conio.h>

#define PI 3.142

{

float r,a;

  clrscr();

  printf("enter the radius:\n");

  scanf("%f",&r);

  a=PI*r*r;

  printf("Area of Circle is %.2f",a);

  getch();

}


Output:

enter the radius:

10

Area of Circle is 314.00


........................


// Find area of circle using #define


#include<stdio.h>

#include<conio.h>

#define PI 3.142

{

float r,a;

  clrscr();

  printf("enter the radius:\n");

  scanf("%f",&r);

  a=PI*r*r;

  printf("Area of Circle is %.2f",a);

  getch();

}


Output:

enter the radius:

10

Area of Circle is 314.00


........................


// Find volume of cube

#include<stdio.h>

#include<conio.h>

{

int l,b,h,v;

  clrscr();

  printf("enter the value of l:\n");

  scanf("%d",&l);

  printf("enter the value of b:\n");

  scanf("%d",&b);

printf("enter the value of h:\n");

  scanf("%d",&h);

v=l*b*h;

  printf("Volume Of Cube::%d",v);

  getch();

}


Output:

enter the value of l:

10

enter the value of b:

10

enter the value of h:

10

volume of Cube:1000


.......................


// Find months andremaining day from total days


#include<stdio.h>

#include<conio.h>

void main()

{

    int a,b,r;

        clrscr();

    printf("enter the value a:\n");

    scanf("%d",&a);

        b=a/30;

    printf("Month::%d\n",b);

    r=a%30;

    printf("Remaining Days::%d",r);

    getch();

}


Output:

enter the value a:

65

Month::2

Remaining Days::5


...................


// Find simple interest


#include<stdio.h>

#include<conio.h>

void main()

{

   

float i,p,r,n;

  clrscr();

    printf("enter the value p:\n");

    scanf("%f",&p);

    printf("enter the value r:\n");

    scanf("%f",&r);

    printf("enter the value n:\n");

    scanf("%f",&n);

    i=(p*r*n)/100;

    printf("Interest::%f",i);

    getch();

}


Output:

enter the value of p:

1200

enter the value of r:

1.2

enter the value of n:

3

Interest::43.2


.......................


// Find differenciate in rupees and paisa


#include<stdio.h>

#include<conio.h>

void main()

{

    int r,p;

        float a;

        clrscr();

        printf("enter the value a:\n");

    scanf("%f",&a);

        r=a;

    printf("\nTotal Rupees:%d\n",r);

    p=(a-r)*100;

    printf("\nTotal Paisa:%d\n",p);

    getch();

}


Output:

enter the value a:

12.50

Total Rupees:12

Total Paisa:50


...............................


// Swapping of two number using third variable


#include<stdio.h>

#include<conio.h>

void main()

{

  int a,b,temp;

  clrscr();

     printf("\nEnter the value of A\n");

     scanf("%d",&a);

     printf("\nEnter the value of B\n");

     scanf("%d",&b);

     clrscr();

     printf("\nBefore swapping\n");

     printf("A::%d\nB::%d",a,b);

     temp=a;

     a=b;

     b=temp;

     printf("\nAfter swapping\n");

     printf("A::%d\nB::%d",a,b);

getch();

}


Output:

        Enter the value of A

25

Enter the value of B

20  

Before swapping

A::25

B::20

After swapping

A::20

B::25


...................


// Swapping of two number without third variable


#include<stdio.h>

#include<conio.h>

void main()

{

  int a,b,temp;

  clrscr();

     printf("\nEnter the value of A\n");

     scanf("%d",&a);

     printf("\nEnter the value of B\n");

     scanf("%d",&b);

     clrscr();

     printf("\nBefore swapping\n");

     printf("A::%d\nB::%d",a,b);


     a=b+a;

     b=a-b;

     a=a-b;


/* or directly use this another method

* a=a+b-(b=a);

*/


     printf("\nAfter swapping\n");

     printf("A::%d\nB::%d",a,b);

getch();

}


Output:

        Enter the value of A

25

Enter the value of B

20  

Before swapping

A::25

B::20

After swapping

A::20

B::25


......................


// swap the contents of two numbers using bitwise XOR 


 #include <stdio.h>

   void main()

 {

     long i, k;

     printf("Enter two integers ");

     scanf("%ld %ld", &i, &k);

     printf(" Before swapping \ni= %ld\nk = %ld", i, k);

     i = i ^ k;

     k = i ^ k;

     i = i ^ k;

     printf(" After swapping  \ni= %ld\nk = %ld", i, k);

 }


Output:


 Enter two integers

 45

 89

 Before swapping 

 i= 45

 k = 89

 After swapping

 i= 89

 k = 45


.....................


// Example show use of getchar


#include<stdio.h>

#include<conio.h>

void main()

{

  char a,b;

  clrscr();

   printf("\nEnter one character\n");

   scanf("%c",&a);

   printf("Input character is ==> %c",a);

   fflush(stdin);//to clear input buffer

   printf("\n\n\nEnter second character");

   b=getchar();


   printf("\nASCII value of character(%c)is=> %d",b,b);

getch();

}


Output:

Enter one character

p

Input character is ==> p


Enter second character

n

ASCII value of character(n)is=> 110


....................


// Example show Use of Putchar


#include<stdio.h>

#include<conio.h>

void main()

{

  char a,b;

  clrscr();

   printf("\nEnter one lowercase character\n");

   a=getchar();

   printf("Lowercase character is ==>");

   putchar(a);

   printf("\n\nCharacter in uppercase ==>");

   putchar(a-32);


getch();

}


Output:


        Enter one lowercase character

n

Lowercase character is ==>

n

Character in uppercase ==>

N


.......................


// Example show Use of getche


#include<stdio.h>

#include<conio.h>

void main()

{

  char a,b;

  clrscr();

   printf("\nEnter first character  ");

   a=getche();

   printf("\nSecond character  ");

   b=getche();

   printf("\n\nFirst Character==> %c\nSecond Character==>%c",a,b);

getch();

}


Output:    


Enter first character    

D

Second character  

S

First Character==> D

Second Character==>S


....................


// Use of comma opearor


#include<stdio.h>

#include<conio.h>

void main()

{

  int n;

  int m;

  clrscr();

     printf("Program to comma operator\n\n");

     printf("\nEnter the value of N\n");

     scanf("%d",&n);

     m=(n,n+5);

     printf("\nAfter use of comma operator value is %d",m);

getch();

}


Output:


        Program to comma operator

Enter the value of N  

5

After use of comma operator value is 10


.......................


// program to multiply given number by 4 using bitwise operators 


 #include <stdio.h>

 void main()

 {

     long number, tempnum;

     printf("Enter an integer ");

     scanf("%ld", &number);

     tempnum = number;

     number = number << 2;

     printf("%ld x 4 = %ld", tempnum, number);

 }


Output:


 Enter an integer

 450

 450 x 4 = 1800


.................


// Program to display function without using the Main Function


 #include <stdio.h>

 #define decode(s,t,u,m,p,e,d) m##s##u##t

 #define begin decode(a,n,i,m,a,t,e)

 int begin()

 { 

    printf(" Hello Developers ");

 }


Output:


 Hello Developers


................


// Program to display function without using the Main Function


 #include <stdio.h>

 #define decode(s,t,u,m,p,e,d) m##s##u##t

 #define begin decode(a,n,i,m,a,t,e)

 int begin()

 { 

    printf(" Hello Developers ");

 }


Output:


 Hello Developers


..................


//  Program to convert temperature from degree centigrade to Fahrenheit.


#include<stdio.h>

 

int main() {

float celsius, fahrenheit;

 

printf("Enter temp in Celsius : ");

scanf("%f", &celsius);

 

fahrenheit = (1.8 * celsius) + 32;

printf("\nTemperature in Fahrenheit : %f ", fahrenheit);

 

return (0);

}


Output:

Enter temp in Celsius : 32

Temperature in Fahrenheit : 89.59998


.................


// Shift inputed data by two bits to the left.


#include<stdio.h>

void main(){

   int x,y;

   printf("Read the integer from keyboard :-");

   scanf("%d",&x);

   x<<=2;//left shift operator

   y=x;

   printf("\nThe left shifted data is = %d",y);

 }


Output:


 Read the integer from keyboard :-10

 The left shifted data is = 40


.................


//ASCII value of given character


#include<stdio.h>

int main( 

    char c; 

    printf("Enter any character: ");

    scanf("%c",&c); 

    printf("ASCII value of given character: %d",c);

    return 0;

}


Output:

 

 Enter any character: N

 ASCII value of given character: 78


.........................


// goto statement forword jump


#include <stdio.h> 

#include <conio.h>

 

int  main() 

int a = 10;

clrscr();


printf( "\n Nils Patel" );


if( a == 10 )

{

goto  LABEL;

}


printf( "\n This simple" );

printf( "\n Program" );


LABEL:

printf( "\n go to statement" );

printf( "\n Forword jump" );


getch();

return 0;

}


Output:


 Nils Patel

 go to statement

 Forword jump

.......................

// goto statement with backward jump


#include <stdio.h> 

#include <conio.h>

 

int  main() 

int i;

clrscr();


i = 1;


Label:

printf( "  %d", i );

i++;

if( i <= 10 )

{

goto Label;

}


getch();

return 0;

}


Output:

  

  1  2  3  4  5  6  7  8  9  10

Thanks Author Vinod Shukla From Bihar.

Support Bihar

मैं हूँ Software engineering student Vinod Shukla, मैं इस Blog का Director हूँ हम इस blog के माध्यम से बिहार के Support के लिए Tech , Internet, Students Career, Spoken English, Private & Gov Job और Blogging से related Articles लिखता रहता हूँ ।

एक टिप्पणी भेजें

Please Select Embedded Mode To Show The Comment System.*

और नया पुराने