Showing posts with label Enter by User. Show all posts
Showing posts with label Enter by User. Show all posts

C Program to Calculation of One Number Raised to Another

How to write a C Program to Calculation of One Number Raised to Another in C Programming Language ?

Two numbers are entered through the keyboard. Write a program to find the value of one number raised to the power of another. 


  1. #include<stdio.h>
  2. main()
  3. {
  4. int num1, index, result, temp; /* num2=index*/
  5.  
  6. printf("Enter the number:");
  7. scanf ("%d", &num1);
  8.  
  9. printf("Enter the index:");
  10. scanf("%d", &index);
  11.  
  12. result=1;
  13. temp=1;
  14.  
  15. while(temp<=index)
  16.  
  17. {
  18. result = result*num1;
  19.  
  20. temp++;
  21.  
  22. }
  23.  
  24. printf("%d raised to %d is: %d ", num1, index, result);
  25.  
  26. }


Another C Program to Calculation of One Number Raised to Another:



  1. #include
  2.  
  3. main()
  4. {
  5. int i,n,res;
  6. printf("Enter the Num:");
  7. scanf("%d", &n);
  8. printf("Enter the index:");
  9. scanf("%d", &i);
  10. res=pow(n,i);
  11. printf("The number " %" raised to the power " %"is "%"==" %d, n,i,res );
  12. }
  13. }

C Program to Calculation of One Number Raised to Another:


  1. #include
  2. main()
  3. {
  4. int a,b,c,d;
  5. printf("Enter two numbers separated by space: ");
  6. scanf("%d%d",&a,&b);
  7. = pow(a,b);
  8. printf("The value of, %d raised to the power of %d is %d",a,b,c);
  9. }

C Program to Count Vowels, Consonants and Spaces in a string

C Program to count vowels, consonants and spaces in a string in C Programming Language ?

This C Program to Count Vowels, Consonants and Spaces in a string.
In this C Program the Sentence is Entered by the User and the C Program then Count Vowels, Consonants and Spaces in a String.

To Find:
  1. Total number of vowels entered.
  2. Total number of consonants entered.
  3. Total number of spaces entered.

Solution:

  1. #include<stdio.h>
  2. main()
  3. {
  4. int i,cons=0,vow=0,sp=0;
  5. char a[100];
  6. printf("Enter the sentence\n");
  7. gets(a);
  8. for(i=0;a[i]!='\0';i++)
  9. {
  10. if(a[i]=='a'||a[i]=='A')
  11. vow=vow+1;
  12. else if(a[i]=='e'||a[i]=='E')
  13. vow=vow+1;
  14. else if(a[i]=='i'||a[i]=='I')
  15. vow=vow+1;
  16. else if(a[i]=='o'||a[i]=='O')
  17. vow=vow+1;
  18. else if(a[i]=='u'||a[i]=='U')
  19. vow=vow+1;
  20. else if(a[i]==' ')
  21. sp=sp+1;
  22. else
  23. cons=cons+1;
  24. }
  25. printf("Total number of vowels entered = %d\n",vow);
  26. printf("Total number of consonants entered = %d\n",cons);
  27. printf("Total number of spaces entered = %d\n",sp);
  28. }

C Program to calculate Area, Perimeter of Rectangle; Area, Circumference of Circle.


How to write a C Program to calculate Area, Perimeter of Rectangle; Area, Circumference of Circle in C Programming Language ?

Solution:
  1. The program helps you calculate the area and perimeter of a rectangle.
  2. It also calculates the area and the circumference of the circle.
  3. The values of Length, Breadth and Radius are to be entered through the keyboard.
The length and breadth of a rectangle and radius of a circle are input through the keyboard. Write a program to calculate the area and perimeter of the rectangle, and the area and the circumference of the circle.

/*
aor: area of rectangle
por: perimeter of rectangle
aoc: area of circle
coc: circumference of circle
*/

The circumference of a circle is same as the perimeter that is the distance around the outer edge. 

