1- Wap to print all the number from 1 to 10 ?
#include <stdio.h>
#include<conio.h>
void main()
{
int i;
clrscr();
for(i=1; i<=10; i++)
{
printf(“n%d” &i);
}
getch();
}
2- Wap to print all the number from 1 to 20 ?
#include <stdio.h>
#include<conio.h>
void main()
{
Int i;
clrscr();
for(i=1; i<=20; i++)
{
printf(“n%d” &i);
}
getch();
}
3- Wap to print all the number from 5 to 15 ?
#include <stdio.h>
#include<conio.h>
void main()
{
int i;
clrscr();
for(i=5; i<=15; i++)
{
printf(“n%d” &i);
}
getch();
}
4- Wap to accept the number from user that is n then print all number from 1 to n?
#include <stdio.h>
#include<conio.h>
void main()
{
int i;
clrscr();
printf(“enter a number”);
scan(“%d”, &n);
for(i=1; i<=n; i++)
{
printf(“n%d” &i);
}
getch();
}
5- Wap to print the sum of all the number from 1 to 5 ?
#include <stdio.h>
#include<conio.h>
void main()
{
int I, sum=0;
clrscr();
for(i=1; i<=5; i++)
{
sum=sum+i;
}
printf(“sum is %d”, sum);
getch();
}
6- Wap to accept a number from user then calculate the sum of all the number from 1 to n and print a number.
#include <stdio.h>
#include<conio.h>
void main()
{
int i, sum=0;
clrscr();
printf(“enter a number”);
scan(“%d”, &n);
for(i=1; i<=n; i++)
{
sum=sum+i;
}
printf(“sum is %d”, sum);
getch();
}
7- Wap to accept a number from user then print all the even number from 1 to n.
#include <stdio.h>
#include<conio.h>
void main()
{
int n, i;
clrscr();
printf(“enter a number”);
scan(“%d”, &n);
for(i=2; i<=n; i++)
{
printf(“\n%d”, i);
i=i+1;
}
getch();
}
8- Wap to accept a number from user then print sum of all the even number between 1 to n?
#include <stdio.h>
#include<conio.h>
void main()
{
int n, i, sum=0;
clrscr();
printf(“enter a number”);
scan(“%d”, &n);
for(i=1; i<=n; i++)
if (i%2==0)
{
sum=sum+i;
}
printf(sum is %d”, sum);
getch();
}
9-Wap to accept a number from user then print the sum of all the number from 1 to n and average of number from 1 to n?
#include <stdio.h>
#include<conio.h>
void main()
{
int n, i, sum=0,avg;
clrscr();
printf(“enter a number”);
scan(“%d”, &n);
for(i=1; i<=n; i++)
if (i%2==0)
{
sum=sum+i;
}
if=sum/n;
printf(“sum of number is %d”, sum);
printf(“average is %d”, avg);
getch();
}
10- Wap to print all the number from 1 to 10?
#include <stdio.h>
#include<conio.h>
void main()
{
int i;
clrscr();
for (i=10; i>=i; i--)
{
printf(“%d”, i);
}
getch();
}
11- Wap to accept a number from user that is n then print all the number from n to 1?
#include <stdio.h>
#include<conio.h>
void main()
{
int n,i;
clrscr();
printf(“enter a number”);
scan(“%d”, &n);
for (i=n; i>=1; i--)
{
printf(“%d”, i);
}
getch();
}
12- Wap to accept a number from user that is n then print all the odd number from n to 1?
#include <stdio.h>
#include<conio.h>
void main()
{
int n,i;
clrscr();
printf(“enter a number”);
scan(“%d”, &n);
for (i=n; i>=1; i--)
{
printf(“%d”, i);
i=i-2;
}
getch();
}
No comments:
Post a Comment