-->

Facebook

Jasper Roberts - Blog
Showing posts with label cpu(2110003) programs. Show all posts
Showing posts with label cpu(2110003) programs. Show all posts

Tuesday, December 13, 2016

Write a C program to print address of a variable

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

void main( )
{

int a;
clrscr();
printf(“Address of a = %u“,&a);
getch();

}

OUTPUT:
Address of a =64453

Tuesday, April 28, 2015

Write a program using pointer to compare two strings.

#include<stdio.h>

int compare_string(char*, char*);

main()
{
    char first[100], second[100], result;

    printf("Enter first string\n");
    gets(first);

    printf("Enter second string\n");
    gets(second);

    result = compare_string(first, second);

    if ( result == 0 )
      printf("Both strings are same.\n");
    else
      printf("Entered strings are not equal.\n");

    return 0;
}

int compare_string(char *first, char *second)
{
  while(*first==*second)
  {
     if ( *first == '\0' || *second == '\0' )
        break;

     first++;
     second++;
  }
  if( *first == '\0' && *second == '\0' )
     return 0;
  else
     return -1;
}

Output:
Enter first String:HI
Enter Second String:HI
Both string are same

Write a program using pointer to read an array if integer

#include<stdio.h>
void main()
{
int a[5]={5,4,6,8,9};
int *p=&a[0];
int i;

clrscr();

for(i=0;i<5;i++)
printf("%d",*(p+i));

for(i=0;i<5;i++)
printf(" %u\n",(p+i));

getch();
}

Write a function power that computes x raised to the power y for integer x and y and returns double type value.

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

int power(int a,int b);
void main()
 {
  int x,y;
  clrscr();
  printf("enter the x:");
  scanf("%d",&x);
  printf("enter the y:");
  scanf("%d",&y);
  power(x,y);
  getch();
 }
int power(int a,int b)
 {
  double c;
  c=pow(a,b);
  printf("\n ans=%lf",c);
  return 0;
 }

Write a program using pointer and function to determine the length of string.

#include<stdio.h>

#include<conio.h>
#include<stdio.h>
#include<conio.h>
void ptr();

void main()
{
clrscr();
ptr();
getch();
}
void ptr()
{

    char s[100];
    char *p;
    int length;

    printf("\n Enter the string:");
    scanf("%s",s);

    for(p=s;*p!='\0';p++);

    length=p-s;

    printf("Length of the string is::%d",length);
     }

Friday, April 10, 2015

Write a function find out maximum out of three numbers.

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

int largest()
{
int n1, n2, n3;
printf("\n ENTER THREE NUMBERS:");
scanf("%d",&n1);
printf("\n ENTER THREE NUMBERS:");
scanf("%d",&n2);
printf("\n ENTER THREE NUMBERS:");
scanf("%d",&n3);
printf("\n\n\t THE BIGGEST NUMBER IS: ");

if( (n1 > n2) && (n1 > n3) )
printf("%d", n1);
else if(n2 > n3)
printf("%d", n2);
else
printf("%d", n3);

printf("\n\n\t THE SMALlEST NMBER IS…: ");
if( (n1 < n2) && (n1 < n3) )
printf("%d", n1);
else if(n2 < n3)
printf("%d", n2);
else
printf("%d",n3);
 return 0;

}

void main()
{
clrscr();
largest();
getch();
}
Largest Numbers

Write a function program to add first N numbers.



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

void main()
{
    int n;
clrscr();
numbers(n);
getch();
}

int numbers(int n)
{
int sum = 0, i;

   printf("Enter the number of integers you want to add\n");
   scanf("%d", &n);

   for (i = 1; i <= n; i++)
   {
      sum = sum + i;
   }

   printf("Sum of entered integers = %d\n",sum);

   return 0;
}

Wednesday, April 8, 2015

Find given string is palingrom or not using string library function.

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

void main()
{
   char str1[50], str2[50];
   clrscr();

   printf("\n Enter the first string:");
   gets(str1);

   strcpy(str2,str1);
 
strrev(str2);

   if (strcmp(str1,str2) == 0)
{
      printf("Entered string is a palindrome.\n");
}
   else
{
      printf("Entered string is not a palindrome.\n");
}

 getch();
}
OUTPUT:
Enter the first string: rever
Entered string is a palindrome.

Write a C program to copy one string to another string.

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


void main()
{
   char str1[50], str2[50];
   clrscr();

  printf("\n enter first string:");
gets(str1);

  printf("\n enter second string:");
gets(str2);

  printf("\n Before Copy String s1 is: %s",str1);

strcpy(str1,str2);

   printf("\n After Copy String s1 is: %s", str1);

getch();
}
Write a C program to copy one string to another string.
Copy String

