PART B Programs 8879821
PART B Programs 8879821
Part B programs
1. WAP to check a number is palindrome or not
Sol: Refer the lab manual(page no. 17) for the program
2. WAP to find square root of a given number without using built in function.
Sol: Refer the lab manual(page no. 42) for the program
4. WAP to Print the number of vowels and consonants present in the string.
Sol:
#include <stdio.h>
#include<string.h>
int main()
{
char s[1000];
int i,vowels=0,consonants=0;
printf("Enter the string : ");
gets(s);
for(i=0;s[i];i++)
{
if((s[i]>=65 && s[i]<=90)|| (s[i]>=97 && s[i]<=122))
{
if(s[i]=='a'|| s[i]=='e'||s[i]=='i'||s[i]=='o'||s[i]=='u'||s[i]=='A'||s[i]=='E'||s[i]=='I'||s[i]=='O'
||s[i]=='U')
vowels++;
else
consonants++;
}
}
printf("vowels = %d\n",vowels);
printf("consonants = %d\n",consonants);
return 0;
}
Prof.Vidya Y, CSE,RNSIT 1
Computer programming lab
Prof.Vidya Y, CSE,RNSIT 2
Computer programming lab
return 0;
}
8. WAP to copy the contents of one string to another and print the count of no. of characters copied.
Sol:
#include<stdio.h>
int main()
{
char str1[80], str2[80];
int i;
printf("Input a string");
scanf("%s", str2);
Prof.Vidya Y, CSE,RNSIT 3
Computer programming lab
#include <stdio.h>
#include <string.h>
union student
{
char name[20];
char addr[20];
float sal;
int id;
};
int main()
{
union student record1;
strcpy(record1.name, "Rahul");
strcpy(record1.addr, "chennai");
record1.sal = 500000;
record1.id = 123;
Prof.Vidya Y, CSE,RNSIT 4
Computer programming lab
return 0;
}
Prof.Vidya Y, CSE,RNSIT 5