pps week 10 h
pps week 10 h
HTNO : 24R21A05D6
BRANCH : CSE
SECTION : D
PROBLEM STATEMENT:
#include<stdio.h>
#include<string.h>
int main()
char str1[100],str2[100],str3[100];
int n;
scanf("%s",str1);
strcpy(str2,str1);
scanf("%d",&n);
strncpy(str3,str2,n);
return 0;
PROBLEM STATEMENT :
Write a C program that will demonstrate the use of calloc() or malloc() for
dynamic memory allocation and realloc() for resizing the allocated
memory.
C Program:
#include<stdio.h>
#include<stdlib.h>
int main(){
int n,m,*ptr,i;
scanf("%d",&n);
ptr=(int*)calloc(n,sizeof(int));
if(ptr==NULL)
return 1;
for(i=0;i<n;i++)
scanf("%d",(ptr+i));
scanf("%d",&m);
ptr=(int*)realloc(ptr,(n+m)*sizeof(int));
if(ptr==NULL)
return 1;
}
for(i=n;i<n+m;i++)
scanf("%d",(ptr+i));
for(i=0;i<n+m;i++)
printf("%d ",*(ptr+i));
free(ptr);
return 0;
PROBLEM STATEMENT :
Write a program to find the length of a given string without
using strlen() function.
Logic: while(str[i]!='\0'),i++
C Program:
#include<stdio.h>
#include<string.h>
int main()
char str[100];
int i=0;
scanf("%s",str);
while(str[i]!='\0'){
i++;
return 0;