You are on page 1of 40

Q 1- WAP to Add two Number ?

/* addition of two numbers of int datatype*/

#include<stdio.h>

#include<conio.h>

void main()

int a,b,c;

printf("enter the value of a:");

scanf("%d",&a);

printf("enter the value of b:");

scanf("%d",&b);

c=a+b;

printf("value of c:%d",c);

getch();

1
Q 2- Wap To Get sum of two number using Array ?

/* sum of five element by using array*/

#include<stdio.h>

#include<conio.h>

void main()

int a[5],i,sum=0;

clrscr();

for(i=0;i<=4;i++)

printf("\nenter element:");

scanf("%d",&a[i]);

for(i=0;i<=4;i++)

sum=sum+a[i];

printf("\n the sum of five element is %d",sum);

getch();

Q 3 - Wap to Add two Matrixes ?

2
#include<stdio.h>

#include<conio.h>

void main()

int a[4][4],b[4][4],c[4][4],i,j,p,q;

clrscr();

printf("enter the order of matrix\n");

scanf("%d%d",&p,&q);

printf("matrix can be added\n");

printf("enter the elements of the matrix a");

for(i=0;i<p;i++)

for(j=0;j<q;j++)

scanf("%d",&a[i][j]);

printf("enter the elements of the matrix b");

for(i=0;i<p;i++)

for(j=0;j<q;j++)

scanf("%d",&b[i][j]);

printf("the sum of matrix a and b\n");

for(i=0;i<p;i++)

for(j=0;j<q;j++)

c[i][j]=a[i][j]+b[i][j];

for(i=0;i<p;i++)

for(j=0;j<q;j++)

3
printf("%d\t",c[i][j]);

printf("\n");

getch();

Q 4- Wap to Know Whether entered number is Armstrong or not ?

#include<stdio.h>

#include<conio.h>

4
void main()

int num,i,sum,rem;

clrscr();

for(i=1;i<=500;i++)

num=i;

sum=0;

while(num>0)

rem=num%10;

sum=sum+rem*rem*rem;

num=num/10;

if(i==sum)

printf("\nnumber is armastrong=%d",i);

getch();

Q 5- wap to Passing an Array to a function ?

/* passing array to function */

#include<stdio.h>

5
#include<conio.h>

void main()

int large(int a[10]);

int ar[10];

int l,i;

clrscr();

for(i=0;i<=9;i++)

printf("\nenter %d element\t",i+1);

scanf("%d",&ar[i]);

l=large(ar);

printf("\nlargest element is %d",l);

getch();

int large(int a[10])

int big,i;

big=0;

for(i=1;i<=9;i++)

if(a[i]>big)

big=a[i];

6
}

return big;

Q 6- Wap to sort an array in ascending order ?

#include<stdio.h>

#include<conio.h>

void main()

int arr[10],i,j,temp;

clrscr();

7
printf("\nenter the element of the array:");

for(i=0;i<10;i++)

scanf("%d",&arr[i]);

for(i=0;i<10;i++)

for(j=i+1;j<10;j++)

if(arr[i]>arr[j])

temp=arr[i];

arr[i]=arr[j];

arr[j]=temp;

printf("\nsorted array is :");

for(i=0;i<10;i++)

printf("%d\t",arr[i]);

printf("\n");

getch(); }

Q 7- Wap to understand the use of Break Statement ?

#include<stdio.h>

#include<conio.h>

void main()

int i,n;

clrscr();

8
printf("enter the value");

scanf("%d",&n);

for(i=1;i<=n;i++)

if(i==5)

printf("i understand the use of break\n");

break;

printf("number: %d\n",i);

printf("\n");

getch();

Q 8- Wap to Swap Two number using Pointer ?

#include<stdio.h>

#include<conio.h>

void swap(int *x,int *y);

void main()

int a,b;

clrscr();

9
printf("\nenter the 1st number:");

scanf("%d",&a);

printf("\nenter the 2nd number:");

scanf("%d",&b);

swap(&a,&b);

printf("\nafter the function execution:");

printf("\na=%d",a);

printf("\nb=%d",b);

getch();

void swap(int *x,int *y)

int temp;

temp=*x;

*x=*y;

*y=temp;

printf("\nthe swapped value");

printf("\na=%d",*x);

printf("\nb=%d",*y);

10
Q 9 - Wap To swap two number By function (Call by value ) ?

/*call by value*/

#include<stdio.h>

#include<conio.h>

void main()

void swap(int x,int y);

int a,b;

clrscr();

printf("\nenter the first number:");

11
scanf("%d",&a);

printf("\nenter the second number:");

scanf("%d",&b);

swap(a,b);

printf("\nafter the function execution");

printf("\na=%d",a);

printf("\nb=%d",b);

getch();

void swap(int x,int y)

int temp;

temp=x;

x=y;

y=temp;

printf("\nthe swapped value:");

printf("\na=%d",x);

printf("\nb=%d",y);

12
Q 10- wap to Understand The CONTINUE statement ?

#include<stdio.h>

#include<conio.h>

void main()

int i,n;

clrscr();

printf("\nenter the value");

scanf("%d",&n);

for(i=1;i<=n;i++)

if(i==3)

13
printf(" i understand\n");

continue;

printf("number:%d\n",i);}

printf("\n);

getch();

Q 11- Wap to convert the value of km into meter,centi meter, inch and feet ?

#include<stdio.h>

#include<conio.h>

void main()

int cm,m,km;

float inch,ft;

clrscr();

printf("\nenter the value of km:");

scanf("%d",&km);

m=km*100;

14
cm=m*100;

inch=cm/2.54;

ft=inch/12;

printf("\nthe value of m,cm,inch,ft=\n%d\n%d\n%f\n%f",m,cm,inch,ft);

getch();

Q 12- wap to Know how many number is negative and Positive are I entered in
array ?

#include<stdio.h>

#include<conio.h>

void main()

int a[5],n,c_pos=0,c_neg=0,i;

clrscr();

printf("enter the size of array\n");

scanf("%d",&n);

printf("enter the element of array\n");

for(i=0;i<n;i++)

scanf("%d",&a[i]);

for(i=0;i<n;i++)

15
{

if(a[i]<0)

c_neg++;

else

c_pos++;

printf("there are %d negative numbers in the array\n",c_neg);

printf("there are %d positive numbers in the array\n",c_pos);

getch();

Q 13- Wap to know the factorial of entered number ?

#include<stdio.h>

#include<conio.h>

void main()

int n,i;

long int fact=1;

printf("enter the number");

scanf("%d",&n);

if(n<0)

printf("number is negative");

else

while(n>1)

16
fact=fact*n;

n--;

}}

printf("%ld",fact);

getch();

Q 14- Wap to know the largest number in array ?

#include<stdio.h>

#include<conio.h>

void main()

int large(int a[5]);

int ar[5];

int l,i;

clrscr();

for(i=0;i<=4;i++)

printf("\n enter element\t");

scanf("%d",&ar[i]);

l=large(ar);

printf("\n largest element is =%d",l);

17
getch();

int large(int a[5])

int big,i;

big=0;

for(i=1;i<=4;i++)

if(a[i]>big)

big=a[i];

return big;

18
Q 15- wap to know the factorial of given number using function ?

#include<stdio.h>

#include<conio.h>

int fact(int n);

void main()

int num;

int f;

clrscr();

printf("\n enter a number:");

scanf("%d",&num);

f=fact(num);

printf("\n fact=%d",f);

getch();

int fact(int n)

int fc; int i;

19
fc=1;

for(i=n;i>=1;i--)

fc=fc*i;

return fc;

Q 16- Wpa to know the fcctorial of given number using function ?

#include<stdio.h>

#include<conio.h>

void fact(int n);

void main()

int num;

clrscr();

printf("\n enter a number:");

scanf("%d",&num);

fact(num);

getch();

void fact(int n)

int fc; int i;

fc=1;

for(i=n;i>=1;i--)

fc=fc*i;

20
printf("\n the output is: %d",fc);

