Program To Count The Number of Digits
Program To Count The Number of Digits
Q. C program to find the sum of first and last digit of a given num
#include <stdio.h>
int main()
{
int num, sum=0, firstDigit, lastDigit;
/* Find the first digit by dividing num by 10 until first digit is left */
while(num >= 10)
{
num = num / 10;
}
firstDigit = num;
/* Find sum of first and last digit*/
sum = firstDigit + lastDigit;
return 0;
}
getch();
}
Q.. Inverted full pyramid of *
* * * * * * * * *
* * * * * * *
* * * * *
* * *
*
#include <stdio.h>
#include<conio.h>
void main() {
int rows, i, j, space;
clrscr();
printf("Enter the number of rows: ");
scanf("%d", &rows);
for (i = rows; i >= 1; --i) {
for (space = 0; space < rows - i; ++space)
printf(" ");
for (j = i; j <= 2 * i - 1; ++j)
printf("* ");
for (j = 0; j < i - 1; ++j)
printf("* ");
printf("\n");
}
getch();
}
#include<stdio.h>
int main()
{
int n,i;
float sum=0.0;
for(i=1;i<=n;i++)
{
sum+=(1.0/i); //sum = sum + 1.0/i
}
return 0;
}