The formula of circumference is = 2 pi r (pi's symbol) 
where r = the radius of the circle 
and pi = 3.14(Approx)


  1. #include <stdio.h>

  2. //C program to find Area and Circumference of a Circle with Sample Input and Output.

  3. main()
  4. {
  5. float length, breadth, radius, aor, por, aoc, coc;
  6.  
  7. printf ("\nEnter the Length and Breadth of the Rectangle: ");
  8. scanf("%f %f", &length, &amp;breadth);
  9.  
  10. printf("\nEnter the Radius of the Circle: ");
  11. scanf("%f", &radius);
  12.  
  13. aor = length*breadth;
  14. por= 2*(length+breadth);
  15.  
  16.  
  17. aoc = 3.14*radius*radius;
  18.  
  19. coc = 2*radius*3.14;
  20.  
  21. printf("\nThe area of the rectangle is: %f", aor);
  22.  
  23. printf("\nThe perimeter of the rectangle is: %f ", por);
  24.  
  25.  
  26. printf("\n\nThe area of the Circle with radius %f is: %f ", radius, aoc);
  27.  
  28. printf("\nThe circumference of the same circle is: %f", coc);
  29.  
  30. }

C Program to find result where value and power are user given

How to Write a C Program to find result where value and power are user given in C Programming Language ?


Solution:

  1. #include <stdio.h>
  2. #include <conio.h>
  3. void main()
  4. {
  5.  int a,p,n,r;
  6.  clrscr();
  7.  printf("Enter Number: ");
  8.  scanf("%d",&n);
  9.  printf("\nEnter Power: ");
  10.  scanf("%d",&p);
  11.  for(a=p;a!=0;a--)
  12.  {
  13.   r=n*n;
  14.  }
  15.  printf("%d",r);
  16.  getch();
  17. }

C Program That in a Given Natural Number x Insert Figure c at Position p

How to Write a program that in a given natural number x insert figure c at position p . The numbers x , c and p are entered from standard input . 


For example , x = 140 , c = 2 , p = 2 , the result is the 1420th


Solution:
  1. #include<stdio.h>
  2. #include<math.h>

  3. int main() {
  4.         int x,c,p,i,y,d;
  5.         scanf("%d%d%d", &x,&c,&p);
  6.         printf("Number: %d, figure %d, required position: %d\n", x,c,p);
  7.         i=1;   
  8.         y=10;  
  9.         if(i==p){
  10.                 x=x*10;
  11.                 x=x+c;
  12.                 printf("X: %d\n", x);
  13.         }
  14.         while(i<p){
  15.         i++;
  16.         c=c*10;
  17.                 if(i==p){
  18.                 d=x%y;
  19.                 x=x-d;
  20.                 x=x*y;
  21.                 x=x+c+d;
  22.                 printf("X: %d\n", x);  
  23.                 }
  24.         y=10*y;
  25.         }
  26.                
  27.  
  28.         return 0;
  29. }

C Program To Find Prime Number And If Number Is Not Prime Then Find Factors

Write a C program to find prime number and if number is not prime then find factors of the number in C Programming Language ?


Solution:

  1. #include <stdio.h>
  2. #include <conio.h>
  3. void main()
  4. //C Program to Check whether the Given Number is a Prime
  5. //C program to display all the factors of a number entered by user.
  6. {
  7.  int flag=0,i,n,r,a[100],b=0,s;
  8.  clrscr();
  9.  printf("\n Enter Number: ");
  10.  scanf("%d",&n);
  11.  for(i=2;i<=n/2;i++)
  12.  {
  13.   r=n%i;
  14.   if(r==0)
  15.   {
  16.    flag=s;
  17.    a[b]=i;
  18.    b++;
  19.   }
  20.  }
  21.  if(flag==s)
  22.  {
  23.   printf(" So The Number %d is not prime",n);
  24.   printf("\n The factors are: ");
  25.   for(i=0;i<b;i++)
  26.   {
  27.    printf("%d ",a[i]);
  28.   }
  29.  }
  30.  else
  31.  {
  32.   printf("\n So The Number %d is prime",n);
  33.  }
  34.  getch();
  35. }