Sie sind auf Seite 1von 24

1. W.A.P to print the ASCII value of the character entered by the user.

#include<stdio.h>
#include<conio.h>

void main()
{
char a;
int b;
clrscr();
printf(" \n \n enter the character whose ASCII value is to be determined : ");
scanf("%c",&a);
b=a;
printf(" \n \n the ASCII value of the character entered %c is : %d",b);
getch();
}
2. W.A.P to convert temperature in degree into Fahrenheit.
#include<stdio.h>
#include<conio.h>

int main()
{
float cel,faren;
printf("\n enter the temp in degree celcius");
scanf("%f",&cel);
faren=((9.0*cel)/5)+32;
printf("\n the temp in farenhite is : %f",faren);

getch();
return 0;
}

3. W.A.P to convert the number entered in bytes into bits, kilobytes, gigabytes & nibble.

#include<stdio.h>
#include<conio.h>

main()
{
double kilobytes,gigabytes,bytes;
int bits;
printf("\n enter the number of bytes");
scanf("%lf",&bytes);
bits = bytes * 8;
kilobytes = bytes/1024;
gigabytes = kilobytes/1024;
printf("\n number of bits = %d \n number of kilobytes = %lf \n number of gigabytes = %lf
",bits,kilobytes,gigabytes);
getch();
return 0; }
4. W.A.P to find whether the number entered by the user is even or odd.
#include<stdio.h>
#include<conio.h>

void main()
{
int n;
clrscr();
printf(" \n \n Enter the number : ");
scanf("%d",&n);
if((n%2)==0)
{
printf("\n \n The number entered is even");
}
else
printf("\n \n The number entered is odd");
getch();
}

5. W.A.P to find whether the number entered by the user is positive or negative.

#include<stdio.h>
#include<conio.h>

void main()
{
int n;
clrscr();
printf(" \n \n Enter the number : ");
scanf("%d",&n);
if(n<0)
{
printf("\n \n The number entered is negative");
}
else
printf("\n \n The number entered is positive");
getch();
}
6. W.A.P to swap two numbers without using third variable.
#include<stdio.h>
#include<conio.h>

void main()
{
clrscr();
int a,b;
printf("\n \n Enter two numbers two be swapped : ");
scanf("%d %d",&a,&b);
if(a>b)
{
a=a+b;
b=a-b;
a=a-b;
printf("\n \n the numbers after swapping are : %d %d",a,b);
}
else
{ b=b-a;
a=a+b;
b=a-b;
printf("\n \n the numbers after swapping are : %d %d",a,b);
} getch();}
7. W.A.P to find the largest of three numbers entered by the user.

#include<stdio.h>
#include<conio.h>

void main()
{
int a,b,c;
clrscr();
printf("\n enter the three numbers to be compared : ");
scanf("%d %d %d",&a,&b,&c);
if((a>b)&&(a>c))
{
printf(" \n \n a is the largest ");
}
else
{
if((b>c)&&(b>a))
{
printf(" \n \n b is largest " );
}
else
printf("\n \n c is largest " );
}
getch(); }
8. W.A.P to find whether the character entered by the user is a vowel (using switch).
#include<stdio.h>
#include<conio.h>

void main()
{ char ch;
printf("\n enter the character value ");
scanf("%c",&ch);
switch(ch)
{
case 'a':
case 'e':
case 'i':
case 'o':
case 'u': printf("\n character entered is a vowel ");break;
default: printf("\n character entered is not a vowel ");
}

getch();
}

9. W.A.P the program such that it prints digit of a three digit number entered by the user
in words. For example, if the number entered by the user is 123 then ‘one two three’
should be printed as an output.
#include<stdio.h>
#include<conio.h>

main()
{ int num,first,second,third;
printf("\n enter a three digit number ");
scanf("%d",&num);
first=num/100;
third=num%10;
num=num/10;
second=num%10;
switch(first)
{
case 0:printf("\n zero ");break;
case 1:printf("\n one ");break;
case 2:printf("\n two ");break;
case 3:printf("\n three ");break;
case 4:printf("\n four ");break;
case 5:printf("\n five ");break;
case 6:printf("\n six ");break;
case 7:printf("\n seven ");break;
case 8:printf("\n eight ");break;
case 9:printf("\n nine ");break;
default: printf("\n wrong value ");

}
switch(second)
{
case 0:printf("\n zero ");break;
case 1:printf("\n one ");break;
case 2:printf("\n two ");break;
case 3:printf("\n three ");break;
case 4:printf("\n four ");break;
case 5:printf("\n five ");break;
case 6:printf("\n six ");break;
case 7:printf("\n seven ");break;
case 8:printf("\n eight ");break;
case 9:printf("\n nine ");break;
default: printf("\n wrong value ");

}
switch(third)
{
case 0:printf("\n zero ");break;
case 1:printf("\n one ");break;
case 2:printf("\n two ");break;
case 3:printf("\n three ");break;
case 4:printf("\n four ");break;
case 5:printf("\n five ");break;
case 6:printf("\n six ");break;
case 7:printf("\n seven ");break;
case 8:printf("\n eight ");break;
case 9:printf("\n nine ");break;
default: printf("\n wrong value ");

}
getch();
return 0; }
10. W.A.P which reads two integer values VAL1 and VAL2. if VAL1 is less then VAL2,
display the message “UP” else display “down”. If both the values VAL1 and VAL2 are
same then display “equal”. (using switch).

#include<stdio.h>
#include<conio.h>

main()
{ int val1,val2,temp;
printf("\n enter the two values val1 & val2 ");
scanf("%d %d",&val1,&val2);
if(val1==val2)
temp=1;
else
{
if(val1<val2)
temp=2;
else
temp=3;
}
switch(temp)
{

case 1:printf("\n same ");break;


case 2:printf("\n UP ");break;
case 3:printf("\n DOWN ");break;}

getch();
return 0; }

11. W.A.P to that uses puts( ) function to display the following on the screen :
“OBJECT : C”
“ the c compiler is a fatherly old chap”
“who doesn’t nag you with small little details”

#include<stdio.h>
#include<conio.h>

main()
{
puts("OBJECT : C");
puts(" the c compiler is a fatherly old chap");
puts("who doesn't nag you with small little details");

getch();
return 0; }
12. W.A.P that determines in which quadrant an angle lies.

#include<stdio.h>
#include<conio.h>

main()
{ int angle,temp;
printf("\n enter a the value of the angle in degrees");
scanf("%d",&angle);
if(angle>0 && angle<90)

temp=1;
if(angle>90 && angle<180)
temp=2;
if(angle>180 && angle<270)
temp=3;
if(angle>180 && angle<360)
temp=4;
switch(temp)
{

case 1:printf("\n the angle entered lies in first quadrant ");break;


case 2:printf("\n the angle entered lies in second quadrant ");break;
case 3:printf("\n the angle entered lies in third quadrant ");break;
case 4:printf("\n the angle entered lies in fourth quadrant ");break;
default: printf("\n wrong value ");

getch();
return 0; }

13. W.A.P to find to print the table of the number entered by the user.

#include<stdio.h>
#include<conio.h>

main()
{ int num,n,i,table;
printf("\n enter a the number of till which you want the table");
scanf("%d",&n);
printf("\n enter the number whose table you want to get printed ");
scanf("%d",&num);
for(i=1;i<=n;i++)
{
table=num*i;
printf("\n %d x %d = %d ",num,i,table);
}

getch();
return 0; }
14. W.A.P to reverse a number entered by the user and then find whether the number is a
palindrome or not.

#include<stdio.h>
#include<conio.h>

void main()
{
clrscr();
int rev,n,num,d;
printf("\n \n Enter the number to be checked : ");
scanf("%d",&num);
rev=0;
n=num;
while(n!=0)
{
rev=rev*10;
d=n%10;
n=n/10;
rev=rev+d;
}
printf("\n \n The number obtained after reversal is : %d",rev);
if(rev==num)
{
printf("\n \n The number is a pallindrome");
}
else
printf("\n \n not a pallindrome");
getch();
}

15. W.A.P to find the factors of the number entered by the user.

#include<stdio.h>
#include<conio.h>

main()
{ int num,n,i;
printf("\n enter the number whose factors you want to get printed ");
scanf("%d",&num);
printf("\n the factors of %d (between 1-100) are : ",num);
for(i=1;i<100;i++)
{
if((i%num)==0)
printf("\t %d ",i);
}

getch();
return 0; }
16. W.A.P that prints all perfect numbers between 2 & 9999 inclusive. A perfect number is
the positive integer such that :
a) the number is equal to sum of its proper divisor.
b) A proper divisor is any divisor whose value is less
than the number.

