Thursday, 23 February 2017

Sample Questions of C Language for BCA-1

1] Program to find sum of two numbers.
#include<stdio.h>
#include<conio.h>
void main()
{ int a,b,s;
clrscr();
printf(“Enter two no: ”);
scanf(“%d%d",&a,&b);
s=a+b;
printf(“sum=%d”,s);
getch();
}

Output:
Enter two no: 5, 6     sum=11

2] Program to find area and circumference of circle.
#include<stdio.h>
#include<conio.h>
void main()
{ int r;
float pi=3.14,area,ci;
clrscr();
printf(“enter radius of circle: ”);
scanf(“%d”,&r);
area=pi*r*r;
printf(“area of circle=%f ”,area);
ci=2*pi*r;
printf(“circumference=%f ”,ci);
getch();
}

Output:

enter radius of a circle: 5
area of circle=78.000
circumference=31.4

3] Program to find the simple interest.
#include<stdio.h>
#include<conio.h>
void main()
{ int p,r,t,si;
clrscr();
printf(“enter principle, Rate of interest & time to find simple interest: ”);
scanf(“%d%d%d”,&p,&r,&t);
si=(p*r*t)/100;
printf(“simple intrest= %d”,si);
getch();
}

Output:
enter principle, rate of interest & time to find simple interest: 500 5 2
simple interest=50

4] Program to convert temperature from degree centigrade to Fahrenheit.
#include<stdio.h>
#include<conio.h>
void main()
{ float c,f;
clrscr();
printf(“enter temp in centigrade: ”);
scanf(“%f”,&c);
f=(1.8*c)+32;
printf(“temp in Fahrenheit=%f ”,f);
getch();
}
Output:
enter temp in centigrade: 32
temp in Fahrenheit=89.59998

5] Program to calculate sum of 5 subjects and find percentage.

#include<stdio.h>
#include<conio.h>
void main()
{
int s1,s2,s3,s4,s5,sum,total=500;
float per;
clrscr();
printf(“enter marks of 5 subjects: ”);
scanf(“%d%d%d%d%d”,&s1,&s2,&s3,&s4,&s5);
sum=s1+s2+s3+s4+s5;
printf(“sum=%d”,sum);
per=(sum*100)/total;
printf(“percentage=%f”,per);
getch();
}

Output:
enter marks of 5 subjects: 60 65 50 60 60
sum=300
percentage=60.000

6] Program to show swap of two no’s without using third variable.

#include<stdio.h>
#include<conio.h>
void main()
{ int a,b;
clrscr();
printf(“enter value for a & b: ”);
scanf(“%d%d”,&a,&b);
a=a+b;
b=a-b;
a=a-b;
printf(“after swapping the value of a & b: %d %d”,a,b);
getch();
}

Output:
enter value for a & b: 4 5
after swapping the value of a & b: 5 4

7] Program to reverse a given number.

#include<stdio.h>
#include<conio.h>
void main()
{ int n,a,r=0;
clrscr();
printf(“enter any no to get its reverse: ”);
scanf(“%d”,&n);
while(n>=1)
{ a=n%10;
r=r*10+a;
n=n/10;
}
printf(“reverse=%d”,r);
getch();
}

Output:
enter any no to get its reverse: 456
reverse=654

8] Program to find gross salary.
#include<stdio.h>
#include<conio.h>
void main()
{ int gs,bs,da,ta;
clrscr();
printf(“enter basic salary: ”);
scanf(“%d”,&bs);
da=(10*bs)/100;
ta=(12*bs)/100;
gs=bs+da+ta;
printf(“gross salary=%d”,gs);
getch();
}

Output:
enter basic salary: 100
gross salary=122

9] Program to print a table of any number.

#include<stdio.h>
#include<conio.h>
void main()
{ int gs,bs,da,ta;
clrscr();
printf(“enter basic salary: ”);
scanf(“%d”,&bs);
da=(10*bs)/100;
ta=(12*bs)/100;
gs=bs+da+ta;
printf(“gross salary=%d”,gs);
getch();
}

Output:

