0% found this document useful (0 votes)
68 views

Lab Assignment 5: Task-01

The document contains code for 7 tasks related to C programming assignments on strings and arrays. Task 1 checks the type of character entered. Task 2(a) and 2(b) encrypt and decrypt characters in an array. Task 3 counts different types of characters in an array. The remaining tasks involve string manipulation functions like reverse, substring, capitalization etc.
Copyright
© © All Rights Reserved
0% found this document useful (0 votes)
68 views

Lab Assignment 5: Task-01

The document contains code for 7 tasks related to C programming assignments on strings and arrays. Task 1 checks the type of character entered. Task 2(a) and 2(b) encrypt and decrypt characters in an array. Task 3 counts different types of characters in an array. The remaining tasks involve string manipulation functions like reverse, substring, capitalization etc.
Copyright
© © All Rights Reserved
You are on page 1/ 9

LAB ASSIGNMENT 5

Task-01
#include<stdio.h>
#include<string.h>
int main()
{
char ch;
printf("Enter a character: ");
scanf("%d",&ch);
if(ch>=65&&ch<=90)
printf("\nType: Capital letter");
else if(ch>=97&&ch<=122)
printf("\nType: Small letter");
else if(ch>=48&&ch<=57)
printf("\nType: Digit");
else
printf("Character you entered is not a capital letter, neither small letter nor digit");
getchar();
return 0;
}
Task-02(a)

#include<stdio.h>
#include<string.h>
#include<conio.h>
int main()
{
char A[5],enc[5];
int i,d;//d is for distance
for(i=0;i<5;i++)
{
printf("\nenter elements you want to encrypt: \n");
A[i]=getche();
}
printf("\nenter the distance you want for encryption\n");
scanf("%d",&d);
for(i=0;i<5;i++)
{
enc[i]=A[i]+d;
if(enc[i]>122)
enc[i]-=26;
}
for(i=0;i<5;i++)
{
printf("\nEncrypted array is: %c ",enc[i]);
}
getchar();
return 0;
}

Task-02(b)

#include<stdio.h>
#include<string.h>
#include<conio.h>
int main()
{
char A[5],enc[5];
int i,d; //d is for distance
for(i=0;i<5;i++)
{
printf("\nenter elements you want to de-encrypt: \n");
A[i]=getche();
}
printf("\nenter the distance you want for de-encryption\n");
scanf("%d",&d);
for(i=0;i<5;i++)
{
enc[i]=A[i]-d;

if(enc[i]<97)
enc[i]+=26;
}
for(i=0;i<5;i++)
{
printf("\nDe-encrypted array is: %c ",enc[i]);
}
getchar();
return 0;
}
Task-03
#include<stdio.h>
#include<string.h>
#include<conio.h>
int main()
{
char array[500];
int i,b=0,c=0,d=0,e=0;
for(i=0;i<500;i++)
{
printf("\nEnter the elements of array\n");
array[i]= getche();
}
for(i=0;i<strlen(array);i++)
{
if(array[i]>=48 && array[i]<=57)
b++;
else if(array[i]>=97 && array[i]<=122)
c++;
else if(array[i]>=65 && array[i]<=90)
d++;
else
e++;
}
printf("\nIntegers are %d\n",b);
printf("Small alphabets are %d\n",c);
printf("Capital alphabet are %d\n",d);
printf("Others are %d\n",e);
getchar();
return 0;
}
Task-01
#include<stdio.h>
#include<conio.h>
#include<string.h>
int main()
{
char name[100], roll[200];
puts("\nEnter your name\n");
puts("\nEnter the roll no.\n");
scanf("%s%s",name,roll);
printf("your name is: %s, and roll no. %s",name,roll);
getchar();
return 0;
}

Task-01(modified)

#include<stdio.h>
#include<conio.h>
#include<string.h>
int main()
{
char name[100], roll[200];
puts("\nEnter your name\n");
puts("\nEnter the roll no.\n");
gets(name);
gets(roll);
printf("your name is: %s, and roll no. %s",name,roll);
getchar();
return 0;
}
Task-02

#include<stdio.h>
#include<string.h>
#include<conio.h>
int main()
{
char A[100], rev[100];
int i;

puts("enter elements of array you want to reverse\n");


gets(A);

for(i=0;i<strlen(A);i++)
{
rev[strlen(A)-1-i]=A[i];
}
for(i=0;i<5;i++)
printf("\nelements of reverse array is: %c\n",rev[i]);
getchar();
return 0;
}

Task-03

#include<stdio.h>
#include<string.h>
int main()
{
char array[200];
printf("\nEnter elements of array: \n");
gets(array);
printf("Length of string is: %d\n",strlen(array));
printf("\nFirst character is: " );
putchar(array[0]);
printf("\nLast character is: ");
putchar(array[strlen(array)-1]);
getchar();
return 0;
}

Task-04
#include<stdio.h>
#include<conio.h>
#include<string.h>
int main()
{
char A[200];
int b=0,c=0,d=0,e=0,i;
puts("Enter complete home address: \n");
gets(A);
for(i=0;i<strlen(A);i++)
{
if(A[i]>=48 && A[i]<=57)
b++;
else if(A[i]>=97 && A[i]<=122)
c++;
else if(A[i]>=65 && A[i]<=90)
d++;
else
e++;
}
printf("\nThe integer are %d\n",b);
printf("The small alphabet are %d\n",c);
printf("The capital alphabet are %d\n",d);
printf("The others are %d\n",e);
getchar();
return 0;
}

Task-05

#include<stdio.h>
#include<string.h>
#include<conio.h>
int main()
{
char A[100];
int i,length, st_point;
puts("Please enter the string:");
gets(A);
printf("Please enter length of substring: \n");
scanf("%d",&length);
printf("Please enter starting point of substring: \n");
scanf("%d",&st_point);
printf("Substring is: \n");
for(i=st_point-1;i<length;i++)
{
printf("%c",A[i]);
}
getchar();
return 0;
}

Task-06
#include<stdio.h>
#include<string.h>

int main()
{
char A[100];
int a,s,d,e=0,count=1;
printf("Enter elements of array:");
gets(A);
printf("Enter your choices\n1 First Captial\n2 All capital\n 3 first letter of word capital\n 4 Word
count\n");
scanf("%d",&s);
switch(s)
{
case 1:
if(A[a]>='a' && A[a]<='z')
A[0]=A[0]-32;
printf("The string is \n");
puts(A);
break;

case 2:
for(a=0;a<strlen(A);a++)
{
if(A[a]>='a' && A[a]<='z')
{
A[a]=A[a]-32;
}
}
printf("The string is \n");
puts(A);
break;

case 3:
for(a=0;a<strlen(A);a++)
{
if((A[a]==' ') && (A[a+1]>='a' && A[a+1]<='z'))
{
A[a+1]=A[a+1]-32;
}
}
printf("The string is \n");
puts(A);
break;
case 4:
for(a=0;a<strlen(A);a++)
{
if(A[a]==' ')
count++;
}
printf("%d",count);
break;
}
getchar();
getchar();
}

Task-07
#include<stdio.h>
#include<string.h>
int main()
{
char array[100],A;
int i,j;

printf("Enter elements of array: ");


gets(array);

for (i=0;i<strlen(array);i++)
{
for (j=0;j<strlen(array)-1;j++)
{
if(array[j+1]<array[j])
{
A=array[j+1];
array[j+1]=array[j];
array[j]=A;
}
}
}
printf("New order of array is: ");
puts(array);
getchar();
return 0;
}

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy