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. }