Ans.
#include
#include<conio.h>
void
main()
{
clrscr();
printf("Name:- payal");
printf("\n Address:-near primary
school");
printf("\n City:-Ambaliyasan");
getch();
}
Example
Output
Name:-
Payal
Address:
near primary school
city
ambaliyasan.
Q.
Write a program to calculate simple addition of two given number.
Ans:
#include
#include<conio.h>
void
main()
{
int num1,num2,ans;
clrscr();
printf("\n Enter Value
No.1:");
scanf("%d",&num1);
printf("\n Enter Value
No.2:");
scanf("%d",&num2);
ans=num1+num2;
printf("\n The addition of No.1
and No.2 is:%d",ans);
getch();
}
Output
Example :
Enter
Value No.1:25
Enter
Value No.2:25
The
addition of No.1 and No.2 is :50
Q.
Write a program to calculate the area of circle.
Ans:
#include
#include<conio.h>
#define
PI 3.14
void
main()
{
int r;
float ans;
clrscr();
printf("\n Enter
Radiance(r):");
scanf("%d",&r);
ans=PI*r*r;
printf("\n The area of CIRCLE
is :%.2f",ans);
getch();
}
Output
Example:
Enter
Radiance(r):5
The
area of CIRCLE is:78.50
Q. Write a
program to calculate months and days on given days,
Ans:
#include
#include<conio.h>
void main()
{
int mon;
int day;
clrscr();
printf("\n Enter Days:");
scanf("%d",&day);
mon=day/30;
day=day%30;
printf("\n
Months:%d",mon);
printf("\n Day:%d",day);
getch();
}
Example
Output:
Enter
Days:360
Months:12
Day:0
Q.
Write a program to calculate simple interest.
Ans:
#include
#include<conio.h>
void
main()
{
long int p,n;
float i,r;
clrscr();
printf("\n Enter the Present
valve(p):");
scanf("%ld",&p);
printf("\n Enter the Rate
value(r):");
scanf("%f",&r);
printf("\n Enter the Number of
Year(n):");
scanf("%ld",&n);
i=p*r*n/100;
printf("\n The Intrest is
%.2f",i);
getch();
}
Example
output:
Enter
the present value(p):1000
Enter
the Rate value(r):10
Enter
the Number of Year(n):2
The
interest is 200.00
Q. Write a
program to calculate total and percentage of given marks.
Ans:
#include
#include<conio.h>
void main()
{
int
sub1,sub2,sub3,sub4,sub5,sub6,sub7,total;
float per;
clrscr();
printf("\n Science :");
scanf("%d",&sub1);
printf("\n Maths :");
scanf("%d",&sub2);
printf("\n Guj. :");
scanf("%d",&sub3);
printf("\n Hindi :");
scanf("%d",&sub4);
printf("\n English :");
scanf("%d",&sub5);
printf("\n Sanskrit:");
scanf("%d",&sub6);
printf("\n P.T :");
scanf("%d",&sub7);
total=sub1+sub2+sub3+sub4+sub5+sub6+sub7;
per=total/7;
printf("\n Science
:%d",sub1);
printf("\n Maths :%d",sub2);
printf("\n
Gujarati:%d",sub3);
printf("\n Hindi :%d",sub4);
printf("\n English
:%d",sub5);
printf("\n
Sanskrit:%d",sub6);
printf("\n P.T :%d",sub7);
printf("\n\n Total :%d",total);
printf("\n\n
Percentage:%.2f",per);
getch();
}
Output
Example:
Science :75
Maths :92
Guj. :72
Hindi :70
English :85
Sanskrit :82
P.T :83
Total :559
Percentage :79.85
Q.
Write a program to find that the given number is ODD or EVEN.
(Using
if Condition)
Ans:
#include
#include<conio.h>
void
main()
{
int num,ans;
clrscr();
printf("\n Enter
Number:");
scanf("%d",&num);
ans=num%2;
if(ans==0)
{
printf("\n The
number %d is EVEN",num);
}
else
{
printf("\n The
number %d is ODD",num);
}
getch();
}
Example
Output:
Enter
Number:5
The
number 5 is ODD
[OR]
Enter
Number:6
The
number 6 is EVEN
Q.
Write a program to find that the given number is POSITIVE or NEGATIVE.
Ans:
#include
#include<conio.h>
void
main()
{
int num;
clrscr();
printf("\n Enter
Number:");
scanf("%d",&num);
if(num<0 span="">0>
{
printf("\n The
number %d is NEGATIVE",num);
}
else
{
printf("\n The
number %d is POSITIVE",num);
}
getch();
}
Example
Output:
Enter
Number:10
The
number 10 is POSITIVE
[OR]
Enter
Number:-5
The
number -5 is NEGATIVE
Q.
Write a program to made simple calculator that performs simple calculation.
Ans:
#include
#include<conio.h>
void
main()
{
int a,b;
int add,sub,mul,dvd,mod;
clrscr();
printf("\n Enter Value
1:");
scanf("%d",&a);
printf("\n Enter Value
2:");
scanf("%d",&b);
add=a+b;
sub=a-b;
mul=a*b;
dvd=a/b;
mod=a%b;
printf("\n The Addition of
Values is:%d",add);
printf("\n The Substraction of
Values is:%d",sub);
printf("\n The Multiplication
of Values is:%d",mul);
printf("\n The Division of the
Values is:%d",dvd);
printf("\n The Remainder of the
Values is:%d",mod);
getch();
}
Example
Output:
Enter
Value 1:10
Enter
Value 2:5
The
Addition of Values is:15
The
Substraction of Values is:5
The
Multiplication of Values is:50
The
Division of Values is:2
The
Remainder of Values is:0
Q. Write a
program to find the area of TRIANGLE.
Ans:
#include
#include<conio.h>
void main()
{
float pi=3.14,ans;
int r,h;
clrscr();
printf("\n Enter
Radiance[r]:");
scanf("%d",&r);
printf("\n Enter Height[h]:");
scanf("%d",&h);
ans=pi*r*r*h;
printf("\n The area of Triangle
is:%.2f",ans);
getch();
}
Output
Example:
Enter
Radiance[r]:5
Enter
Height[h]:5
The area of
TRIANGLE is:392.50
Q. Write a
program to find the square of given number which must be less than 10.
(Using short
hand assignment operator)
Ans:
#include
#include<conio.h>
#define N 10
void main()
{
int a,b;
clrscr();
printf("\n Enter Value:");
scanf("%d",&a);
if(a
{
a*=a;
printf("\n Square
is:%d",a);
}
else
{
printf("\n Please
enter value less than 10");
}
getch();
}
Example
Output:
Enter Value:5
Square is:25
[Or]
Enter
Value:14
Please enter
value less than 10
Q.
Write a program to find the greater value. (Using conditional operator)
Ans:
#include
#include<conio.h>
void
main()
{
int a,b,x;
clrscr();
printf("\n Enter Value:");
scanf("%d",&a);
printf("\n Enter Value:");
scanf("%d",&b);
x=(a>b)?a:b;
printf("\n The greater value
is:%d",x);
getch();
}
Example
Output
Enter
Value:5
Enter
Value:8
The
greater value is:8
Q. Write a
program to calculate DA.
Ans:
#include
#include<conio.h>
void main()
{
float age,salary;
float ans;
clrscr();
printf("\n Enter Age:");
scanf("%f",&age);
printf("\n Enter
Salary:");
scanf("%f",&salary);
if(age>55 &&
salary<10000 span="">10000>
{
ans=salary*20/100;
printf("\n
Da:%.2f",ans);
}
else
{
ans=salary*25/100;
printf("\n
Da:%.2f",ans);
}
getch();
}
Example
Output
Enter Age:50
Enter
Salary:10000
Da:2500.00
Q. Write a
program to find the given year is LEAP YEAR or NOT.
Ans
#include
#include<conio.h>
void main()
{
int yr,ans;
clrscr();
printf("\n Enter year:");
scanf("%d",&yr);
ans=yr%4;
if(ans==0)
{
printf("\n %d is
Leap Year",yr);
}
else
{
printf("\n %d is
Not Leap Year",yr);
}
getch();
}
Example
Output:
Enter
year:2000
2000 is Leap
Year.
Q.
Write a program to find percentage and grade using If….Else ladder.
Ans
#include
#include<conio.h>
void
main()
{
int
sub1,sub2,sub3,sub4,sub5,sub6,sub7,total;
float per;
clrscr();
printf("\n Science :");
scanf("%d",&sub1);
printf("\n Maths :");
scanf("%d",&sub2);
printf("\n Guj. :");
scanf("%d",&sub3);
printf("\n Hindi :");
scanf("%d",&sub4);
printf("\n English :");
scanf("%d",&sub5);
printf("\n Sanskrit:");
scanf("%d",&sub6);
printf("\n P.T :");
scanf("%d",&sub7);
total=sub1+sub2+sub3+sub4+sub5+sub6+sub7;
per=total/7;
printf("\n Science
:%d",sub1);
printf("\n Maths :%d",sub2);
printf("\n
Gujarati:%d",sub3);
printf("\n Hindi :%d",sub4);
printf("\n English
:%d",sub5);
printf("\n
Sanskrit:%d",sub6);
printf("\n P.T :%d",sub7);
printf("\n\n Total :%d",total);
printf("\n\n
Percentage:%.2f",per);
if(per>=70)
{
printf("\n
Distiction");
}
else
if(per>=60)
{
printf("\n First
Class");
}
else
if(per>=45)
{
printf("\n Second
Class");
}
else
{
printf("\n Pass
Class");
}
getch();
}
Example
Output
Science
: 50
Maths : 50
Gujarati:50
Hindi :50
English
50
Sanskrit50
P.T :50
Total :350
Percentage:50
Second
Class
Q.
Write a program to find Maximum value from given three number.
Ans
#include
#include<conio.h>
void
main()
{
int a,b,c;
clrscr();
printf("\n Enter number A
:");
scanf("%d",&a);
printf("\n Enter number B
:");
scanf("%d",&b);
printf("\n Enter number C
:");
scanf("%d",&c);
if(a>b)
{
if(a>c)
{
printf("\n
Value of A is Max (%d)",a);
}
else
{
printf("\n
Value of C is Max (%d)",b);
}
}
else
{
if(c>b)
{
printf("\n
Value of C is Max (%d)",c);
}
else
{
printf("\n
Value of B is Max (%d)",b);
}
}
getch();
}
Example
output
Enter
number A:5
Enter
number B:10
Enter
number C:20
Value
of C is Max (20)
Q. Write a
program to find the SQRT of given number using GOTO.
Ans
#include
#include<conio.h>
#include
void main()
{
int x,y;
re:
clrscr();
printf("\n Enter Value:");
scanf("%d",&x);
if(x<0 span="">0>
goto re;
y=sqrt(x);
printf("\n SQRT of %d is
%d",x,y);
getch();
}
Example
Output
Enter Value:4
SQRT of 4 is
2
Q. Write a
program to display Railway times. Using Switch Condition.
Ans
#include
#include<conio.h>
void main()
{
char t;
clrscr();
printf("\n Choose from
following Choice you want");
printf("\n\n Delhi
Mail...........:D");
printf("\n\n Gujarat
Queen........:G");
printf("\n\n Sabarmati
Express....:S");
printf("\n\n Rajdhani
Express.....:R");
printf("\n\n Enter
Choice:");
scanf("%c",&t);
switch(t)
{
case'd':
printf("\n
The time of Delhi Mail is 9:30 AM");
break;
case'g':
printf("\n
The time of Gujarat Queen is 10:00 AM");
break;
case's':
printf("\n
The time of Sabarmati Express is 12:00 NooN");
break;
case'r':
printf("\n
The time of Rajdhani Express is 3:00 PM");
break;
default:
printf("\n
Please Enter Proper Choice");
}
getch();
}
Example
output
The time of
Delhi Mail is 9:30 AM
The time of
Gujarat Queen is 10:00 AM
The time of
Sabarmati Express is 12:00 NooN
The time of
Rajdhani Express is 3:00 PM
Enter Choice:
g
The time of
Gujarat Queen is 10:00 AM
Q.
Write a program to print 1 to 10 using while loop.
Ans
#include
#include<conio.h>
void
main()
{
int x;
clrscr();
x=1;
while(x<=10)
{
printf("\n
%d",x);
x++;
}
getch();
}
Example
Output
1
2
3
4
5
6
7
8
9
10
Q.
Write a program to display given output.
Ans
#include
#include<conio.h>
void
main()
{
int x,y,z;
clrscr();
printf("\n Enter Value:");
scanf("%d",&z);
for(x=0;x<=z;x++)
{
for(y=0;y<=x;y++)
{
printf("%d",x);
}
printf("\n");
}
getch();
}
Example
Output.
1
22
333
4444
Q.
Write a program to display output.
Ans
#include
#include<conio.h>
void
main()
{
int x,y,z;
clrscr();
printf("\n Enter Value:");
scanf("%d",&z);
for(x=0;x<=z;x++)
{
for(y=0;y<=x;y++)
{
printf("%d",y);
}
printf("\n");
}
getch();
}
Example
Output
1
12
123
1234
12345
Q.
Write a program to display given output.
Ans
#include
#include<conio.h>
void
main()
{
int x,y;
clrscr();
printf("\n Enter value:");
scanf("%d",&x);
for(x=0;x>=1;x--)
{
for(y=1;y<=x;y++)
{
printf("%d",y);
}
printf("\n");
}
getch();
}
Example
Output
12345
1234
123
12
1
Q.
Write a program to display given output.
Ans
#include
#include<conio.h>
void
main()
{
int x,y,z;
clrscr();
printf("\n Enter Value:");
scanf("%d",&z);
for(x=0;x<=z;x++)
{
for(y=0;y<=x;y++)
{
printf("*");
}
printf("\n");
}
getch();
}
Example
Output
*
**
***
****
*****
Q.
Write a program to find the sum of entered digits.
Ans.
#include
#include<conio.h>
void
main()
{
int no,i,sum=0;
clrscr();
printf("\n Enter value:");
scanf("%d",&no);
while(no>0)
{
sum=sum+no%10;
no=no/10;
}
printf("\n The sum of digit
is:%d",sum);
getch();
}
Example
Output
Enter
value:56
The
sum of digit is:11.
Q. Write a
program to find the sum of first 100 natural no.
Ans
#include
#include<conio.h>
void main()
{
int no,i,sum=0;
clrscr();
for(i=1;i<=100;i++)
{
sum=sum+i;
}
printf("Sum of 100
is:%d",sum);
getch();
}
Example
Output
Sum of 100
is:5050.
Q. Write a
program to find the sum of first 100 odd no and even no.
Ans.
#include
#include<conio.h>
void main()
{
int i,eve=0,odd=0;
clrscr();
for(i=1;i<=200;i++)
if(i%2==0)
{
eve=eve+i;
}
printf("\n Sum of first 100
even number is:%d",eve);
for(i=1;i<=200;i+=2)
{
odd=odd+i;
}
printf("\n The sum of first 100
odd number is:%d",odd);
getch();
}
Example
output
Sum of first
100 even number is:10100
Sum of first
100 odd number is:10000
Q. Write a
program to display 25 fibonacci numbers.
Ans
#include
#include<conio.h>
void main()
{
long int a=0,b=1,sum=0,cont=0;
clrscr();
printf("0");
while(cont<=24)
{
sum=a+b;
a=b;
b=sum;
printf("\n
%ld",sum);
cont++;
}
getch();
}
Example
Output
1
2
3
5
8
13
21
34
55
89
144
233
377
610
987
1597
2584
4181
6765
10946
17711
28657
46368
75025
121393
Q. W.a.p find
the area and volume of sphere
Ans
#include
#include<conio.h>
#define PI
3.14
void main()
{
float
a,v,r;
clrscr();
printf("Enter
value for radius:-");
scanf("%f",&r);
a=4*PI*r*r;
printf("\n area of
sphere is%f",a);
v=4/3*PI*r*r*r;
printf("\n volume of
shere is %f",v);
getch();
}
Example
Output
Enter value
for radius:10
Area of
sphere :1256.0000
Volume of
sphere: 3140.0000
Q. Write a
program to display given out put.
Ans
#include
#include<conio.h>
void main()
{
int c,d;
char
string[]="CPROGRAMMING";
clrscr();
printf("\n\n");
printf("------------\n");
for(c=0;c<=11;c++)
{
d=c+1;
printf("|%-12.*s|\n",d,string);
}
printf("|------------|\n");
for(c=11;c>=0;c--)
{
d=c+1;
printf("|%-12.*s|\n",d,string);
}
printf("------------\n");
getch();
}
Example
output
C
Cp
Cpro
Cprog
Cprogr
Cprogra
……
Cprogramming
Cprogrammin
Cprogrammi
Cprogramm
……….
C
Q. Write a
program to convert the value of centigrade to Fahrenheit.
Ans
#include
#include<conio.h>
void main()
{
float c,f;
clrscr();
printf("\n Enter
Value(Centigrade):");
scanf("%f",&c);
f=(c*1.8)+32;
printf("\n Centigrade:%.2f ||
Fahrenheit:%.2f",c,f);
getch();
}
Example
Output
Enter
Value(Centigrade):35
Centigrade:35
|| Fahrenheit:95.00
Q
Write a program to find the factorial of accepted no.
Ans
#include
#include<conio.h>
void
main()
{
int n,fact=1;
clrscr();
printf("\n Enter value:");
scanf("%d",&n);
while(n>=1)
{
fact=fact*n;
n--;
}
printf("\n Factorial
is:%d",fact);
getch();
}
Example
output
Enter
value:5
Factorial
is 120
Q. Write a
program to print accepted number in reverse order.
Ans
#include
#include<conio.h>
void main()
{
long int a,rem=0,rev=0;
clrscr();
printf("\n Enter value:");
scanf("%ld",&a);
while(a>0)
{
rem=a%10;
a=a/10;
rev=rem+rev*10;
}
printf("\n The reverse
is:%ld",rev);
getch();
}
Example
Output
Enter value:
105
The reverse
is:501
Q. write a
program to find first 100 prime number.
Ans
#include
#include<conio.h>
void main()
{
int i,j,f=0,k=0,count=1;
clrscr();
while(count<=100)
{
f=0;
for(i=1;i<=k;i++)
{
for(j=2;j<=k/2;j++)
{
if(k%j==0)
{
f=1;
break;
}
}
}
if(f==0)
{
printf("\t%d",k);
count++;
}
k++;
}
getch();
}
Example
Output
1,2,3,5,7,11,13………………………………………..491,499,503,521,523.
Q.
Write a program to find whether the acceptde string number is palindrome or
not:
Ans
#include
#include<conio.h>
void
main()
{
int rem=0,rev=0,no,a;
clrscr();
printf("Enetr value of no:=");
scanf("%d",&no);
a=no;
while(no>0)
{
rem=no%10;
rev=rev*10+rem;
no=no/10;
}
if(rev==a)
printf("\n The number is
palindrom:=%d",rev);
else
printf("\n The number is not
palindrom:=%d",rev);
getch();
}
Example
Output:
Enter
value of no:505
This
number is palindrome.
Q. Write
program write a program to find x1+x2+x3+x4+......xn:
Ans
#include<conio.h>
#include
#include
void main()
{
int x,no,sum=0,i;
clrscr();
printf("Enter the no:=");
scanf("%d",&no);
printf("Give value of x:=");
scanf("%d",&x);
for(i=1;i<=no;i++)
{
sum=sum+pow(x,i);
}
printf("sum=%d",sum);
getch();
}
Example
Output
Enter the
no:= 3
Give the
value of x:=2
12.00000
Q Write a
program to find 1+1/2+1/3+1/4+....1/n.:
Ans
#include
#include<conio.h>
void main()
{
int i,no,j=1;
float sum=0;
clrscr();
printf("Enter the no:=");
scanf("%d",&no);
for(i=1;i<=no;i++)
{
sum=sum+(float)j/i;
}
printf("%f",sum);
getch();
}
Example
output
Enter the no:
5
2.28334
Q write a C
program to find 1+1/2!+1/3!+1/4!+.....1/n!..:
Ans
#include
#include<conio.h>
void main()
{
int i,j,no,f;
float sum=0;
clrscr();
printf("Enter the no:=");
scanf("%d",&no);
for(i=1;i<=no;i++)
{
f=1;
for(j=1;j<=i;j++)
{
f=f*j;
}
sum=sum+ 1.0/f;
}
printf("sum=%f",sum);
getch();
}
Example
Output
Enter the no:
5
1.716667
Q.Write a
program to convert decimal to binary:
Ans
#include
#include<conio.h>
void main()
{
int j,i=0,rem=0,ar[50],no;
clrscr();
printf("Enter the decimalno:=");
scanf("%d",&no);
while(no>0)
{
rem=no%2;
no=no/2;
ar[i]=rem;
i++;
}
for(j=i-1;j>=0;j--)
printf("%d",ar[j]);
getch();
}
Example
output
Enter the
decimalno: = 10
1010
First Step:
no=10
rem=0
no=5
ar[0]=0
Second Step (no=5)
rem=1
no=2
ar[1]=1
Third Step
(no=2)
rem=0
no=1
ar[2]=0
Four step
(no=1)
rem=1
no=0
ar[3]=1
now arr[3]={0,1,0,1}
Q write a C
program to convert decimal to octal:
Ans
#include
#include<conio.h>
void main()
{
int j,i=0,rem=0,ar[50],no;
clrscr();
printf("Enter the decimalno:=");
scanf("%d",&no);
while(no>0)
{
rem=no%8;
no=no/8;
ar[i]=rem;
i++;
}
for(j=i-1;j>=0;j--)
printf("%d",ar[j]);
getch();
}
Example
Output
Enter the
decimalno:=34
42
First Step
rem=2
no=4
ar[0]=2
Second
step(no=4 )
rem=4
no=0
ar[1]=4
ar[1]={2,4}
Q. write a C
program to convert decimal to hexa:
#include
#include<conio.h>
#include<ctype.h>
void main()
{
int i=0,j,no,rem=0;
char ar[50];
clrscr();
printf("Enter the decimalno:=");
scanf("%d",&no);
while(no>0)
{
rem=no%16;
no=no/16;
if(rem==10)
ar[i]='A';
else if(rem==11)
ar[i]='B';
else
if(rem==12)
ar[i]='C';
else
if(rem==13)
ar[i]='D';
else if(rem==14)
ar[i]='E';
else if(rem==15)
ar[i]='F';
else
ar[i]=rem;
i++;
}
for(j=i-1;j>=0;j--)
{
if(isalpha(ar[j])!=0)
printf("%c",ar[j]);
else
printf("%d",ar[j]);
}
getch();
}
Example
output
Enter the no:
29
1D
First Step
no=29
rem=13
no=1
ar[0]=D
Second Step
no=1
rem=1
no=0
ar[1]=1
Q. Convert given line into upper case or lower
case character as user want.Use switch statement for the
#include
#include<conio.h>
#include<ctype.h>
#include
#include
void main()
{
int i,len;
char str[50],ch;
clrscr();
printf("Give any alphabatic
string:-");
scanf("%s",&str);
printf("Give u for upper and l for
lower:-");
scanf("%s",&ch);
len=strlen(str);
switch(ch)
{
case'u':
case'U':for(i=0;i<len;i++)
{
str[i]=toupper(str[i]);
}
printf("%s",str);
break;
case'l':
case'L':for(i=0;i<len;i++)
{
str[i]=tolower(str[i]);
}
printf("%s",str);
break;
default:
printf("Invalid entry");
}
getch();
}
Q.
Check accepted integer is prime number or no:
Ans
#include
#include<conio.h>
void
main()
{
int i,k=0,n;
clrscr();
printf("Enter the no:=");
scanf("%d",&n);
for(i=2;i<=n/2;i++)
{
if(n%i==0)
k=1;
}
if(k==0)
printf("The number is prime");
else
printf("The number is not
prime");
getch();
}
Example
output
Enter
the no:6
The
number is not prime
Q. wrie a
program to convert accepted integer into word for example 55 = fifty five.
Ans
void
one(int);
void
two(int);
void
two2(int);
#include
#include<conio.h>
void main()
{
long int n,no,num[81],i,j,k;
clrscr();
printf ("enter the no:");
scanf ("%ld",&n);
if(n==0)
printf("zero");
no=n;
i=0;
while(n>0)
{
num[i]=n%10;
n=n/10;
i++;
}
i=i-1;
if(i==0)
one(no);
if(i==1)
two(no);
if(i==2)
{
k=no/100;
one(k);
printf("hundred
");
k=no%100;
two(k);
}
if(i==3)
{
k=no/1000;
one(k);
printf("thousand ");
k=no/100;
k=k%10;
if(k!=0)
{
one(k);
printf("hundred ");
}
k=no%100;
two(k);
}
if(i==4)
{
k=no/1000;
two(k);
printf("thousand ");
k=no/100;
k=k%10;
if(k!=0)
{
one(k);
printf("hundred ");
}
k=no%100;
two(k);
}
if(i==5)
{
k=no/100000;
one(k);
printf("lack ");
k=no%100000;
k=k/1000;
two(k);
printf("thousand ");
k=no/100;
k=k%10;
if(k!=0)
{
one(k);
printf("hundred ");
}
k=no%100;
two(k);
}
getch();
}
void one (int
n)
{
switch (n)
{
case 0:
break;
case 1:
printf ("one");
break;
case 2:
printf ("two");
break;
case 3:
printf ("three");
break;
case 4:
printf ("four");
break;
case 5:
printf ("five");
break;
case 6:
printf ("six");
break;
case 7:
printf ("seven");
break;
case 8:
printf ("eight");
break;
case 9:
printf ("nine");
break;
}
}
void two(int n)
{
switch (n)
{
case 10:
printf ("ten");
break;
case 11:
printf ("eleven");
break;
case 12:
printf ("twelve");
break;
case 13:
printf ("thirteen");
break;
case 14:
printf ("fourteen");
break;
case 15:
printf ("fifteen");
break;
case 16:
printf ("sixteen");
break;
case 17:
printf ("seventeen");
break;
case 18:
printf ("eighteen");
break;
case 19:
printf ("nineteen");
break;
default:
two2(n);
break;
}
}
void two2(int na)
{
int n,n1;
n=na/10;
n1=na%10;
switch (n)
{
case 2:
printf ("twenty");
break;
case 3:
printf ("thrity");
break;
case 4:
printf ("fourty");
break;
case 5:
printf ("fifty");
break;
case 6:
printf ("sixty");
break;
case 7:
printf ("seventy");
break;
case 8:
printf ("eighty");
break;
case 9:
printf ("ninty");
break;
}
one(n1);
}
Example
output
Enter number:
55
Fifty five.
Q. Write a
program to find frequency of entered number.
#include
#include<conio.h>
#define max
10
void main()
{
int str1[max],str2[max];
int fre[max],k=0,j,i,fr,f;
clrscr();
for(i=0;i<10 i="" span="">10>
{
printf("Enter the no:-");
scanf("%d",& str1[i]);
}
for(i=0;i<10 i="" span="">10>
{
f=0;
for(j=0;j
{
if(str2[j]==str1[i])
{
f=1;
break;
}
}
if(f==0)
{
fr=0;
str1[k]=str1[i];
fr++;
for(j=i+1;j<10 j="" span="">10>
{
if(str1[j]==str2[k])
{
fr++;
}
fre[k]=fr;
k++;
}
printf("Frequency List");
for(j=0;j
printf("%d Nos of time%d
\n",str2[j],fre[j]);
}
}
getch();
}
Enter the no:
2
Enter the
no:3
Enter the
no:1
Enter the
no:2
Enter the
no:3
…………….
Frequency
list
2 nos times 2
3 nos of time 1
Q. write a
program accept different array merge it and make it sort in ascending order.
Ans
#include
#include<conio.h>
void main()
{
int a[10],b[20],c[20],a1=0,b1,c1,n,m,i,j,t;
clrscr();
printf("Give size of first array:");
scanf("%d",&m);
printf("Give size of second
array:");
scanf("%d",&n);
for(i=0;i
{
printf("Give no:");
scanf("%d",&a[i]);
}
for(i=0;i
{
printf("Give no:");
scanf("%d",&b[i]);
}
for(i=0;i
{
c[a1]=a[i];
a1++;
}
for(i=0;i
{
c[a1]=b[i];
a1++;
}
for(i=0;i
{
for(j=i+1;j
{
if(c[i]>c[j])
{
t=c[i];
c[i]=c[j];
c[j]=t;
}
}
}
for(i=0;i
printf("%d\n",c[i]);
getch();
}
Q Write a
gram for finding no of word,character and blank spaces.
Ans
#include
#include<conio.h>
#include
#include<ctype.h>
void main()
{
clrscr();
char str[50],c;
int i,j,len,sp=0,w=0;
printf("Give any string:");
gets(str);
len=strlen(str);
if(str[0]==' ')
w=0;
else
w=1;
for(i=0;i<len;i++)
{
if(isspace(str[i])!=0)
{
++sp;
}
if(isspace(str[i])!=0&&isspace(str[i+1])==0)
{
++w;
}
}
printf("No of Spaces:%d\n",sp);
printf("No of Words:%d\n",w);
printf("No of
characters:%d\n",len-sp);
getch();
Example
output
Give any
string: h i
No of space:
1
No of word: 2
No of
character: 2
Q Write Program for finding Median of given no.
Ans
#include
#include<conio.h>
void main()
{
clrscr();
int str[50];
int i,j,len,t;
float m;
printf("Give Size of Array:");
scanf("%d",&len);
for(i=0;i<len;i++)
{
printf("Give No:");
scanf("%d",&str[i]);
}
for(i=0;i<len;i++)
{
for(j=i+1;j<len;j++)
{
if(str[i]>str[j])
{
t=str[i];
str[i]=str[j];
str[j]=t;
}
}
}
for(i=0;i<len;i++)
{
printf("%d ",str[i]);
}
if(len%2==1)
{
t=len/2;
printf("\nMedian:%d ",str[t]);
}
else
{
t=len/2;
m=(str[t]+str[t-1])/2.0;
printf("\nMedian:%f ",m);
}
getch();
}
Example
output
Give no:1
Give no:2
………..
Give no:6 Median:3.500000
Q. Write a
Program for arranging characters of a
string in ascending.
#include
#include<conio.h>
#include
void main()
{
clrscr();
char str[50],c;
int i,j,len;
printf("Give any string:");
scanf("%s",str);
len=strlen(str);
for(i=0;i<len;i++)
{
for(j=0;j<len;j++)
{
if(str[i]<str[j])
{
c=str[i];
str[i]=str[j];
str[j]=c;
}
}
}
printf("%s",str);
getch();
}
Example
output
Give any
string: c d e k a b
a b c d e k
Example :cab
str[0]c<str[0]c condition false
str[0]c<str[1]a Conditon false
str[0]c<str[2]b conditioin false
str[1]a<str[0]c condition True
varc=a;
str[1]=str[0]c;
str[0]=varc str[0]=a,str[1]=c; acb
str[1]c<str[2]b Conditon false
str[2]c<str[0]a conditioin false
str[2]c<str[1]c False
str[2]c<str[2]b False
str[3]b<str[0]a Conditon false
str[3]b<str[1]c Condition True
varc=b
str[3]=c
str[1]=b abc
Q Write
aProgram to find the memory location.
Ans
#include
#include<conio.h>
#include
void main()
{
int i,*p;
clrscr();
p=&i;
printf("Give Value of i:");
scanf("%d",&i);
printf("Value %d is store at %u memory
location.",i,p);
getch();
}
Give any
value of i: 5
Value 5 is
stored at 65524 memory location.
Q
Write a program to display given output.
Ans
#include
#include<conio.h>
void
main()
{
int i,j,no,k;
clrscr();
printf("Enter the no:=");
scanf("%d",&no);
for(i=1;i<=no;i++)
{
k=i;
for(j=1;j<=i;j++)
{
printf("%d",k);
k++;
}
printf("\n");
}
getch();
}
Example
output
Enter
the number: 5
1
23
345
4567
56789
Q. Write a
program to display output.
Ans
#include
#include<conio.h>
void main()
{
int i,j,p,no;
clrscr();
printf("\n Enter the no:=");
scanf("%d",&no);
for(i=1;i<=no;i++)
{
p=i-1;
for(j=1;j<=2*i-1;j++)
{
if(j>=i+1)
p--;
else
p++;
printf("%d",p);
}
printf("\n");
}
getch();
}
Example
output
1
232
34543
4567654
567898765
Q. Write a
program to display given output.
Ans
#include
#include<conio.h>
void main()
{
int i,j,p,no;
clrscr();
printf("Enter the no:=");
scanf("%d",&no);
for(i=1;i<=no;i++)
{
p=0;
for(j=1;j<=2*i-1;j++)
{
if(j>=i+1)
p--;
else
p++;
printf("%d",p);
}
printf("\n");
}
getch();
}
Example
output
Enter the
no:5
1
121
12311
123421
12345321
Q.
Write a program to display given output
Ans
#include
#include<conio.h>
void
main()
{
int i,j,a=1;
clrscr();
for(i=1;i<5 i="" span="">5>
{
for(j=1;j<=i;j++)
{
printf("%d",a);
a++;
}
printf("\n");
}
getch();
}
Example
output
1
23
456
78910
Q.
write a program to display given output.
Ans
#include
#include<conio.h>
void
main()
{
int i,j,a=1,no;
clrscr();
printf("\n Enter the no:=");
scanf("%d",&no);
for(i=1;i<=no;i++)
{
for(j=1;j<=i;j++)
{
printf("%d",a);
a++;
}
printf("\n");
}
getch();
}
Example
Output
Enter
the no.:5
1
23
456
78910
11
12 13 14
Q. Write a
program to display given output on center of the screen.
Ans
#include
#include<conio.h>
void main()
{
int i,j,no,s;
clrscr();
printf("Enter the no:=");
scanf("%d",&no);
for(i=0;i<=no;i++)
{
for(s=20;s>=i;s--)
{
printf("
");
}
for(j=1;j<=i;j++)
{
printf(" %d ",i);
}
printf("\n");
}
getch();
}
Example
Output
1
22
333
4444
55555
Q.
Write a program to display given output
Ans
#include
#include<conio.h>
void
main()
{
int i,j,no;
clrscr();
printf("Enter the no:=");
scanf("%d",&no);
for(i=1;i<=no;i++)
{
for(j=1;j<=i;j++)
{
printf("%d",j%2);
}
printf("\n");
}
getch();
}
Example
Output
Enter
the no: 4
1
10
101
1010
Q. Write a
program to display given output.
Ans
#include
#include<conio.h>
void main()
{
int i,j,k,n;
clrscr();
printf("\n enter the no:-");
scanf("%d",&n);
for(i=1;i
{
k=i;
for(j=1;j<=i;j++)
{
if(k%2==0)
printf("0");
else
printf("1");
k++;
}
printf("\n");
}
getch();
}
1
01
101
0101
10101
Q write a
program to display given output.
Ans
#include
#include<conio.h>
void main()
{
int i,j,k,no;
clrscr();
printf("Enter the no:=");
scanf("%d",&no);
for(i=1;i<=no;i++)
{
k=i;
for(j=1;j<=i;j++)
{
if(k%2==0)
printf("0");
else
printf("1");
k++;
}
printf("\n");
}
getch();
}
Enter the
no:=4
1
01
001
0101
Q. Print the
details of three students using structure.
Ans:
#include
#include<conio.h>
#include
#define l 2
void main()
{
int i,j;
struct stud
{
int rno;
char nm[50];
char add[50];
char ct[50];
int ph;
}s[l];
clrscr();
for(i=0;i
{
printf("Give Roll No:");
scanf("%d",&s[i].rno);
printf("Give Name:");
scanf("%s",s[i].nm);
printf("Give Address:");
scanf("%s",s[i].add);
printf("Give City:");
scanf("%s",s[i].ct);
printf("Give Phone No:");
scanf("%d",&s[i].ph);
}
for(i=0;i
{
printf("Roll No:%d\n",s[i].rno);
printf("Name:%s\n",s[i].nm);
printf("Address:%s\n",s[i].add);
printf("City:%s\n",s[i].ct);
printf("Phone No:%d\n",s[i].ph);
}
getch();
}
Q. Write a
program for sum of diagonal and anti-digonal of matrix.
Ans:
#include
#include<conio.h>
void main()
{
clrscr();
int i,j,n,m,a[10][10],sum=0;
printf("Enter No of
Rows:");
scanf("%d",&n);
printf("Enter Value of
columns:");
scanf("%d",&m);
if(m!=n)
printf("Sum of diagonal not possible");
else
{
for(i=0;i
{
for(j=0;j
{
printf("Give value of
a[%d][%d]:",i,j);
scanf("%d",&a[i][j]);
}
}
printf("Matrix\n");
for(i=0;i
{
for(j=0;j
{
printf("%d",a[i][j]);
}
printf("\n");
}
for(i=0;i
{
sum=sum+a[i][i];
}
printf("Sum of Diagonal=%d",sum);
}
sum=0;
j=m-1;
for(i=0;i
{
sum=sum+a[i][j];
j--;
}
printf("\n Sum of anti-diagonal=%d",sum);
getch();
}
Q Deine a
structure called cricket with following information.
Ans:
#include
#include<conio.h>
#include
#define l 3
#include<stdlib.h>
void main()
{
char ch[50]="";
int i,j;
struct crt
{
int
arg;
char nm[50];
char tnm[50];
}s[l];
clrscr();
for(i=0;i
{
printf("Give Name:");
scanf("%s",s[i].nm);
printf("Give Name of Team:");
scanf("%s",s[i].tnm);
printf("Give Average:");
scanf("%d",&s[i].arg);
}
for(i=0;i
{
if(strcmp(s[i].tnm,ch)!=0)
{
strcpy(ch,s[i].tnm);
printf("%s team list\n",ch);
for(j=i;j
{
if(strcmp(s[j].tnm,ch)==0)
{
printf("%s\n",s[j].nm);
printf("%d\n",s[j].arg);
}
}
}
}
getch();
}
Q. Write a
program to sort 10 number and sort it using pointer.
Ans:
#include
#include<conio.h>
#include
void main()
{
int i,*p,no[4],t,*j,*y;
clrscr();
// p=y=no;
for(i=1;i<=4;i++)
{
printf("Give Value of %d
number:",i);
scanf("%d",&no[i-1]);
}
for(p=no;p
{
j=p++;
for(;j<=p+3;)
{
if(*p>*j)
{
t=*p;
*p=*j;
*j=t;
}
j=p++;
}
}
for(i=0;i<4 i="" span="">4>
{
printf("%d\n",no[i]);
}
getch();}
Q Write a
program to find NPR with user define function.
Ans
#include
#include<conio.h>
#define l 5
void
fnpr(int,int);
void
fncr(int,int);
void main()
{
clrscr();
int n,r;
printf("Give Value of N:");
scanf("%d",&n);
printf("GIve Value of R:");
scanf("%d",&r);
if(n-r<1 span="">1>
printf("Calculation Not
Possible.");
else
fnpr(n,r);
fncr(n,r);
getch();
}
void fnpr(int
n1,int r1)
{
int i,j,nf=1,nrf=1;
float f;
for(i=1;i<=n1;i++)
{
nf=nf*i;
}
for(j=1;j<=(n1-r1);j++)
{
nrf=nrf*j;
}
f=nf/nrf;
printf("Result of npr:%f",f);
}
void fncr(int n1,int r1)
{
int i,j,nf=1,nr,rf=1;
float ncr;
for(i=1;i<=n1;i++)
{
nf=nf*i;
}
for(i=1;i<=r1;i++)
{
rf=rf*i;
}
nr=n1-r1;
ncr=nf/rf*nr;
printf("\n result of
ncr:-%f",ncr);
}
Q. Write a
program to swap the two different numbers using UDF using pointer and
functions.
Ans:
#include
#include<conio.h>
void exg(int
*,int *);
void main()
{
clrscr();
int n=1,r=2;
printf("Before Exchange n:%d and
r:%d\n",n,r);
exg(&n,&r);
getch();
}
void exg(int
*p,int *q)
{
int t;
t=*p;
*p=*q;
*q=t;
printf("New value after exchange of n:%d
and r:%d\n",*p,*q);
}
Q. Write a
program to create a text file store some information and print same value from
terminal.
Ans:
#include
#include<conio.h>
void main()
{
FILE *fp;
char c;
clrscr();
fp=fopen("myfile","w");
printf("Type any string and press cny-z
for terminate\n");
while((c=getchar())!=EOF)
{
putc(c,fp);
}
fclose(fp);
fp=fopen("myfile","r");
while((c=getc(fp))!=EOF)
{
printf("%c",c);
}
fclose(fp);
getch();
}
Q Write a
program to create one integer value contained file. From this create two
another files one for odd and one for even.
Ans:
#include
#include<conio.h>
#include
void main()
{
FILE *fp,*ep,*op;
char c;
int i,no;
clrscr();
fp=fopen("ifile","w");
for(i=0;i<5 i="" span="">5>
{
printf("Give number %d:",i+1);
scanf("%d",&no);
putw(no,fp);
}
fclose(fp);
fp=fopen("ifile","r");
ep=fopen("efile","w");
op=fopen("ofile","w");
while((no=getw(fp)!=EOF))
{
if(no%2==0)
putw(no,ep);
else
putw(no,op);
}
fclose(ep);
fclose(op);
fclose(fp);
ep=fopen("efile","r");
printf("Even Number List\n");
while((no=getw(ep)!=EOF))
{
printf("%d\t",no);
}
fclose(ep);
getch();
}
Q. Write a
program to create file and store some information using fprintf() fscanf()
Ans:
#include
#include<conio.h>
#include
void main()
{
FILE *fp;
char nm[50];
int no;
clrscr();
fp=fopen("txt","w");
printf("Give Name and Roll No:");
fscanf(stdin,"%s %d",nm,&no);
fprintf(fp,"%s %d",nm,no);
fclose(fp);
fp=fopen("txt","r");
fscanf(fp,"%s %d",nm,&no);
fprintf(stdout,"%s %d",nm,no);
getch();
}
Q. Write a
program to find a percentage of vowels in accepted text. Using file.
Ans:
#include
#include<conio.h>
#include
void main()
{
FILE *fp;
char c;
clrscr();
fp=fopen("mfile","w");
printf("Give any string and press cnt-z
to terminate.\n");
while((c=getchar())!=EOF)
{
putc(c,fp);
}
fclose(fp);
fp=fopen("mfile","r");
while((c=getc(fp))!=EOF)
{
if(c=='a'||c=='u'||c=='i'||c=='o'||c=='e')
printf("%c ",c);
}
getch();
}
Q Write a
program to work as dos type command using command line arguments.
Ans:
#include
#include<conio.h>
void
main(argc ,argv)
int argc;
char *argv[];
{
FILE *fp;
int i;
int w;
clrscr();
printf(" no of command line argument
are %d\n",argc);
fp=fopen(argv[1],"w");
for(i=2;i<argc;i++)
{
fprintf(fp,"%d",argv);
}
fclose(fp);
fp=fopen(argv[1],"r");
for(i=2;i<argc;i++)
{
fscanf(fp,"%d",&w);
fprintf(stdout,"\n %s",w);
}
fclose(fp);
getch();
}

No comments:
Post a Comment