Translate

10 simple program in C language

10 Simple Programs in C language 

Before starting i suggest you to use tools "DEV C++" which very simple to use click here to download 
                        


1. Program to print Hello world in C.

we are going to print just "Hello World" use of C program.

code --

#include<stdio.h>
#include<conio.h>

void main()
{
printf("Hello Wrold");

getch();

}

Output --
                         
 


2. Program to use Scanf . 
With the help of scanf  we can give input and print it.

Code

#include<stdio.h>

#include<conio.h>

void main()
{
char Name[20];
printf("Enter your Name \t");
scanf("%s",&Name);
printf("Your Name is - %s",Name);
getch();
}

Output --

                                       




3. Program to use "for" loop.
With the help of "for" loop we can any thing print in loop.

Code--
#include<stdio.h>

#include<conio.h>

void main()
{
char Name[20];
int i;
printf("Enter your Name \t");
scanf("%s",&Name);
for(i=0;i<5;i++)
{
  printf("\nYour Name is - %s",Name);
  
    }
getch();
}

Output--

                       

4.program to addition of two number.

Code--

#include<stdio.h>

#include<conio.h>

void main()
{
int a,b,c;
printf("Enter the 1st No--");
scanf(" %d",&a);
printf("Enter the 2nd No --");
scanf(" %d",&b);
c=a+b;
printf("Sum is %d",c);
getch();
}

Output--
                            



5.Program to convert paise to rupees and rupees to paise.

Code--
#include<stdio.h>
#include<conio.h>
void main(){
int paise1,paise2,rupee,rupees;
printf("\nEnter the value of paise \t");
scanf("\n%d",&paise1);
rupee=paise1/100;
printf("Rupees %d",rupee);
printf("\nEnter value in a rupees to convert into paise\t");
scanf("\n%d",&rupees);
paise2=rupees*100;
printf("\nPaise is %d",paise2);
    
     
     getch();
     
}



Output--

                     

6.Program to Reverse of numbers.

Code--
#include<stdio.h>
#include<conio.h>
void main()
{
int array[50],i,n;
printf("\nEnter the size of array");
scanf("%d",&n);
printf("\n Now enter the array value one by one\n");
for(i=0;i<n;i++)
{
scanf("\n%d",&array[i]);
}
for(i=n;i>0;i--)
{
printf("\n Reverse value is=%d",array[i-1]);
}
getch();
}

Output--

                                  

7.Program to print star .
Code--
#include<stdio.h>

#include<conio.h>
void main()
{
int i,n,j;
printf("Enter the value of star");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
for(j=1;j<=i;j++)
{
printf("*");
    }
    printf("\n");
}
getch();
}

Output--
                             

8. Program of array sorting and find median of array.

Code--
#include<stdio.h>
#include<conio.h>

int main()
{
int array[50],k,i,n,a,tamp=0,j,mid;
printf("\nEnter the size of array\t");
scanf("%d",&n);
printf("\nNow enter the number one by one\t\n");
for(i=0; i<n; i++)
{
scanf("%d",&array[i]);
}
for(i=0;i<n;i++)
{
printf("\nArrays was %d \t",array[i]);
}
printf("\n After sorting array\n");
for(j=0;j<n;j++)
{
for(i=0;i<n;i++)
{
if(array[i]>array[i+1])
{
    tamp = array[i];
    array[i] = array[i+1];
    array[i+1] = tamp;
    }
   
   
       }
       
    
    
}
for(i=0;i<n;i++)
{
printf("\nSorted list=%d",array[i]);
     }
     if(n%2==0)
      {
      printf("\nMedian is :%d",(array[n/2]+array[n/2-1])/2);
}
else
{
    printf("\nMedian is =:%d",array[n/2]);
}
return 0;
getch();
}

Output--

           

9.Program of calculator  use of while and switch statement. 

Code--
#include<stdio.h>
#include<conio.h>
#include<process.h>

void main()
{
while(1)
{
int a,b,c;
char op;
printf("\nEnter the first number\t");
scanf("%d",&a);
printf("\nEnter the second number\t");
scanf("%d",&b);
printf("\nYou can use this operator\n");
fflush(stdin);
printf("\n\n'+'\n\n'-'\n\n'*'\n\n'/'\n\nIf you want to exit then press'x'\t");
scanf("%c",&op);
switch(op)
{
case'+':
c=a+b;
break;
case'-':
    c=a-b;
break;
case'*':
    c=a*b;
break;
case'/':
    c=a/b;
break;
case'x':
     exit(1);
}
printf("%d",c);
}
getch();
}

Output--

       

10. Most interesting program of KBC .

Code--

#include<stdio.h>
#include<conio.h>
int main()
{
char a,b,c,d,e,f,g,h,i,j,k,l,m;  
printf("Welcome to KBL\n");
    printf("If you are ready to play this game then press 'y'  ");
    printf("\n Otherwise press any key\n");
    scanf("\n %c",&a);
     if ((a == 'y')||(a == 'Y'))
     {
      printf("Qus No.1 \n");
            printf("For 2,000  \n");
            printf("How many have ring in olympic flag\n");
            printf("A.Two\n");
            printf("B.Three\n");
            printf("C.Four\n");
            printf("D.Five\n");
            
            scanf("%s",&b);
             if ((b == 'd')||(b=='D'))
            {
                printf("\nYou won 2,000 Rs\n");
                
                 printf("\nQus No.2 \n");
            printf("For 4,000  \n");
            printf("World largest statue\n");
            printf("A.Statue of Librity\n");
            printf("B.Stutue of Gaga\n");
            printf("C.Statue of unity\n");
            printf("D.Statue of balto\n");
            
            scanf("%s",&c);
            if ((c=='c')||(a =='C'))
            {
            printf("\nYou won 4,000 Rs\n");
             
            printf("\nQus No.3 \n");
            printf("For 6,000  \n");
            printf("The capital of Uttarakhand is\n");
            printf("A.Masoorie\n");
            printf("B.Dehara Dun\n");
            printf("C.Nanital\n");
            printf("D.Himachal\n");
            
              scanf("%s",&d);

        if ((d == 'b')||(d=='B'))
            {
                printf("\nYou won 6,000 Rs\n");
                
                printf("\nQus No.4 \n");
            printf("For 12,000  \n");
            printf(" Which Indian state has the literacy rate have low\n");
            printf("A.Rajasthan\n");
            printf("B.Bihar\n");
            printf("C.Himachal\n");
            printf("D.Arunachal Pradesh\n");
            
            scanf("%s",&e);

        if (e == 'b')
            {
                printf("\nYou won 12,000 Rs\n");
                
                printf("\nQus No.5 \n");
            printf("For 20,000  \n");
            printf(" How much literacy have in india \n");
            printf("A.65.38%\n");
            printf("B.54.36%\n");
            printf("C.45.32%\n");
            printf("D.62.23%\n");
            
            scanf("%s",&f);

        if (f == 'a')
            {
                printf("\nYou won 20,000 Rs\n");
                
                 printf("\nQus No.6 \n");
            printf("For 35,000  \n");
            printf("  Which of the following is not a member of the European Union.\n");
            printf("A.United kingdom\n");
            printf("B.Norway\n");
            printf("C.Greece\n");
            printf("D.Finland\n");
            
            scanf("%s",&g);

        if (g == 'b')
            {
                printf("\nYou won 35,000 Rs\n");
                
                printf("\nQus No.7 \n");
            printf("For 50,000  \n");
            printf(" Currently who is the Chief Minister of Goa (State of India)\n");
            printf("A.Mansoor adil\n");
            printf("B.Manohar parrikar\n");
            printf("C.Prasant Sawant\n");
            printf("D.Ashok Ghalot\n");
            
            scanf("%s",&i);

        if (i == 'c')
            {
                printf("\nYou won 50,000 Rs\n");
                
                 printf("\nQus No.8 \n");
            printf("For 75,000  \n");
            printf("  In 2017 which Space Agency sends 104 satellites in a single mission?\n");
            printf("A.NASA\n");
            printf("B.ISRO\n");
            printf("C.Russian\n");
            printf("D.Chaina\n");
            
            scanf("%s",&j);

        if (j == 'b')
            {
                printf("\nYou won 75,000 Rs\n");
                
                 printf("\nQus No.9 \n");
            printf("For 1,00,000  \n");
            printf("  Birth of Mahatama Ghandhi\n");
            printf("A.2 october 1865\n");
            printf("B.2 october 1869\n");
            printf("C.2 october 1875\n");
            printf("D. 2 october 1895\n");
            
            scanf("%s",&k);

        if (k == 'b')
            {
                printf("\nYou won 1,00,000 Rs\n");
                
                 printf("\nQus No.10 \n");
            printf("For 2,50,000  \n");
            printf("  The first speaker of Lok Sabha was\n");
            printf("A. APJ Abdul Kalam\n");
            printf("B. K.M Munshi\n");
            printf("C. G.V Mahavalnker\n");
            printf("D. H.J Kaniya\n");
            
            scanf("%s",&l);

        if (l == 'c')
            {
                printf("\nYou won 10,00,000 Rs\n");
                
                 printf("\nQus No.11 \n");
            printf("For 10,00,000  \n");
            printf("  Reserve Bank of India is headquartered at\n");
            printf("A.New Delhi\n");
            printf("B.Kolkata\n");
            printf("C.Chenni\n");
            printf("D.Mumbai\n");
            
            scanf("%s",&m);

        if (m == 'd')
            {
                printf("\nYou won 1,00,00,000 Rs\n");
                
                printf("\nWell Done \n  Thanks for played");
            }
            else
             printf("You loss the game\n");
            }
            else
             printf("You loss the game\n");
            }
            else
             printf("You loss the game\n");
            }
            else
             printf("You loss the game\n");
            }
            else
             printf("You loss the game\n");
            }
            else
             printf("You loss the game\n");
            }
            else
             printf("You loss the game\n");
            }
            else
             printf("You loss the game\n");
            }
            else
             printf("You loss the game\n");
}
else
printf("You loss the game\n");
            }
}
else
{
printf("ok");
}
return 0;
getch();
}


Here i am not going to full output due to very long output.

Output--

         


Thank you. For visit my side come again and share this program with your friends and tell me how's it in comment and if have any kind of problem then you can ask in my Instagram which i given below i will contact.



                                           THANK YOU 

                                            Tap on image ↓


  Tap on image ↓



  






Post a Comment

0 Comments