Assignment 02-H2 (8.11.19)

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 9

SHRI G.S.

INSTITUTE OF TECHNOLOGY & SCIENCE, INDORE


DEPARTMENT OF COMPUTER ENGINEERING
CO 10504 Computer Programming
Lab Assignment No. 02(H2)

Name – Swapnil Mishra ;


Roll No. -- AB_17084 ;

Q1. Write a program to print hollow square star pattern.

5
545
54345
5432345
Proogram
#include<stdio.h>
void main()
{
int a,i,j,k;
for(i=0;i<4;i++)
{
for(k=3;k>i;k--)
{
printf(" ");
}
a=5;
for(j=0;j<=i;j++)
{
printf("%d",a);
a=a-1;
}
a=a+2;
for(j=1;j<=i;j++)
{
printf("%d",a);
a=a+1;
}
printf("\n");
}
}

Output

Q2. C Program to Check Armstrong Number.

Program
#include<stdio.h>
void main()
{
int a,b,c,d,e,f,p;
scanf("%d",&p);
a=p;
b=a%10;
a=a/10;
c=a%10;
a=a/10;
d=a%10;
a=a/10;
e=a%10;
f= b*b*b + c*c*c + e*e*e + d*d*d;
if(p==f)
{
printf("Number is a armstrong no.");
}
else {printf("Number is not a armstrong no.");}
}

output

Q3.C Program to Copy String Without Using strcpy().

Program
#include<stdio.h>
#include<string.h>
void main()
{
int i;
char a[10]="SGSITS",b[10]="GOAL";
for(i=0;b[i]!='\0';i++)
{
a[i]=b[i];
}
a[i]='\0';
puts(a);
}

Output

Q4. C Program to Sort Elements in Lexicographical Order (Dictionary Order).

Programinng
#include<stdio.h>
#include<string.h>
void main()
{
char a[5][50],b[50];
int i,j;
for (i=0;i<5;i++)
{
gets(a[i]);
}
for(i=0;i<5;i++)
{
for (j=i+1;j<5;j++)
{
if (strcmp(a[i],a[j])>0)
{
strcpy(b,a[i]);
strcpy(a[i],a[j]);
strcpy(a[j],b);
}
}
}
printf("String in the dictionary form\n");
for(i=0;i<5;i++)
{
puts(a[i]);
}
}

Output

Q5. C Program to find Largest Element in Array in C Programming.

Programing
#include<stdio.h>
void main()
{
int a[10]={1,2,3,4,5,6,7,8,9,0},n=0,i;
for(i=0;i<10;i++)
{
for(n;n<a[i];++n)
{

}
}
printf("largest no. is %d",n);
}

output

Q6. C Program to delete duplicate elements in an array.

Program

#include<stdio.h>
#include<string.h>
void main()
{
char a[10]="SGSITSCOLL";
int i,j;
for(i=0;a[i] != '\0';i++)
{
for (j=(i+1);j<10;j++)
{
if(a[i]==a[j])
{
a[j]=' ';
}
}
}
puts(a);
}

Output

Q7. C Program to Check whether Matrix is Magic Square or Not ?


Program

#include<stdio.h>
void main()
{
int a[3][3],i,j,r[3],c[3],d;
for (i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
scanf("%d",&a[i][j]);
}
}
for (i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
printf("%d ",a[i][j]);
}
printf("\n");
}
for(i=0;i<3;i++)
{
r[i]=0;
for(j=0;j<3;j++)
{
r[i] += a[i][j];
}
}
for(i=0;i<3;i++)
{
c[i]=0;
for(j=0;j<3;j++)
{
c[i] += a[i][j];
}
}
d=0;
for(i=0;i<3;i++)
{
d += a[i][i];
}
if (r[0]==r[1]==r[2]==c[0]==c[1]==c[2]==d)
printf("It is a magic square");
else printf("It is not a magic square");
}

Output

Q8. C Program to find addition of Lower Triangular Elements in C Programming.

Program

#include<stdio.h>
void main()
{
int i, j, a[3][3]={1,2,3,4,5,6,7,8,9}, s=0;
for (i = 0; i < 3; i++)
for (j = 0; j < 3; j++)
{
if (i > j)
{
s = s + a[i][j];
}
}
printf("\nSum of Lower Triangle Elements : %d", s);
}

Output

Q9. Program to Cyclically Permute the Elements of an Array.

Program

#include<stdio.h>
void main()
{
int a[5]={1,2,3,4,5},i,b,c;
c=a[0];
printf("original series is ");
for(i=0;i<5;i++)
printf("%d",a[i]);
for(i=0;i<5;i++)
{
a[i]=a[i+1];
}
a[4]=c;
printf("series after rotation is ");
for(i=0;i<5;i++)
printf("%d",a[i]);
}

Output

Q10. WAP to check if the given sequence of numbers is in ascending order or


not. The sentinel value for the sequence is -1.
program

#include<stdio.h>
void main()
{
int a[10],b=0,i;
for (i=0;i<10;i++)
{
scanf("%d",&a[i]);
}
for(i=0;i<9;i++)
{
if(a[i]<a[i+1])
{
b=++b;
}
}
if(b==9)
printf("the series is in ascending order");
else printf("the series is not in ascending order");
}

output

Q11. Program to find out the number of notes required for a given amount of money.
(use switch statement to solve this question)

Program

#include<stdio.h>
int main()
{
int r,n;
printf("total amount =");
scanf("%d",&r);
// printf("in which type of note do you want your money");
// scanf("%d",&n);
switch (10)
{
case 10: if(r%10 ==0)
{
printf("no. of 10 notes required is %d\n",r/10);
}
else{
printf("all the money can not be given in this particular type of notes
\n");
}

case 20: if(r%20 ==0)


{
printf("no. of 20 notes required is %d\n",r/20);
}
else{
printf("all the money can not be given in this particular type of notes
\n");
}

case 50: if(r%50 ==0)


{
printf("no. of 50 notes required is %d\n",r/50);
}
else{
printf("all the money can not be given in this particular type of notes\n
");
}

case 100: if(r%100 ==0)


{
printf("no. of 100 notes required is %d\n",r/100);
}
else{
printf("all the money can not be given in this particular type of notes\n
");
}

case 500: if(r%500 ==0)


{
printf("no. of 500 notes required is %d\n",r/500);
}
else{
printf("all the money can not be given in this particular type of notes\n
");
}
case 1000: if(r%1000 ==0)
{
printf("no. of 1000 notes required is %d\n",r/1000);
}
else{
printf("all the money can not be given in this particular type of notes\n
");
}

case 2000: if(r%2000 ==0)


{
printf("no. of 2000 notes required is %d\n",r/2000);
}
else{
printf("all the money can not be given in this particular type of notes\n
");
}

}
return 0;
}

Output

You might also like