Write a program to join two strings.

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


void main()
{
   char str1[50], str2[50];

  printf("enter first string:");
gets(str1);

  printf("enter second string:");
gets(str2);

strcat(str1,str2);


   printf("String : %s", str1);

getch();
}
Write a program to copy one string to another string.
string copy

Saturday, April 4, 2015

Write a C Program to display the ASCII value of a given string.


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 progratcount 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

Thursday, April 2, 2015

Write a C Program to given no in ascending order.

Practical Set - 4
5. Write a prograto 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

Tuesday, March 31, 2015

Write a C Program to Add, subtract and multiply two nos. using switch statement.



PRACTICAL-SET-4
3.  Add, subtract and multiply two nos. using switch statement.


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

void main()
{
int num1,num2, choice;
clrscr();

printf("Enter the value of number1 : ");
scanf("%d",&num1);

printf("Enter the value of number2 : ");
scanf("%d",&num2);


printf("\n 1. Addition, ");
printf("\n 2. Substraction,");
printf("\n 3. Multiplication,  ");
printf("\n 4. Division.");

printf("\n Enter Your Choice:");
scanf("%d",&choice);

switch(choice)
{
case 1:
printf("%d + %d = %d",num1, num2, num1+num2);
break;

case 2:
printf("%d - %d = %d",num1, num2, num1-num2);
break;

case 3:
printf("%d * %d = %d",num1, num2, num1*num2);
break;
case 4:
printf("%d / %d = %d",num1, num2, num1/num2);
break;

default:
printf("Please enter the correct choise!!");
}
getch();

}

OUTPUT:
Enter the value of number1 : 10
Enter the value of number2 : 10
 1. Addition,
 2. Substraction,
 3. Multiplication,
 4. Division.

Enter Your Choice:1
10 + 10 = 20

Write a c program to reverse the digit.

PRACTICAL-SET-
2.  Write a prograto reverse the digit.


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

void main()
{
    int num,r,reverse=0;
    clrscr();

    printf("Enter the number: ");
    scanf("%d",&num);

    while(num)
{
         r=num%10;
         reverse=reverse*10+r;
         num=num/10;
    }

    printf("Reverse of a given number is = %d",reverse);
getch();
}

OUTPUT:
Enter the number:  1234
Reverse of a given number is = 4321

Thursday, March 12, 2015

Write a C program to convert km to meter, inch, cm and feet.

#include
#include

void main(){
float km,m,feet,inch,cm; 
printf("Enter the distance between two cities(in km) - ");
scanf("%f",&km);
m = km*1000; //since 1km = 1000m
feet= km*3280.84; //since 1km=3280.84feet
inch=km*39370.1; //since 1 km=39370.1inches
cm=km*100000; //since 1km = 100000cm
printf("\nDistance in kilometres = %f ",km);
printf("\nDistance in metres = %f ",m);
printf("\nDistance in feet = %f ",feet);
printf("\nDistance in inches = %f ",inch);
printf("\nDistance in centimetres = %f ",cm);
getch();
}

go to statement in c programming language.

- In c programming language, if statement, if...else statement, switch statements provides conditional jumps.
- A goto statement in C programming language provides an unconditional jump from the goto to a labeled statement in the same function.
- Use of goto statement is highly discouraged in c programming language.
- Because it makes difficult to trace the control flow of a program making the program hard to understand and debug.

- Syntax:
goto label;
.
.
.
label: statement;

-Example:

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

void main()
{

  int number = 10;

  A:
       do
       {
          if( number == 15)
      {
         number = number + 1;
         goto A;
      }
      printf("\n value of number is: %d",number);
      number++;
   
   }while( number < 20 );

   getch();
}

OUTPUT:
value of number is:11
value of number is:12
value of number is:13
value of number is:14
value of number is:15
value of number is:16
value of number is:17
value of number is:18
value of number is:19

Write a C Program to reverse the given number.

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

void main()
{
  int number,rem;
  int reverse=0;
  printf("Enter an integer number: ");
  scanf("%d", &number);
  while(number!=0)
  {
     rem=number%10;
     reverse=reverse*10+rem;
     number=number/10;
  }
  printf("Reversed Number = %d",reverse);
  getch();
}

OUTPUT:
Enter an integer number: 123
Reversed Number = 321

Thursday, February 26, 2015

Write a C Program which explaining Shorthand Notations.

// C Program which explaining Shorthand Notations.

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

void main()
{
         int i;
         clrscr();
         printf("Enter the value of i:");
         scanf("%d",&i);
       
         i += 5;
         printf("\n i = %d",i);