#include <stdio.h>
#include <conio.h>
void main()
{
int n, i, sum = 0;
clrscr();
printf(" Enter any number: " );
scanf(" %d ", &n);
for(i = 1; i<n; i = i + 2 )
{
printf(" %d + ", i);
sum = sum + i;
}
printf(" %d ", n);
printf(" \nSum = %d ", sum + n );
getch();
}
OUTPUT:
Enter any number: 9
1 + 3 + 5 + 7 + 9
Sum = 25
Sample C Program To Print A Star Pyramid.
#include <stdio.h>
#include <conio.h>
void main()
{
int row, c, n, temp;
printf(" Enter the number of rows in pyramid of stars you wish to see: ");
scanf(" %d ", &n);
temp = n;
for ( row = 1 ; row <= n ; row++ )
{
for ( c = 1 ; c < temp ; c++ )
printf(" ");
temp--;
for ( c = 1 ; c <= 2 * row - 1 ; c++ )
printf(" * ");
printf(" \n ");
}
getch();
return 0;
}
OUTPUT:
Enter the number of rows in pyramid of stars you wish to see 5
*
***
*****
*******
*********
ALSO READ:
-- Program To Print First Ten(10) Natural Numbers.
-- Program To Print Fibonacci Series Upto 100.
-- Program To Check Whether A Number Is Prime Or Not.
-- Program To Compute The Reverse Of A Number.
-- Program To Print A Semicolon Without Using A Semicolon.
-- Program To Display Function Without Using The Main Function.
-- Program To Print Any Print Statement Without Using Semicolon.
-- Program To Display Its Own Source Code As Its Output.
-- Program To Swap Two Strings Using strcpy() Function.
-- Program to accept a string and print the reverse of the given string.
-- Program To Get IP Address.
-- Program To Accept An Integer & Reverse It.
-- Program To Convert Given Number Of Days To A Measure Of Time Given In Years, Weeks & Days.
-- Program To Illustrate The Concept Of Unions.
-- Program To Find The Size Of A Union.
... Back To C++ Programs Index
... Back To C++ FAQ's Index
... Back To C Programs Index
... Back To C FAQ's Index
... Back To HR Interview Index
Comments
Post a Comment
Please share your opinions and suggestions or your experience in the comments section. This way we can all help each other...
Experienced guys can share their resumes at admin@interview-made-easy.com