C Programs for Practise

 1.C Program for Swapping Two numbers

#include<stdio.h>

int main()

{

    int A,B,temp=0;

    printf("Enter A, B values\n");

    scanf("%d %d",&A,&B);

    printf("Before Swapping A =%d\t B=%d",A,B);

    temp=A;

    A=B;

    B=temp;

    printf("\n After Swapping A=%d \t B=%d",A,B);

    return 0;


}


Output:
Enter A, B values
6
8
Before Swapping A =6     B=8
 After Swapping A=8      B=6


2.C Program using size of operator

#include<stdio.h>
int main()
{
int a;
float b;
char c;
printf("size of  a is %d",sizeof(a));
printf("\nsize of b is %d",sizeof(b));
printf("\nsize of c is %d",sizeof(c));
return 0;
}

Output:
size of a is 4
size of b is 4 
size of c is 1

3.C Program to write non formatted I/O functions
#include<stdio.h>
int main()
{
char c;

c=getchar();
putchar(c);
return 0;
}

Output:
C
C

4. C Program to calculate Quotient and reminder if divisor, dividend given
#include<stdio.h>
int main()
{
    int Divisor,Dividend,Quotient,Reminder;
    printf("Enter Dividend Value\n");
    scanf("%d",&Dividend);
    printf("Enter Divisor Value\n");
    scanf("%d",&Divisor);
    Quotient=Dividend/Divisor;
    printf("\nQuotient Value is=%d",Quotient);
    Reminder=Dividend%Divisor;
    printf("\nReminder Value is=%d",Reminder);
    return 0;
}

Output:
Enter Dividend Value
250
Enter Divisor Value
15

Quotient Value is=16
Reminder Value is=10

5.Write a C program to Find out Simple Intrest(SI)

#include<stdio.h>
int main()
{
int p,t;
float si,r;
printf("Enter Principle\t");
scanf("%d",&p);
printf("Enter duaration\t");
scanf("%d",&t);
printf("Enter rate of intrest\t");
scanf("%f",&r);
si=(p*t*r)/100;
printf("The Value of SI=%f",si);
return 0;
}

Output:
Enter Principle 10000
Enter duaration 5
Enter rate of intrest   3.5
The Value of SI=1750.000000

6.Write a C -Program to find maximum number among 3 numbers

#include<stdio.h>
#include<conio.h>
int main()
{
    int a,b,c,max;
    printf("Enter a, b, c values\n");
    scanf("%d%d%d",&a,&b,&c);
    max=a;
    if(b>max)
    { max=b;
        printf("b is maximum value=%d",max);
    }
    if(c>max)
    {
        max=c;
        printf(" C is maximum values=%d",max);
    }
    return 0;
}

Output:

Enter a, b, c values
6
9
2
b is maximum value=9

7.Write a C program to identify entered character is upper case or lower case
#include<stdio.h>
#include<conio.h>
int main()
{
    char ch;
    printf("Enter a Letter\n");
    scanf("%c",&ch);
    if(ch>=65&&ch<=97)
    {
        printf("Letter is in upper case\t=%c",ch);
    }
    if(ch>=97&&ch<=122)
    {
        printf("Letter is in lower case\t=%c",ch);
    }
    return 0;

}

No comments:

Post a Comment