Q 17- Wap to print fibbonoci Series ?

#include<stdio.h>

#include<conio.h>

void main()

int a=0;int b=1;int c;

int i,n;

printf("\nenter the number of terms:");

scanf("%d",&n);

for(i=1;i<=n-2;i++)

c=a+b;

printf("%d%d%d",a,b,c);

a=b;

b=c;

21
getch();

Q 18- Wap to whether given number is Odd or Even using file handling ?

#include<stdio.h>

#include<conio.h>

void main()

FILE *f1,*f2,*f3;

int num,i;

clrscr();

printf("content of data file\n");

f1=fopen("data","w");

for(i=1;i<=30;i++)

scanf("%d",&num);

if(num==-1)break;

putw(num,f1);

fclose(f1);

f1=fopen("data","r");

f2=fopen("odd","w");

f3=fopen("even","w");

22
while((num=getw(f1))!=EOF)

if(num%2==0)

putw(num,f3);

else

putw(num,f2);

fclose(f1);

fclose(f2);

fclose(f3);

f2=fopen("odd","r");

f3=fopen("even","r");

printf("\n\ncontents of odd file \n\n");

while((num=getw(f2))!=EOF)

printf("%4d",num);

printf("\n\ncontents of even file\n\n");

while((num=getw(f3))!=EOF)

printf("%4d",num);

fclose(f2);

fclose(f3);

getch();

23
Q 19- Wap to know the number is odd or even by goto statement ?

#include<stdio.h>

#include<conio.h>

void main()

int n;

printf("enter the value");

scanf("%d",&n);

if(n%2==0)

goto even;

else

goto odd;

even:

printf("number is even");

goto end;

odd:

printf("number is odd");

goto end;

end:

printf("\n");

getch();

24
Q 20- Wap to Add two n umber of int data type ?

/* addition of two numbers of int datatype*/

#include<stdio.h>

#include<conio.h>

void main()

int bs,da,hra;

float gross_sal;

clrscr();

printf("\nenter basic salary");

scanf("%d",&bs);

da=(40*bs)/100;

hra=(20*bs)/100;

gross_sal=bs+da+hra;

printf("value of gross salary : %f\n",gross_sal);

getch();

25
Q 21- Wap to get largest element in an Array ?

/* largest element in an array*/

#include<stdio.h>

#include<conio.h>

void main()

int a[5],i,c;

clrscr();

for(i=0;i<=4;i++)

printf("\nenter the element");

scanf("%d",&a[i]);

c=a[0];

for(i=1;i<=4;i++)

if(c<a[i])

c=a[i];

printf("\nthe largest element is %d",c);

getch();

26
Q 22- Wap to Print

**

***

****

#include<stdio.h>

#include<conio.h>

void main()

int i,j,k;/* where i,j,k denotes no. of rows,space and columns resp.*/

int a=3;/* this line indicates the maximum no. of space*/

clrscr();

for(i=1;i<=4;i++)

for(j=1;j<=a;j++)

printf(" ");

for(k=1;k<=i;k++)

printf("*");

printf("\n");

a=a-1;

27
getch();

Q 23- Wap to free the allocated memory of a variable ?

#include<stdio.h>

28
#include<conio.h>

#include<alloc.h>

#include<stdlib.h>

void main()

int n,*ptr;

int i;

clrscr();

printf("\nenter number of integer to be entered");

scanf("%d",&n);

ptr=(int*)malloc(n*sizeof(int));

if(ptr==0)

printf("\nmemory not allocated","aborting!!!");

exit(1);

else

for(i=0;i<n;i++)

printf("\nenter %d element",i+1);

scanf("%d",&ptr[i]);

for(i=0;i<n;i++)

printf("\n%d",ptr[i]);

29
printf("\nDONE!!!!");

free (ptr);

getch();

Q 24- Wap to enter the onfo. Of Student using Structure ?

#include<stdio.h>

#include<conio.h>

struct student

30
int roll_no;

char name[20];

struct date

int day;

int month;

int year;

}b;

}a;

void main()