#include<stdio.h>
#include<conio.h>

main()

{ int sum,i;
//printf("\n enter the number whose factors you want to get printed ");
//scanf("%d",&num);
printf("\n the perfect numbers are : ");
for(i=1;i<9999;i++)
{sum=0;
for(int j=1;j<i;j++)
{

if((i%j)==0)
sum=sum+j;}
if(i==sum)
printf("\t %d ",i);}

getch();
return 0; }
17. W.A.P to find the average of ‘n’ numbers entered by the user.
#include<stdio.h>
#include<conio.h>

void main()
{
clrscr();
float sum=0.0,a,av;
int n;
printf("\n \n Enter the number of elements to be entered : ");
scanf("%d",&n);
printf("\n \n enter the elements : ");
for(int i=0;i<n;i++)
{
scanf("%f",&a);
sum = sum+a;
}
av=sum/n;
printf("\n \n average of %d numbers are : %f ",n,av);
getch();
}
18. W.A.P to find the number of digits present in the number and also find their sum.

#include<stdio.h>
#include<conio.h>

void main()
{
clrscr();
int sum=0,n,num,d;
printf("\n \n Enter the number : ");
scanf("%d",&num);

for(int i=0;n!=0;i++)
{
d=n%10;
n=n/10;
sum = sum+d;
}
printf("\n \n The number of digits are : %d \t the sum of the digits is : %d",i,sum);
getch();
}

19. A positive integer is entered by the user along with the base in which that number
needs to be converted. W.A.P to display the number entered, the base of the number
system in which it is converted and also the converted number (using switch).
20. W.A.P that implements a menu of the following type :
Menu
Option 1 ‘a’
Option 2 ‘b’
Option 3 ‘c’
Option 4 ‘q’

Enter your choice of option:


In response to user’s selection, it prints the following messages:

a) Option 1 ‘one is alone’


b) Option 2 ‘two is company’
c) Option 3 ‘three is crowd’
d) Option 4 ‘quit’

#include<stdio.h>
#include<conio.h>
main()

{ char choice;
printf("\n Menu \n Option 1 'a' \n Option 2 'b' \n Option 3 'c' \n Option 4 'q' ");
printf("\n Enter your choice of option:");
scanf("%c",&choice);
switch(choice)
{

case 'a' : printf("\n one is alone ");


break;
case 'b' :printf("\n two is company"); break;
case 'c' :printf("\n three is crowd"); break;
case 'd' :printf("\n quit"); break;
default : printf("\n wrong choice");
}

getch();
return 0; }

21. W.A.P that displays a box of the following type on the screen having maximum of 15
number of lines.
______________________________________________
| |
| |
|______________________________________________|
22. W.A.P to generate the following patterns using switch.
i) *
**
***
****
*****
#include<stdio.h>
#include<conio.h>

void main()
{
clrscr();
for(int i=1;i<=4;i++)
{
for(int j=1;j<=i;j++)
{
printf(" * ");
}
printf("\n");
}
getch();
}

ii) 1
121
12321
1234321

#include<stdio.h>
#include<conio.h>

void main()
{
clrscr();
for(int i=1;i<=5;i++)
{
for(int j=5;j>=i;j--)
{
printf(" ");
}
for(j=1;j<=1;j++)
{
printf("%d",j);
}
for(j=i-1;j>=1;j--)
{
printf("%d",j);
} printf("\n"); } getch(); }
iii) A
B B
C C C
D D D D
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
for(int i=65;i<=69;i++)
{
for(int j=65;j<=i;j++)
{
printf(" %c ",j);
}
printf("\n");
}
getch();
}
23. W.A.P which reads marks of N students in an array and adds a grace of 10 marks to
every element of the array.

#include<stdio.h>
int main()
{
int marks[10],i;
printf("\nEnter the marks of Students(10 max.)");

for(i=0;i<10;i++)
{
printf("\nEnter maks of %d student",i+1);
scanf("%d",&marks[i]);
}

for(i=0;i<10;i++)
{
printf("\nEntered maks of %d student",marks[i]);
}

for(i=0;i<10;i++)
{
marks[i]+=10;
}

for(i=0;i<10;i++)
{
printf("\nMarks after adding grace marks for %d student=%d",i+1,marks[i]);
}
return 0;
}
24. W.A.P that finds the maximum number and it’s position in a list of N numbers.

#include<stdio.h>

int main()
{
int list[10],i,j,k;
printf("\nEnter the distinct numbers(10 max.)");

for(i=0;i<10;i++)
{
printf("\nEnter %d number",i+1);
scanf("%d",&list[i]);
}

for(i=0;i<10;i++)
{
printf("\nEntered number at position %d = %d",i+1,list[i]);
}

j=list[0];
k=1;
for(i=1;i<10;i++)
{
if (j<list[i])
{
j=list[i];
k=i;
}
}

printf("\nLagest no at position %d = %d",k,j);


return 0;
}
25. W.A.P to replace the duplicate elements of an array with zero.
#include<stdio.h>
#include<conio.h>

void main()
{
clrscr();
int a[20],n;
printf("\n \n Enter the number of terms : ");
scanf("%d",&n);
printf("\n \n Enter the elements of the array : ");
for(int i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
printf("\n \n The array entered is : ");
for(i=0;i<n;i++)
{
printf("%d\t",a[i]);
}
printf("\n \n The Array after removal of duplicate elemnets is : ");
i=0;
while(i<n)
{
for(int k=1;k<n;k++)
{
if(a[i]==a[i+k])
{
a[i]=a[i]-a[i+k];
}
}
printf(" \n ");
printf("\t %d",a[i]);
i++;
}
getch();
}
26. W.A.P to find the average of elements entered by the user in an array.
#include<stdio.h>
#include<conio.h>

void main()
{
clrscr();
float sum=0.0,av;
int n,a[20];
printf("\n \n Enter the number of elements to be entered : ");
scanf("%d",&n);
printf("\n \n enter the elements : ");
for(int i=0;i<n;i++)
{
scanf("%f",&a[i]);
sum = sum+a[i];
}
av=sum/n;
printf("\n \n average of %d numbers are : %f ",n,av);
getch();
}

27. W.A.P to display the position of the elements entered by the user in a string along with
the addresses of those elements.
#include<stdio.h>
#include<conio.h>
#include<string.h>
main()

{ char list[30];
int len1,i;
printf("\n enter the string ");
scanf("%s",list);
len1=strlen(list);
printf("\n length of the string is : %d ",len1);
for(i=0;i<len1;i++)
printf("\n %c is at %d location & it's address is %u ",list[i],i+1,&list[i]);

getch();
return 0; }
28. W.A.P which inserts a value in an array at a particular position.
#include<stdio.h>

int main()
{
int list[10],i,j,k;

for(i=0;i<10;i++)
list[i]=0;

printf("\nEnter the value and the position in array(array max size=10)");


scanf("%d%d",&i,&j);

list[j-1]=i;

printf("\nArray values are:");

for(i=0;i<10;i++)
printf("\n%d value=%d",i+1,list[i]);

return 0;
}

29. W.A.P that computes the sum of the diagonal elements of a square matrix.

#include<stdio.h>
#include<conio.h>
main()
{ int n,a[20][20],temp=0,i,j;
printf("\n Enter the size of the square matrix ");
scanf("%d",&n);
printf("\n enter the elements of the matrix");
for(i=0;i<n;i++)
{
for( j=0;j<n;j++)
{
scanf("%d",&a[i][j]);
}
}
printf("\n The matrix entered is : \n ");
for( i=0;i<n;i++)
{
for( j=0;j<n;j++)
{
printf("%d",a[i][j]);
printf("\t");
}
printf("\n");
}

for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
if(i==j)
temp=temp+a[i][j];
}
}
printf("\n the sum of daigonal elements is : %d ",temp);

getch();
return 0; }

30. Given a set of randomly ordered numbers, sort them in ascending order by selection
sort method.

#include<stdio.h>
#include<conio.h>
main( )
{
int arr[10],n,temp ;
printf("\n enter the number of terms ");
scanf("%d",&n);
printf("\n enter the numbers to be sorted ");
for(int i=0;i<n;i++)
{
scanf("%d",&arr[i]);
}
for ( int i = 0 ; i <= n - 2 ; i++ )
{
for ( int j = i + 1 ; j <= n - 1 ; j++ )
{
if ( arr[i] > arr[j] )
{
temp = arr[i] ;
arr[i] = arr[j] ;
arr[j] = temp ;
}
}
}

printf("\n the list after sorting is : ");


for ( int i = 0 ; i < n ; i++ )
printf("\t %d ",arr[i]);

getch();
return 0;
}

31. W.A.P that reads the name, rollno and total marks of all the students in a class and
then generates a merit list.

#include<stdio.h>
#include<conio.h>
struct student
{
int total_marks;
char name[30];
int roll_no;
}s[30];
main()
{ int num,temp,marks[30];
printf("\n enter the number of students ");
scanf("%d",&num);
printf("\n enter the details of the students ");
for(int i=0;i<num;i++)
{
printf("\n enter the name of %d.student : ",i);
scanf(" %s",s[i].name);
printf("\n enter the roll no. of %d.student : ",i);
scanf("%d",&s[i].roll_no);
printf("\n enter the total marks of %d.student : ",i);
scanf("%d",&s[i].total_marks);
}
for(int i=0;i<num;i++)
marks[i]=s[i].total_marks;

printf("\n the marks entered of %d students are as follows : ",num);


for ( int i = 0 ; i <= num - 2 ; i++ )
{
for ( int j = i + 1 ; j <= num - 1 ; j++ )
{
if ( marks[i] < marks[j] )
{
temp = marks[i] ;
marks[i] = marks[j] ;
marks[j] = temp ;
}}}
printf("\n the merit list is as follows :" );
for(int i=0;i<num;i++)
{
for(int j=0;j<num;j++)
{
if(marks[i]==s[j].total_marks)

printf(" \n \t roll number %d name %s \n ",s[j].roll_no,s[j].name);


} }
getch();
return 0;
}

32. W.A.P that uses two parallel arrays country and capital to store the names of countries
and their corresponding capitals. It interacts with the user in such a way that for a
given county, it gives the name of it’s capital. Use array initialization concept to store
the names of the countries and it’s capitals.
33. W.A.P that reads a string and counts the number of vowels, words and white spaces
present in the string.

#include<stdio.h>
int main()
{
char c,str[100];
int vowel=0,word=0,ws=0,i=0;
printf("Pls enter the String\n");
while((str[i]=getche())!='\r')
{
if(str[i]==' ')ws++;
if(str[i]=='a'||str[i]=='A'||str[i]=='e'||str[i]=='E'||str[i]=='i'||str[i]=='I'||str[i]=='o'||str[i]=='O')
vowel++;
i++;
}
word=ws+1;
//printf("\ntest\n");
printf("\nword=%d\nvowel=%d\nws=%d",word,vowel,ws);
return 0;
}
34. W.A.P that allows the user to enter a character until he inputs the character ‘q’. Each
time a character is entered, the program displays whether it is an alphabet or not.

#include<stdio.h>
#include<conio.h>
int main()
{
char ch;
int d;

do
{ printf("\n enter the character");
scanf(" %c",&ch);
d=ch;
if(d>65&&d<122)
printf("\n the number is an alphabet");
else
printf("\n the number is not an alphabet");
}
while(ch!='q');
getch();
return 0; }

35. W.A.P to find the location of the word in a string entered by the user. For example, if
the string entered is “somewhere over the rainbow” and the word whose location is to
be found is “over”. So the output should be 11.
36. Write a menu driven program to do the following :
a) find factorial of a number entered by the user using functions.
b) to swap to numbers using call by value.
c) to reverse a number using functions.

#include<stdio.h>
#include<conio.h>
int fact(int);
int swap(int,int);
int reverse(int);
main( )
{
int num1,num2,f,r;
char choice;
printf("\n a) find factorial of a number entered by the user using functions. \n b)
to swap to numbers using call by value.\n c) to reverse a number using functions.");
printf("\n Enter your choice : ");
scanf("%c",&choice);
printf("\n \n
******************************************************************\n \n");
switch(choice)
{
case 'a': printf("\n enter the number whose factorial needs to be determined
");
scanf("%d",&num1);

f=fact(num1);
printf("\n the factorial of %d is : %d ",num1,f);
break;
case 'b': printf("\n enter two numbers to be swapped ");
scanf("%d %d",&num1,&num2);
swap(num1,num2);
break;
case 'c': printf("\n enter the number to be reversed");
scanf("%d",&num1);
r=reverse(num1);
printf("\n the after reversal is : %d ",r);
break;
}
getch();
return 0;
}

int fact(int num)


{
int fac=1,i;
for(i=num;i>0;i--)
{
fac=fac*i;
}
return fac;
}
int reverse(int n)
{
int rev=0,d;
while(n!=0)
{
rev=rev*10;
d=n%10;
n=n/10;
rev=rev+d;
}
return rev;
}

int swap(int n1,int n2)


{
int temp;
temp=n1;
n1=n2;
n2=temp;
printf("\n the numbers after swapping are : %d %d ",n1,n2);
return 0;
}

37. W.A.P to make the following figures using graphics functions.

a)

b)
c)

Das könnte Ihnen auch gefallen