Check Prime or Not - C Program

Program:

#include<stdio.h>
//#include<conio.h>
#include<math.h>
main()
{
    int n,i,flag=0;//clrscr();
    printf("Enter the number:");
    scanf("%d",&n);
    if(n<=1)
        printf("\nThe no is not prime");
    else
    {
        for(i=2;i<=(n/2);i++)
            {
             if(n%i==0)
             flag=1;
            }

        if (flag==0)
            printf("%d is prime.\n",n);
        else
            printf("%d is not prime.\n",n);
    }
//getch();
}
Output:
nn@linuxmint ~ $ gcc c2.c
nn@linuxmint ~ $ ./a.out
Enter the number:2
2 is prime.
nn@linuxmint ~ $ ./a.out
Enter the number:5   
5 is prime.
nn@linuxmint ~ $ ./a.out
Enter the number:9
9 is not prime.
nn@linuxmint ~ $

Largest Among 3 Numbers - C Program

Program:
#include<stdio.h>
//#include<conio.h>
void main()
{
int a,b,c;
//clrscr();
printf("Enter the numbers:");
scanf("%d%d%d",&a,&b,&c);
if(a>b)
{    if(a>c)
        printf("%d is largest among %d,%d,%d\n",a,a,b,c);
    else
        printf("%d is largest among %d,%d,%d\n",c,a,b,c);
}
else if(b>c)
        printf("%d is largest among %d,%d,%d\n",b,a,b,c);
else
        printf("%d is largest among %d,%d,%d\n",c,a,b,c);
//getch();
}

Output:
nn@linuxmint ~ $ gcc cc4.c
nn@linuxmint ~ $ ./a.out
Enter the numbers:5
3
2
5 is largest among 5,3,2nn@linuxmint ~ $

Change Case of The Letter - C Program

Program:
#include<stdio.h>
//#include<conio.h>
void main()
{
    char c; //clrscr();
    printf("\n\t***A PROGRAM TO CHANGE THE CASE OF THE CHARACTER***\n\n");
    printf("Enter a character:");
    scanf("%c",&c);
    if(c<96)
    {
        printf("\nYou entered the upper case letter '%c' \n\tThe lower case is '%c'.\n",c,c+32);
    }
    else
    {
        printf("\nYou entered the lower case letter'%c' \n\tThe upper case is'%c'.\n",c,c-32);
    }
    //getch();
}

Output:
nn@linuxmint ~ $ gcc CC3.c
nn@linuxmint ~ $ ./a.out

    ***A PROGRAM TO CHANGE THE CASE OF THE CHARACTER***

Enter a character:a

You entered the lower case letter'a'
    The upper case is'A'.
nn@linuxmint ~ $

Find ASCII Value of Characters - C Program

Program:
#include<stdio.h>
//#include<conio.h>
void main()
{
    int b=0,i;
    //clrscr();
    printf("ascii values for different numbers:\n");
    for(i=0;i<100;i++)
    {
        b=b+1;
        printf("\t%d=%c",b,b);
        if(b%5==0)
            printf("\n");
    }
//getch();
}

Output:
nn@linuxmint ~ $ gcc cc2.c
nn@linuxmint ~ $ ./a.out
ascii values for different numbers:
    1=     2=     3=     4=     5=
    6=     7=    8=      9=        10=

    11=
               12=
        14=     15=    13=
    16=     17=     18=     19=     20=
    21=     22=     23=     24=     25=
    26=     27=     28=     29=     30=
    31=     32=     33=!    34="    35=#
    36=$    37=%    38=&    39='    40=(
    41=)    42=*    43=+    44=,    45=-
    46=.    47=/    48=0    49=1    50=2
    51=3    52=4    53=5    54=6    55=7
    56=8    57=9    58=:    59=;    60=<
    61==    62=>    63=?    64=@    65=A
    66=B    67=C    68=D    69=E    70=F
    71=G    72=H    73=I    74=J    75=K
    76=L    77=M    78=N    79=O    80=P
    81=Q    82=R    83=S    84=T    85=U
    86=V    87=W    88=X    89=Y    90=Z
    91=[    92=\    93=]    94=^    95=_
    96=`    97=a    98=b    99=c    100=d
nn@linuxmint ~ $

Temperature Conversion C to F & F to C - C Program

Program:
#include<stdio.h>
//#include<conio.h>
void main()
{
    int d,e=248;float a,b,c;
    //clrscr();
    printf("\n\t\t***Temperature conversion program***\n");
    n:
    printf("\n\tWhat u want to do?\n\t\t1:Convert %cC to %cF\n\t\t2:convert %cF to %cC\n\t\t",e,e,e,e);
    scanf("%d",&d);
    if(d==1)
    {
        printf("Enter the temp in %cc\n",e);
        scanf("%f",&a);
        b=(1.8*a)+32;
        printf("The temperature in %cF is:%f",e,b);
    }
    else if(d==2)
    {
        printf("Enter the temperature in %cF:\n",e);
        scanf("%f",&a);
        b=((0.5555555555555556)*(a-32));
        printf("The temperature in %cC is:%f",e,b);
    }
    else
    {
        printf("\n\tWrong choice!\n\tenter either 1 or 2\n\n\n");
        goto n;
    }
    //getch();
}

Output:
nn@linuxmint ~ $ gcc cc1.c
nn@linuxmint ~ $ ./a.out

        ***Temperature conversion program***

    What u want to do?
        1:Convert �C to �F
        2:convert �F to �C
        1
Enter the temp in �c
100
The temperature in �F is:212.000000nn@linuxmint ~ $ ./a.out

        ***Temperature conversion program***

    What u want to do?
        1:Convert �C to �F
        2:convert �F to �C
        3

    Wrong choice!
    enter either 1 or 2



    What u want to do?
        1:Convert �C to �F
        2:convert �F to �C
        2
Enter the temperature in �F:
212
The temperature in �C is:100.000000
nn@linuxmint ~ $
Related Posts Plugin for WordPress, Blogger...