clrscr();

printf("\nenter the name & roll no,date of birth\n");

scanf("%d",&a.roll_no);

gets(a.name);

printf("\n");

scanf("%d%d%d",&a.b.day,&a.b.month,&a.b.year);

printf("\n%d\n%s\n%d-%d-%d",a.roll_no,a.name,a.b.day,a.b.month,a.b.year);

getch();

#include<stdio.h>

#include<conio.h>

void main()

31
int a,n,s=0,r;

clrscr();

printf("\nenter the number:");

scanf("%d",&n);

a=n;

while(n>0)

r=n%10;

s=s*10+r;

n=n/10;

if(s==a)

printf("\nthe number is palindrome");

else

printf("\nthe number is not palindrome");

getch();

Q 25- wap of Enter number using pointer ?

#include<stdio.h>

#include<conio.h>

void main()

char z='b';

32
float x=125.5;

int y=75;

int *a;

char *b;

float *c;

a=&y;

b=&z;

c=&x;

printf("%d%c%f",a,b,c);

getch();

Q 26- Wap to Understand the use of sizeof() operater ?

#include<stdio.h>

#include<conio.h>

main()

int age=30;

float height=5.98;

33
char a='B';

int *p=&age;

float *p1=&height;

char *p2=&a;

printf("\nThe %d\t%d",sizeof(p),sizeof(*p));

printf("\nThe %d\t%d",sizeof(p1),sizeof(*p1));

printf("\nThe %d\t%d\n",sizeof(p2),sizeof(*p2));

Q 27- Wap to know whether entered number is prime or not ?

#include<stdio.h>

#include<conio.h>

void main()

int n,i;

int c=0;

clrscr();

34
printf("\nenter the number:");

scanf("%d",&n);

for(i=1;i<=n;i++)

if(n%i==0)

c=c+1;

if(c==2)

printf("\nnumber is prime");

else

printf("\nnumber is not prime");

getch();

Q 28- Wap to print the wolt. of given thing ?

#include<stdio.h>

#include<conio.h>

void main()

clrscr();

printf("\n\tphilips\t40w\t60w\t30w");

printf("\n\tbajaj\t45w\t50w\t35w");

35
printf("\n\tsamsung\t35w\t45w\t40w");

getch();

Q 29- Wap to know the address of given variable ?

#include<stdio.h>

#include<conio.h>

void main()

int a=87;

int *p=&a;

float b=4.5;

float *p1=&b;

36
clrscr();

printf("\nvalue of p=address of a=%u",p);

printf("\nvalue of p1=address of b=%u",p1);

printf("\naddress of p=%u",&p);

printf("\naddress of p1=%u",&p1);

printf("\nvalue of a=%d%d%d",a,*p,*(&a));

printf("\nvalue of b=%f%f%f",b,*p1,*(&b));

getch();

Q 30- Wap to know the fact. Of given number using recursion ?

#include<stdio.h>

#include<conio.h>

void main()

int fact(int n);

int num,f;

clrscr();

printf("\n enter the number:");

scanf("%d",&num);

37
f=fact(num);

printf("\n factorial is =%d",f);

getch();

int fact(int n)

if(n==0)

return 1;

else

return(n*fact(n-1));

Q 31- Wap to know the Power of given number using function ?

#include<stdio.h>

#include<conio.h>

void main()

int fact(int a,int n);

int p,x,m;

printf("\n enter the value of x:");

scanf("%d",&x);

printf("\n enter the power:");

scanf("%d",&m);

p=power(x,m);

38
printf("%d raised the power to the power %d is:%d",m,x,p);

getch();

int power(int a,int n)

if(n==0)

return 1;

else

return(a*power(a,n-1));

Q 32 Wap to print the Reverse of Given Number ?

#include<stdio.h>

#include<conio.h>

void main()

int n,s=0,r;

clrscr();

printf("\nenter the number:");

scanf("%d",&n);

while(n>0)

39
r=n%10;

s=s*10+r;

n=n/10;

printf("\nthe reverse number is %d",s);

getch();

40

You might also like