Monday, April 20, 2020

Reverse Number in 'C'

Reverse Number:

                            This program reverse the given number.
                       

Example.

                  Given Number: 459
                  Reverse Number: 954



Source Code For Reverse Number:



#include<stdio.h>
#include<conio.h>
void main()
{
             int n, rem;
             clrscr();
             printf("enter a number");
             scanf("%d",&n);
             printf("reverse number is ");
             while(n!=0)
             {
                       rem=n%10;
                       printf("%d",rem);
                       n=n/10; 
              }
              
              getch();

}


Output:




Sunday, April 19, 2020

Sum of n Numbers in 'C'


Sum of n Numbers:

                                   This C program calculates the sum of n numbers.


Source Code For Sum of n Numbers:



#include<stdio.h>
#include<conio.h>
void main()
{
             int i,n,sum=0;
             clrcsr();
             printf("how many numbers you want to add \n");
             scanf("%d",&n);
             for(i=1;i<=n;i++)
             {
                         sum=sum+i;
              }
             printf("sum of  %d numbers is %d",n,sum);
             getch();
}


Output:





Greatest of Two Numbers in 'C'

Source Code For Greatest of Two Numbers:

#include<stdio.h>
#include<conio.h>
void main()
{
            int a, b;
            printf("enter two numbers");
            scanf("%d%d",&a,&b);
            if(a>b)
            {
                     printf("the number %d is greater",a);
             }
             else if(a<b)
             {
                       printf("the number %d is greater",b);
              }
              else
              {
                      printf("the numbers are equal");
               }
               getch();
       

 }


Output:





Sum of Two Numbers in 'C'


Source Code For Sum of Two Numbers:



#include<stdio.h>
#include<conio.h>
void main()
{
        int a, b, sum;
        clrscr();
        printf("enter two numbers");
        scanf("%d%d",&a,&b);
        sum=a+b;
        printf("\n sum of two numbers is %d",sum);
        getch();

}



Output:





Saturday, April 18, 2020

simple program in C - hello world

Source Code For Hello World:



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

void main()
{
           clrscr();
           printf("Hello World");
           getch();

}


Output: