-->

Facebook

Jasper Roberts - Blog

Saturday, April 4, 2015

Write a C Program to Find out length of string using strlen( ) function.

PRACTICAL-SET-5
2.   Find length of string using strlen( ) function

#include<stdio.h>
#include<conio.h>
#include<string.h>

void main()
{
int i;
char str[30];

clrscr();

printf("Enter the string:");
scanf("%s",&str);

i = strlen(str);

printf("Length of the entered string: %d",i);

getch();
}

OUTPUT:
String Length
String Length



Write a C program to count total words in text.

PRACTICAL-SET-5
1.   Write a program to count total words in text.

#include<stdio.h>
#include<conio.h>
#include<string.h>

void main()
{
    char s1[50];
    int i, count = 0;
    clrscr();

    printf("Enter the string:");
    scanf("%[^\n]s", s1);
    for (i = 0;s1[i] != '\0';i++)
    {
        if (s1[i] == ' ')
            count++;    
    }
    printf("Total words in entered string are: %d\n", count + 1);
getch();

}

OUTPUT:
c programs
string length

Friday, April 3, 2015

W.A.P to read array of integers and print it in reverse order.

Practical Set-4
W.A.P to read array of integers and print it in reverse order.

#include<stdio.h>
#include<conio.h>

void main()
{
   int n, i, j, a[100], b[100];

   printf("Enter the number of elements in array:\n");
   scanf("%d", &n);

   printf("Enter the array elements:\n");

   for (i = 0; i < n ; i++)
      scanf("%d", &a[i]);

   for (i = n - 1, j = 0; i >= 0; i--, j++)
      b[j] = a[i];

   for (i = 0; i < n; i++)
      a[i] = b[i];

   printf("Reverse array is:\n");

   for (i = 0; i < n; i++)
      printf("%d\n", a[i]);

   getch();
}

OUTPUT:
Enter the number of elements in array: 3
Enter the array elements:
3
1
2
Reverse array is:
2
1
3

Thursday, April 2, 2015

Write a C Program to given no in ascending order.

Practical Set - 4
5. Write a program to given no in ascending order.

#include<stdio.h>
#include<conio.h>

void main()
{
    int i, j, temp, n, number[30];
    clrscr();
    printf("\n How Many Numbers: \n");
    scanf("%d", &n);
    printf("Enter the numbers: \n");
    for (i = 0; i < n; ++i)
        scanf("%d", &number[i]);
    for (i = 0; i < n; ++i)
    {
        for (j = i + 1; j < n; ++j)
        {
            if (number[i] > number[j])
            {
                temp =  number[i];
                number[i] = number[j];
                number[j] = temp;
            }
        }
    }
    printf("Ascending order: \n");
    for (i = 0; i < n; ++i)
printf("%d\n", number[i]);

    getch();

}
OUTPUT:
How Many Numbers: 3
Enter the numbers: 
30
20
10
Ascending order:
10
20
30