Sei sulla pagina 1di 12

Q 1 Write a C program for finding SI of the given

amount and rate of interest.

#include<stdio.h>
#include<conio.h>
main()
{
float p,r,t,si,total;
clrscr();
printf("Enter the principal ");
scanf("%f",&p);
printf("Enter the rate of interest ");
scanf("%f",&r);
printf("Enter the time in years ");
scanf("%f",&t);
printf("\n");
si=(p*r*t)/(100);
//ok
total=p+si;
printf("Your simple interest is %f\n",si);
printf("Your total amount becomes %f ",total);
gotoxy(1,10);printf("--*-*-*-*-*--\nNimish
Bansal\n02816401516");
getch();
}

Q 2. . Write a C program to subtract two


numbers without using subtraction

#include<stdio.h>
#include<conio.h>
main()
{
int a,b,i,ans;
clrscr();
printf("Enter the 1st number
");
scanf("%d",&a);
printf("Enter the second no
- ");
scanf("%d",&b);
ans=a+((~b)+1);
printf("
_____\n");
printf("After subtraction ans is
%d
\n",ans);
printf("
_____");
gotoxy(1,10);printf("--*-*-*-*-*--\nNimish
Bansal\n02816401516");
getch();
}

Q 3 (A) Write a C program to swap 2 numbers


using Arithmetic operator

#include<stdio.h>
#include<conio.h>
main()
{
int a,b;
clrscr();
printf("Enter the first no ");
scanf("%d",&a);
printf("Enter the second no ");
scanf("%d",&b);
printf("\n");
a=a+b;
b=a-b;
a=a-b;
printf("After swapping the 1st no becomes
%d\n",a);
printf("After swapping the 2nd no becomes
%d ",b);
gotoxy(1,10);printf("--*-*-*-*-*--\nNimish
Bansal\n02816401516");
getch();
}

Q 3(B) Write a C program to swap 2 numbers


using bitwise operator

#include<stdio.h>

#include<conio.h>
main()
{
int a,b,c;
clrscr();
printf("Enter the first no ");
scanf("%d",&a);
printf("Enter the second no ");
scanf("%d",&b);
printf("\n");
a=a^b;
b=a^b;

a=a^b;
printf("After swapping the 1st no becomes
%d\n",a);
printf("After swapping the 2nd no becomes
%d ",b);
gotoxy(1,10);printf("--*-*-*-*-*--\nNimish
Bansal\n02816401516");
getch();
}

Q 4 . Write a C program to check whether the


given character is a digit or a character in
lowercase or uppercase alphabet

#include<stdio.h>
#include<conio.h>
main()
{
char a;
clrscr();
printf("Enter the char. to check if it is digit,
uppercase or lowercase alphabet \n\n");
scanf("%c",&a);
printf("\n");
if(a>='0'&&a<='9')

printf("Its a digit");
else if(a>='a'&&a<='z')
printf("It is lower case alphabet");
else if(a>='A'&&a<='Z')
printf("It is uppercase alphabet");
else
printf("It is neither a digit nor an aphabet,its a
special character");
gotoxy(1,10);printf("--*-*-*-*-*--\nNimish
Bansal\n02816401516");
getch();
}

Q.- 5. Write a C program to check whether the


year is a leap year or not.

#include<stdio.h>
#include<stdlib.h>
void main()
{
int n;
int x;
clrscr();
printf("Please enter any year of your
choice: ");
scanf("%d",&n);
if((n%100)==0)
{if((n%400) ==0)
printf("\nTHe given year is a leap year");
else

printf("\nThe given year is not a leap


year");
}
else if ((n%4)==0)
{printf("\nIt is a leap year");
}
else
printf("\nThe given year is not a leap
year");
gotoxy(1,10);printf("--*-*-*-*-*--\nNimish
Bansal\n02816401516");
getch();
}

Potrebbero piacerti anche