Write a C program to calculate x(y+z) by using user defined function


#include<stdio.h>
void power(int x,int y, int z);
void main()
{
 int x,y,z;
 printf("Enter value of x: ");
 scanf("%d",&x);
 printf("Enter value of y: ");
 scanf("%d",&y);
 printf("Enter value of z: ");
 scanf("%d",&z);
 power(x,y,z);
}
void power(int x,int y, int z)
{
 int ans = 1, i;
 for(i = 1; i <= (y+z); i++)
  ans *= x;
 printf("%d ^ (%d+%d) = %d",x,y,z,ans);
}

/* output
Enter value of x: 1
Enter value of y: 2
Enter value of z: 3
1 ^ (2+3) = 1 */

write a menu driven prodram in 'c' which performs the following ,operations on string . write separate function for each option.


program name:- write a menu driven prodram in 'c' which performs the following ,operations on string . write separate function for each option,
               -cheak if one string is substring of another string ,
               -count number of occurrences of acharacter in the         string,
               -Exit.

#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
int ch;
char str1[30],str2[30],occ;
int i=0,cnt=0;
clrscr();
while(1)
{
printf("\n menues");
printf("\n1. check if one string is substring of another string");
printf("\n2. count number of occurrences of characters in the string");
printf("\n3.exit");
printf("\nEnter Your choice: ");
scanf("%d",&ch);
switch(ch)
{
case 1:printf("\n enter the first string");
               scanf("%s",str1);
               printf("\n enter the second string");
               scanf("%s",str2);
               if(strstr(str1,str2)==NULL)
                        {
                         printf("\n  second string is not substring of first string");
                         }
                         else
                         {
                                    printf("\n  second string is  substring of first string");

                          }

               break;
case 2:
                        printf("\n enter the string");
                        scanf("%s",&str1);
               printf("\n enter the  character to find occurences");
               scanf("%s",&occ);
               i=0,cnt=0;
               while(str1[i]!='\0')
                        {
                         if(str1[i]==occ)
                        {
                         cnt++;
                         }
                         i++;
                        }

               printf("\n the number of occurencs is %d",cnt);
               break;
case 3:exit(0);
              }
              }
               getch();
              }
   /*output
 menues
1. check if one string is substring of another string
2. count number of occurrences of characters in the string
3.exit
Enter Your choice: 1

 enter the first stringindia
enter the second stringind

  second string is  substring of first string
 menues
1. check if one string is substring of another string
2. count number of occurrences of characters in the string
3.exit
Enter Your choice: 2

 enter the stringmaharashtra
enter the  character to find occurencesa

 the number of occurencs is 4
 menues
1. check if one string is substring of another string
2. count number of occurrences of characters in the string
3.exit */

Write a ‘C’ Program to accept ‘n’ numbers and store all prime numbers in an array and display this array


#include<stdio.h>
#include<conio.h>
void main()
{
int a[10],n,i,j,sum=0,prime[10],t=0;
clrscr();
printf("Enter the value of n=");
scanf("%d",&n);
printf("Enter the array=\n");
for(i=0;i<n;i++)
{
printf("Enter number=%d",i);
scanf("%d",&a[i]);
}
for(i=0;i<n;i++)
{
sum=0;
for(j=2;j<a[i];j++)
{
if(a[i]%j==0)
{
sum=1;
break;
}
}
if(sum==0)
{
prime[t]=a[i];
t++;
}
}
printf("prime number is=");
for(i=0;i<t;i++)
{
printf("%d",prime[i]);
printf("\n");
}
getch();
}
/*out put:-
Enter the value of n=10
Enter the array=
Enter number=10
Enter number=13
Enter number=25
Enter number=27
Enter number=73
Enter number=44
Enter number=53
Enter number=55
Enter number=12
Enter number=20

prime number is=13
73
53
*/

Write a C program to calculate the x to the power y without using standard function.


#include<stdio.h>
#include<conio.h>
void main()
{
int i,x,y, ans;
clrscr();
ans=1;
printf("Enter the value of x");
scanf("%d", &x);
printf("Enter the value of y");
scanf("%d", &y);
for(i=1; i<=y; i++)
{
ans= ans*x;
}
printf(" %d to the power %d is %d", x, y, ans);
getch();
}
/* output
Enter the value of x2
Enter the value of y3
 2 to the power 3 is 8 */