enter a no to know table: 2
2*1=2
2*2=4
2*3=6
2*4=8
2*5=10
2*6=12
2*7=14
2*8=16
2*9=18
2*10=20

10] Program to find greatest in 3 numbers.

#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,c;
clrscr();
printf(“enter value of a, b & c: ”);
scanf(“%d%d%d”,&a,&b,&c);
if((a>b)&&(a>c))
printf(“a is greatest”);
if((b>c)&&(b>a))
printf(“b is greatest”);
if((c>a)&&(c>b))
printf(“c is greatest”);
getch();
}
Output:
enter value for a, b& c: 5 7 4
b is greatest

11] Program to show the use of conditional operator.
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
printf(“enter value for a & b: ”);
scanf(“%d%d”,&a,&b);
(a>b)?printf(“a is greater”):printf(“b is greater”);
getch();
}
Output:
enter value for a & b: 5 7
b is greater

12] Program to find that entered year is leap year or not.
#include<stdio.h>
#include<conio.h>
void main()
{
int n;
clrscr();
printf(“enter any year: ”);
scanf(“%d”,&n);
if(n%4==0)
printf(“year is a leap year”);
else
printf(“year is not a leap year”);
getch();
}
Output:
enter any year: 1947
year is not a leap year

13] Program to find whether given no. is even or odd.
#include<stdio.h>
#include<conio.h>
void main()
{
int n;
clrscr();
printf(“enter any no: ”);
scanf(“%d”,&n);
if(n%2==0)
printf(“no is even”);
else
printf(“no is odd”);
getch();
}
Output:
enter any no: 5
no is odd

14] Program to shift inputed data by two bits to the left.
#include<stdio.h>
#include<conio.h>
void main()
{
int x,y;
clrscr();
printf(“Read the integer from keyboard :- ”);
scanf(“%d”,&x);
x<<=3;
y=x;
printf(“\nThe left shifted data is = %d ”,y);
getch();
}
Output:
Read the integer from keyboard :- 2
The left shifted data is = 16

15] Program to use switch statement. Display Monday to Sunday.
#include<stdio.h>
#include<conio.h>
void main()
{
char ch;
clrscr();
printf(“enter m for Monday\nt for Tuesday\nw for Wednesday\nh for Thursday\nf for
Friday\ns for Saturday\nu for Sunday);
scanf(“%c”,&ch);
switch(ch)
{
case ‘m’:
case ‘M’:
printf(“monday”);
break;
case ‘t’:
case ‘T’:
printf(“tuesday”);
break;
case ‘w’:
case ‘W’:
printf(“wednesday”);
break;
case ‘h’:
case ‘H’:
printf(“thursday”);
break;
case ‘f ’:
case ‘F’:
printf(“friday”);
break;
case ‘s’:
case ‘S’:
printf(“saturday”);
break;
case ‘u’:
case ‘U’:
printf(“sunday”);
break;
default :
printf(“wrong input”);
break;
}
getch();
}
Output:
enter m for Monday
t for Tuesday
w for Wednesday
h for Thursday
f for Friday
s for Saturday
u for Sunday: f
friday

16] Program to display arithmetic operator using switch case.
#include<stdio.h>
#include<conio.h>
void main()
{ int a,b,n,s,m,su,d;
clrscr();
printf(“enter two no’s : ”);
scanf(“%d%d”,&a,&b);
printf(“enter 1 for sum\n2 for multiply\n3for subtraction\n4 for division: ”);
scanf(“%d”,&n);
switch(n)
{
case 1:
s=a+b;
printf(“sum=%d”,s);
break;
case 2:
m=a*b;
printf(“multiply=%d”,m);
break;
case 3:
su=a-b;
printf(“subtraction=%d”,su);
break;
case 4:
d=a/b;
printf(“divission=%d”,d);
break;
default:
printf(“wrong input”);
break;
}
getch();
}
Output:
enter two no’s: 8 4
enter 1 for sum
2 for multiply
3 for subtraction
4 for division: 1
sum=12

1 comment:

  1. B.com part3 dtp notes in English. Please sir provide. We can't arrange notes in English medium. Please sir provide us.

    ReplyDelete