Assignment 1
Assignment 1
#include<stdio.h>
#include<conio.h>
void main()
{
int day;
printf("enter no of day");
scanf("%d",&day);
switch(day)
{
case 1:
printf("Sunday");
break;
case 2:
printf("Monday");
break;
case 3:
1
printf("Tuesday");
break;
case 4:
printf("Wednesday");
break;
case 5:
printf("Thursday");
break;
case 6:
printf("Friday");
break;
case 7:
printf("Saturday");
break;
default:
printf("Wrong day");
getch();
}
2
2. Write a program to find no of vowels in a string.
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
int c,i,j,len;
char stri[50],vow[]="aeiouAEIOU";
c=0;
printf("enter string\n");
gets(stri);
len=strlen(stri);
for(i=0;i<=len;i++)
{
for(j=0;j<=9;j++)
{
if(stri[i]==vow[j])
c++;
}
}
if(c==0)
printf("sorry no vowel ");
else
printf(" no of vowel =%d",c);
3
3. WAP to illustrate the use of user-defined function. The program initializes
an array of n elements from 0 to n-1 and then calculate and print the sum
of the array elements
#include<stdio.h>
#include<conio.h>
void main()
{
int a[50],b,i,n;
b=0;
printf("enter no of elements\n");
scanf("%d",&n);
printf("Enter array elements\n");
for(i=0;i<n;i++)
scanf("%d",&a[i]);
for(i=0;i<n;i++)
b=b+a[i];
printf("sum = %d",b);
}
4. WAP to accept the radius & height from console and calculate
a. Circumference Of The Circle
b. Lateral Surface Area Of Cylinder
c. Volume Of Cylinder
d. Curve Surface Area Of A Cone
#include<stdio.h>
#include<conio.h>
void main()
{
int r,h;
4
float c,p,l,lsacyl,vcyl,csacone;
p=3.14;
printf("enter value of radius and height");
scanf("%d%d",&r,&h);
c=2*p*r;
lsacyl=2*p*r*h;
vcyl=p*r*r*h;
l=sqrt(r*r+h*h);
csacone=(p*r*r+p*r*l);
printf("circumference is %.2f\n",c);
printf("lateral surface area of cyl is %.2f\n",lsacyl);
printf("volume of cylinder is %.2f\n",vcyl);
printf("csa of cone is %.2f\n",csacone);
}
5. WAP to take input of string from console in uppercase and print the result
i.e The Same String In Lowercase.
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
int a,i;
char str[50];
printf("enter string in upper case\n");
gets(str);
a=strlen(str);
for (i=0;i<a;i++)
5
if (str[i]>=97&&str[i]<=122)
{
printf("%s",strlwr(str));
break;
}
}
6. WAP to input a 4 digit no. and indicate digit at tenth ,thousand place.
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,c,d;
printf("enter the no.");
scanf("%d",&a);
if(a>=1000&&a<=9999)
{
b=a-((a/100)*100);
c=(b-(b%10))/10;
d=((a-a%1000)/1000);
printf("no at thousand place is %d\n no of tenth place is %d",d,c);
6
}
else { printf("entered no is not of 4 digit");
}
getch();
}
#include<stdio.h>
#include<conio.h>
struct student
{
int roll;
char name[10],course[20],gender[8];
} a[5];
void main()
{
int i;
for(i=0;i<=4;i++)
{
printf("enter %d student details \n Enter roll\t",i+1);
scanf("%d",&a[i].roll);
printf("enter name\t");
scanf("%s",&a[i].name);
printf("enter course\t");
scanf("%s",&a[i].course);
printf("enter gender\t");
scanf("%s",&a[i].gender);
7
}
printf("\n\t\t\t\STUDENTS RECORD\n");
for(i=0;i<=4;i++)
printf("\nstudent %d\n roll is %d\n name is %s\n course is %s\n gender is
%s",i+1,a[i].roll,a[i].name,a[i].course,a[i].gender);
}
8. Write a program to find sum of two matrices.
#include<stdio.h>
#include<conio.h>
void main()
{
int a[3][3],b[3][3],c[3][3],i,j;
printf("enter first 2d array elements\n");
for(i=0;i<=2;i++)
{
for(j=0;j<=2;j++)
{
scanf("%d",&a[i][j]);
}
}
printf("enter second 2d array elements\n");
for(i=0;i<=2;i++)
{
for(j=0;j<=2;j++)
8
{
scanf("%d",&b[i][j]);
}
}
for(i=0;i<=2;i++)
{
for(j=0;j<=2;j++)
{
c[i][j]=a[i][j]+b[i][j];
}
}
printf("sum of 2d array is\n");
for(i=0;i<=2;i++)
{
for(j=0;j<=2;j++)
{
printf("%d\t",c[i][j]);
}
printf("\n");
}
#include<stdio.h>
9
#include<conio.h>
#include<stdlib.h>
void main()
{
int m,n;
int o;
int *arr;
printf("\nChoose Any One Option :");
printf("\n1.Malloc");
printf("\n2.Calloc");
printf("\nEnter Your Option :");
scanf("%d",&o);
switch(o)
{
case 1:
printf("\nEnter number of elements :");
scanf("%d",&n);
arr=(int*)malloc(sizeof(int));
if(arr==NULL)
{
printf("\nMemory Allocation Failed");
}
else
{
printf("\nEnter Elements :");
for(m=0;m<n;m++)
{
scanf("%d",&arr[m]);
}
printf("\nOUTPUT ARE\n");
for(m=0;m<n;m++)
{
printf("%d\n",arr[m]);
10
}
}
break;
case 2:
printf("\nEnter number of elements :");
scanf("%d",&n);
arr=(int*)calloc(n,sizeof(int));
if(arr==NULL)
{
printf("\nMemory Allocation Failed");
}
else
{
printf("\nEnter Elements :");
for(m=0;m<n;m++)
{
scanf("%d",&arr[m]);
}
printf("\nOUTPUT ARE\n");
for(m=0;m<n;m++)
{
printf("%d\n",arr[m]);
}
}
break;
default :
printf("\nInvalid Input");
}
getch();
}
11
10. Program to input and display three-dimensional array.
#include<stdio.h>
#include<conio.h>
void main()
{
int a[3][3][3],i,j,k;
for(i=0;i<3;i++)
for(j=0;j<3;j++)
for(k=0;k<3;k++)
{
printf("enter a[%d][%d][%d] element",i,j,k);
scanf("%d",&a[i][j][k]);
}
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
printf("{");
for(k=0;k<3;k++)
{
printf(" %d ",a[i][j][k]);
}
printf("}\t");
}
printf("\n");
12
}
}
11. Write a program to create a structure data type with one int and two float.
#include<stdio.h>
#include<conio.h>
struct struct_data_type
{
int a;
float b,c;
}z;
void main()
{
12. Write a program to find size of structure data type an its structural array.
13
#include<stdio.h>
#include<conio.h>
struct structure
{
int a,b;
float c;
} z[10] ;
void main()
printf("size of struct data type with two integer and one float is %d\nsize of
struct array z of ten elements is %d\n",sizeof(struct structure),sizeof(z));
#include<stdio.h>
#include<conio.h>
int main()
int arr[10];
14
int i;
printf("\nEnter 10 numbers:\n");
for(i=0;i<10;i++)
scanf("%d",&arr[i]);
printf("\nOutput\n");
for(i=0;i<10;i++)
printf("%d ",arr[i]);
14. WAP for a 3-D array in which you have to insert two elements in each
rows and columns of 2*3 matrix
#include<stdio.h>
#include<conio.h>
void main()
{
int a[2][3][2],i,j,k;
for(i=0;i<2;i++)
for(j=0;j<3;j++)
for(k=0;k<2;k++)
{
printf("enter a[%d][%d][%d] element",i,j,k);
scanf("%d",&a[i][j][k]);
}
for(i=0;i<2;i++)
{
15
for(j=0;j<3;j++)
{
printf("{");
for(k=0;k<2;k++)
{
printf(" %d ",a[i][j][k]);
}
printf("}\t");
}
printf("\n");
}
}
15. WAP to arrange the given test matrix 4*4 in following format :
Test Matrix :
4231
6231
7 8 9 10
4322
4000
0200
0090
16
0002
#include<stdio.h>
#include<conio.h>
void main()
int a[4][4]={{4,2,3,1},{6,2,3,1},{7,8,9,10},{4,3,2,2}},i,j;
for(i=0;i<4;i++)
for(j=0;j<4;j++)
printf("%d\t",a[i][j]);
printf("\n");
17
printf("diagonal matrix is\n");
for(i=0;i<4;i++)
for(j=0;j<4;j++)
if(i==j)
a[i][j]=a[i][j];
else
a[i][j]=0;
printf("%d\t",a[i][j]);
printf("\n");
16. WAP to add 5 at 4th index of stack array having functions Push,Pop &
Display .
#include<stdio.h>
#include<conio.h>
int stack[100];
int count=-1;
18
void push()
{
int n,i,count1;
count1=count+1;
printf("enter no of elements you want to push");
scanf("%d",&n);
if((count+n)>99)
{
for(i=count+1;i<=count+n;i++)
{
}
count=count+n;
}
void pop()
19
{
if(count<0)
{
printf("stack empty");
}
else
{
}
}
void display()
{
int dis=0;
if(count==-1)
printf("stack is empty");
else printf("stack elements are\n");
while(dis<=count)
{
printf("%d\t",stack[dis]);
dis++;
}
}
void add_5_at_4th_index_element()
{
if(stack[3]!=NULL)
{
20
printf("element at 4th index is %d\n",stack[3]);
stack[3]=stack[3]+5;
printf("new value of element at 4th index is %d\n",stack[3]);
display();
}
void main()
{
int d,choice;
while(1)
{
printf("\nmenu:");
printf("\n 1.push \n 2.pop \n 3.display \n 4.Add 5 at 4th index \n
5.exit\n");
printf("enter your choice:");
scanf("%d",&choice);
switch(choice)
{
case 1:
push();
break;
case 2:
pop();
break;
case 3:
display();
21
break;
case 4:
add_5_at_4th_index_element ();
break;
case 5:
exit(0);
default:;
22