Posts

Showing posts from 2016

Calculating Radius, Diameter, Circumference , Area and Length of a Circle

Image
Write a program that asks a user to input the radius and degree of a circle, the program reads it in and calculates: The radius, Diameter, Circumference, Area and Length of a circle. SOLUTION #include<stdio.h> #include<stdlib.h> /*function main begins program execution */ int main( void ) { /*Initialization phase */     int radius ;    // radius to be entered by the user     int degree ;  // degree to be entered by the user   /*Processing phase * /     printf ( "Insert radius and degree of the circle:" );  /*Prompting for input */     scanf ( "%d%d" , & radius , & degree );   /*reading radius and degree from user */     printf ("Radius is:%f\n" , radius*1.0);  /*displaying result       printf( "Diameter is:%f\n" , radius*2.0);  /*displaying result      ...

Function Maximum and Minimum

Image
Write a program that asks a user to input 3 separate integer, the program reads it and determines the maximum and minimum integer. Understanding Functions Modules in C are called functions . C programs are typically written by combining new functions you write with prepackaged functions available in the C standard library . The C standard library provides a rich collection of functions for performing common mathematical calculations , string manipulations , character manipulations , input/output , and many other useful operations. This makes your job easier, because these functions provide many of the capabilities you need. Functions are invoked by a function call , which specifies the function name and provides information (as arguments) that the function needs to perform its designated task. for more on functions click here Solution / *Finding the maximum/minimum of three integers */ #include<stdio.h> int maximum ( int x , int y , int z ); ...

Using the For Statement to Add

Image
Understanding the For Repetition statement Before we use the For Repetition Statement to add numbers, we need to understand what the For Statement really mean and does. The for statement is part of the control statement in C functions. The for statement is required for counter-controlled repetitions. C provides the For statement which specifies the counter-controlled-repetition. Counter-Controlled repetition is often called definite repetition, because the number of repetition terminates when the counter imputed is complete. SOLUTION  // How to Add with the For Selection statement  #include<stdio.h> /*function main begins program execution */ int main ( void ) { /*Initialization phase */     int sum = 0 ;    /*Initializing total */     int x ;   /*no of grade to be entered */ /*Processing phase */     for ( x = 3 ; x <= 1000 ; x += 3 ){    ...

Separating Integers

Image
Write  a program that inputs one five-digits number, separates the number into its individual digits and prints the digits from one another by three spaces each. solution #include<stdio.h> int main( void ) {     /*Starting numbers */     int n ;     int one , two , thr,fov,fiv ;     printf ( "Enter a five digits:" );     scanf ( "%d" , & n );     one = n / 10000 ;     two =( n % 10000 )/ 1000 ;     thr =(( n % 10000 )% 1000 )/ 100 ;     fov =((( n % 10000 )% 1000 )% 100 )/ 10 ;     fiv =(((( n % 10000 )% 1000 )% 100 )% 10 )/ 1 ;     printf ( "%d   %d   %d   %d   %d\n", one, two, thr, fov, fiv );     return 0 ; }

Adding And Subtracting N numbers

Image
Write  a program that asks the user to input any arbitrary N numbers and  Adds and Subtracts it . Solution: /* Adding N numbers */ #include<stdio.h> int main ( void ) {     int n, sum=0, sub=0,mul=0, c, value;     printf ( "Enter the number of integers you want to add\n" );     scanf ("%d" , & n );     printf ( "Enter %d integers\n" , n );     for (c = 1 ;c<=n; c++) {         scanf ( "%d" , & value );         sum = sum + value ; /*adding each no in sum */         sub = value-sub ;     }     printf ( "Sum of entered Integers =%d\n" , sum );     printf ( "Difference  of entered Integers=%d\n" , sub );     return 0 ; }

Averaging Score

Image
A class of 20 students took a quiz; the grades ranging from 0 to 100 for the quiz are made available to you, You are asked to write a program to calculate the average on the quiz Hints The Class average is equal to the sum of the grades divided by the number of students. The algorithm for solving this problem on a computer must input each grade, keep track of the total of all grades input, perform the averaging calculation and print the result. First of all we will need to use the pseudo code to list the actions to execute and specify the order in which these actions should execute. Pseudo code is an artificial and informal language that helps you develop algorithms. It’s useful for developing algorithms that will be converted to structured C programs. They are not executed on computers; rather, they merely help you “think out” a program before attempting to write it in a programming language such as C. pseudo code consists purely consists purely of characters Pse...

C Program Arithmetic

Image
Write a program that asks the user to enter five numbers obtains them from the user     and prints their sum, product, difference, quotient and remainder Solution #include<stdio.h> #include<stdlib.h> /*function main begins program execution */ int main ( void ) {     int a,b,c,d,e; /* numbers to be entered by user */     printf( "Input Five Integers:" ); /*prompting command for user */     scanf( "%d%d%d%d%d" , & a, & b, & c, & d, & e);     /*Output Results */     printf( "Sum is:%d\n" ,a + b + c + d + e); /* \n means new line */     printf( "Product is:%d\n" , a * b * c * d * e);     printf( "Difference is:%d\n" , a - b - c - d - e);     printf( "Division is:%d\n" , a / b / c / d / e);     printf( "Remainder is:%d\n" , a % b % c % d % e);  ...