Wednesday, November 25, 2015

Reads a sentence and prints frequency of each of the vowels and total count of consonants

#include<stdio.h>
#include<conio.h>
int main(){
    char text[100];
    int i,vowel=0,cons=0;
    clrscr();
    printf("Enter a string:\n");
    gets(text);
    for(i=0;text[i]!='\0';++i)
    {
if(text[i]=='a' || text[i]=='e' || text[i]=='i' || text[i]=='o' || text[i]=='u' || text[i]=='A' || text[i]=='E' || text[i]=='I' || text[i]=='O' || text[i]=='U')
{
   ++vowel;
}
else if((text[i]>='a'&& text[i]<='z') || (text[i]>='A'&& text[i]<='Z'))
{
   ++cons;
}
    }
    printf("Vowels: %d",vowel);
    printf("\nConsonants: %d",cons);
    getch();
    return 0;
}

To Compile Press Alt+f9 
To Run Press Ctrl+f9

Output:



Copy String Without Using Library Function

#include<stdio.h>
#include<conio.h>
void STRCOPY(char[],char[]);
int main()
{
     char str1[100], str2[100];
     clrscr();
     printf("Enter String to Copy: \n");
     gets(str1);
     STRCOPY(str1,str2);
     printf("Copied Sentence : %s", str2);
     getch();
     return 0;
}

void STRCOPY(char str1[],char str2[])
{
     int i=0;
     if(str1 != "")
     {
  while(str1[i] != '\0')
  {
     str2[i] = str1[i];
     i++;
  }
     }
     str2[i] = '\0';
}

To Compile Press Alt+f9 
To Run Press Ctrl+f9

Output:



Write a C program to maintain a record of “n” student details using an array of structures with four fields (Roll number, Name, Marks, and Grade). Each field is of an appropriate data type. Print the marks of the student given student name as input

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<conio.h>
struct student{
char name[14];
int rollNo;
int marks[3];
float percentage;
};

int main(){
struct student *stuArray;
int n,i,j;
int tempTotal=0,flag=0,foundIndex;
char tempName[14];
clrscr();
printf("\n No of Students: ");
scanf("%d",&n);
stuArray = (struct student*)malloc(n*sizeof(struct student));
for(i=0;i<n;i++){
printf("\n %d.Name :",(i+1));
scanf("%s",&stuArray[i].name);
printf("\n Roll Number :",(i+1));
scanf("%d",&stuArray[i].rollNo);
tempTotal=0;
for(j=0;j<3;j++)
{
printf("\n Mark %d :",(j+1));
scanf("%d",&stuArray[i].marks[j]);
tempTotal+=stuArray[i].marks[j];
}
stuArray[i].percentage=tempTotal/3;
}

printf("\n Enter the Name to be Searched: ");
scanf("%s",&tempName);
for(i=0;i<n;i++){
if(strcmp(tempName,stuArray[i].name)==0)
{
foundIndex=i;
flag=1;
break;
}
}
if(flag==0)
{
printf("Details Not Found");
}
else
{
printf("\n Mark of %s are given below...",tempName);
for(i=0;i<3;i++)
{
printf("\n Mark %d is %d",(i+1),stuArray[foundIndex].marks[i]);
}
}
getch();
return 0;
}

To Compile Press Alt+f9 
To Run Press Ctrl+f9

Output:


Friday, November 6, 2015

Find The Number Using Linear Search - Working Code

#include<stdio.h>
#include<conio.h>
int main()
{
    int i,num,search,flag,arr[10];
    clrscr();
    printf("Enter the total number of input: \n");
    scanf("%d",&num);
    for(i=0;i<num;i++)
    {
printf("Enter the number %d \n",i+1);
scanf("%d",&arr[i]);
    }
    printf("Enter the number to search \n");
    scanf("%d",&search);
    for(i=0;i<num;i++)
    {
if(arr[i] == search)
{
     printf("The given number %d is located at position %d \n",search, i+1);
     flag = 1;
     break;
}
    }
    if(flag == 0)
       printf("Sorry, the given number %d is not present in the array \n",search);
    getch();
    return 0;
}


To Compile Press Alt+f9 
To Run Press Ctrl+f9

Output:



Monday, November 2, 2015

Sorting Given Number In Ascending Order - Working Code

#include<stdio.h>
#include<conio.h>
void main()
{
   int i,j,num,temp,arr[20];
   clrscr();
   printf("Enter The Total Number Of Values For Sorting: \n");
   scanf("%d",&num);
   for(i=0;i<num;++i)
   {
printf("Enter Number %d: \n",i+1);
scanf("%d",&arr[i]);
   }

   for(i=1;i<num;i++)
   {
for(j=0;j<num;j++)
{
    if(arr[i]<arr[j])
    {
temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
    }
}
   }
   printf("The Given Number In Ascending Order Are: \n");
   for(i=0;i<num;i++)
   {
       printf("%d\n",arr[i]);
   }
   getch();
}

To Compile Press Alt+f9 
To Run Press Ctrl+f9

Note: For sorting descending number, change arr[i]<arr[j] to arr[i]>arr[j]

Output:


Find Largest Number In A Given Array - Working Code

#include<stdio.h>
#include<conio.h>
void main()
{
    int i,arraySize, arr[10];
    clrscr();
    printf("Enter Values to Insert Into Arrays \n");
    scanf("%d",&arraySize);
    for(i=0;i<arraySize;i++)
    {
       printf("Enter the Number %d:",i+1);
       scanf("%d",&arr[i]);
    }
    for(i=1;i<arraySize;i++)
    {
       if(arr[0] < arr[i])
       arr[0] = arr[i];
    }
    printf("Largest Number is %d",arr[0]);
    getch();
}

To Compile Press Alt+f9 
To Run Press Ctrl+f9

Output: