ads

Write a Program in C to Copy a String to Another.


Here is a program in C to copy one string to another string using user defined function. Here two character arrays are defined then prompted to enter the strings and copied to the first string using while() function.

Program in C to Copy a String to Another



Program in C to Copy a String to Another



Steps:
  1. At first  declare two strings str1 and str2 and integers m, i, flag and j under main function.
  2. Prompt message to enter the strings and allow to enter strings using gets() function.
  3. Prompt the message and allow to enter the index where you want to insert in the first string.
  4. Copy second string to the first string using while() function.
  5. Print the first string to the screen.



Code:

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

void main()
{
char str1[20], str2[20];
int m,i,flag=0,j;

clrscr();

printf("Enter the 1st String");
gets(str1);
printf("Enter the 2nd String");
gets(str2);

printf("Enter the index after which you want to insert 2nd string in 1st :");
scanf("%d", &m);
i=0;

while (i<=m)
{
i++;
}
j=0;

while (str2[j]!='\0')
{
str1[i]=str2[j];
i++;
j++;
if (str1[i]=='\0')
flag=1;
}

if (flag==1)
str1[i]='\0';
printf("%s", str1); 
getch();
} 




Related Posts:


C Program to Read Set of Real Numbers from Keyboard & Find the Maximum


C Program to Read Set of Real Numbers and Find the Maximum
To write a C program to read set of real numbers from keyboard and find the maximum among them, you can use a function which takes an array of real numbers and its size as arguments and return the maximum.


Using this function you can write a program to read a set of real numbers from the keyboard and find the maximum number in the array.






C Program to Read Set of Real Numbers and Find the Maximum



Steps: 
  1. Define a function max() 
  2. Under main() function, declare two integers i and n.
  3. Declare an array a.
  4. Prompt the message to the user to insert how many elements they want to enter using printf() and allow to enter using scanf().
  5. Prompt the message and allow to enter the elements.
  6. Find out the maximum number among them using max() function.
  7. Print the maximum number along with message.

Code:


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

max(float a[], int n);

void main()
{

int i,n;
float a[100];


printf("\n How many elements you want to enter:\n");
scanf("%d",&n);

printf("\n Enter the elements:");
for(i=0;i<n;i++)
scanf("%f",&a[i]);
max(a,n);
getch();
}

max(float a[], int n)

{
int i;
float k, large;
large=a[0];
for (i=1;i<n;i++)
{
if (a[i]>large)
{
k=a[i];
a[i]=large;
large=k;
}
}

printf("Largests element is : %f", large);

return 0;

}


 

Related Posts: 


Write a Program in C to Determine Whether a Number is Prime or Not.


Program in C to Determine Whether a Number is Prime or Not.
"A prime number is one, which is divisible only by 1 or itself."

To determine whether a number is prime or not, we have to divide the number successively by all numbers from 2 to one less than itself.

If remainder of any of these divisions is zero, the number is not a prime.

If no division yields a zero then the number is a prime number.



Program in C to Determine Whether a Number is Prime or Not


Steps:

  1. Declare integers num and i inside main()
  2. Prompt the message allow the input using printf() and scanf()
  3. Test whether a Number is prime or not using while() function.

Code:

#include <stdio.h>

int main()
{

int num, i;


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

i=2;

while (i<=num-1)
{

if (num%i==0)
{
printf("Not a prime number\n");
break;
}

i++;
}

if (i==num)

printf("Prime number\n");

return 0;
}



Related Posts: 



Solved MCQ of Data Warehouse set-3


OLAP Cube illustration
OLAP Cube illustration (Photo credit: Wikipedia)

1. Data warehouse architecture is based on .......................

A) DBMS

B) RDBMS

C) Sybase





2. .......................... supports basic OLAP operations, including slice and dice, drill-down, roll-up and pivoting.

A) Information processing

B) Analytical processing

C) Data mining

D) Transaction processing




3. The core of the multidimensional model is the ....................... , which consists of a large set of facts and a number of dimensions.

A) Multidimensional cube

B) Dimensions cube


D) Data model




4. The data from the operational environment enter ........................ of data warehouse.

A) Current detail data

B) Older detail data

C) Lightly Summarized data

D) Highly summarized data




5. A data warehouse is ......................

A) updated by end users.


B) contains numerous naming conventions and formats


C) organized around important subject areas


D) contain only current data




6. Business Intelligence and data warehousing is used for ..............

A) Forecasting


C) Analysis of large volumes of product sales data

D) All of the above




7. Data warehouse contains ................ data that is never found in the operational environment.

A) normalized

B) informational

C) summary

D) denormalized





8. ................... are responsible for running queries and reports against data warehouse tables.

A) Hardware

B) Software

C) End users

D) Middle ware




9. The biggest drawback of the level indicator in the classic star schema is that is limits ............

A) flexibility

B) quantify

C) qualify

D) ability





10. ............................. are designed to overcome any limitations placed on the warehouse by the nature of the relational data model.


B) Relational database

C) Multidimensional database

D) Data repository






Answers:




1. Data warehouse architecture is based on .........................

B) RDBMS


2. .......................... supports basic OLAP operations, including slice and dice, drill-down, roll-up and pivoting.

B) Analytical processing


3. The core of the multidimensional model is the ....................... , which consists of a large set of facts and a number of dimensions.

C) Data cube



4. The data from the operational environment enter ........................ of data warehouse.

A) Current detail data


5. A data warehouse is ......................

C) organized around important subject areas


6. Business Intelligence and data warehousing is used for ..............

D) All of the above


7. Data warehouse contains ................ data that is never found in the operational environment.

C) summary


8. ................... are responsible for running queries and reports against data warehouse tables.

C) End users



9. The biggest drawback of the level indicator in the classic star schema is that is limits ............

A) flexibility


10. ............................. are designed to overcome any limitations placed on the warehouse by the nature of the relational data model.

C) Multidimensional database





Related posts