Homework Loops 3
Homework Loops 3
Homework Loops 3
1
22
333
4444
#include <stdio.h>
int main() {
for(int i=1;i<=4;i++)
{
for(int j=0;j<i;j++)
{
printf("%d",i);
}
printf("\n");
}
return 0;
}
#include <stdio.h>
int main() {
float n,b=0,i;
scanf("%f",&n);
for(i=1;i<=n;i++)
{
b=b+(1/i);
printf("%f",b);
return 0;
3.Write a program in C to display the n terms of square natural number and their
sum.
#include <stdio.h>
int main() {
int n,b=0,c,i;
printf("Enter value of n ");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
c=i*i;
b=b+c;
printf("%d^2 is %d\n",i,c);
}
printf("The sum is %d",b);
return 0;
}
#include <stdio.h>
void main()
{
int no_row,c=1,blk,i,j;
printf("Input number of rows: ");
scanf("%d",&no_row);
for(i=0;i<no_row;i++)
{
for(blk=1;blk<=no_row-i;blk++)
printf(" ");
for(j=0;j<=i;j++)
{
if (j==0||i==0)
c=1;
else
c=c*(i-j+1)/j;
printf("% 4d",c);
}
printf("\n");
}
}
5. Write a program in C to find the number and sum of all integer between
100 and 200 which are divisible by 9.
#include <stdio.h>
void main()
{
for(int j=100;j<200;j++)
{
if (j%9==0)
printf("%d ",j);;
}
}
#include <stdio.h>
void main()
{
int a,b,c=0,j;
printf("Enter two numbers ");
scanf("%d%d",&a,&b);
for(j=a;j>=a;j--)
{
if((a%j==0)&&(b%j==0))
{
break;
}
}
printf("%d is hcf of %d and %d",j,a,b);
}
#include <stdio.h>
void main()
{
int a,n,d,f;
printf("Enter a number ");
scanf("%d",&a);
n=a;
while(n>0)
{
d=n%10;
n=n/10;
f=f+d*d*d;
}
if(a==f)
printf("The number is Armstrong Number");
else
printf("The number is not an Armstrong Number");
}
8.#include
<stdio.h> int
main()
{
int i = 1024;
for (; i; i >>= 1)
printf("Quiztime");
return 0;
}
How many times will “Quiztimebe” printed in the above program?
It will be printed 11 times.
9.#include<stdio
#include <stdio.h>
void main()
{
int a,n,d=1;
printf("Enter a number and its power ");
scanf("%d%d",&a,&n);
for(int i=1;i<=n;i++)
{
d=d*a;
}
printf("%d",d);
}
11.C program to convert Octal to Hexadecimal number system
#include <stdio.h>
void main()
{
int d;
printf("Enter a octal number ");
scanf("%o",&d);
printf("Its hexadecimal number is %x",d);
}