WAP, Write a Program to find number of & sum of all integers greater than 100 & less than 200 that are divisible by 7 with output
Program
#include<stdio.h>
#include<conio.h>
void main()
{
int i, count=0, sum=0;
clrscr();
for (i=101; i<200; i++)
{
if (i%7 = =0)
{
count = count + 1;
sum=sum + i;
}
}
printf("Sum is:%d\n", sum);
scanf("Count is:%d", count);
getch();
}
Output
Sum is: 2107
count is: 14
Changes for C++
If you want to write the same program in c++ apply the following changes to the program.
1.) change the header file from "#include<stdio.h>" to "#include<iostream>.h"
2.) for input & output use "cout<<" & "cin>>" instead of "printf" & "scanf".
3.) don't use "% "symbol and "&" sign in "cin>>" statement.
Program
#include<stdio.h>
#include<conio.h>
void main()
{
int i, count=0, sum=0;
clrscr();
for (i=101; i<200; i++)
{
if (i%7 = =0)
{
count = count + 1;
sum=sum + i;
}
}
printf("Sum is:%d\n", sum);
scanf("Count is:%d", count);
getch();
}
Output
Sum is: 2107
count is: 14
Changes for C++
If you want to write the same program in c++ apply the following changes to the program.
1.) change the header file from "#include<stdio.h>" to "#include<iostream>.h"
2.) for input & output use "cout<<" & "cin>>" instead of "printf" & "scanf".
3.) don't use "% "symbol and "&" sign in "cin>>" statement.
This site is really helpful for students
ReplyDelete