11 1
11 1
#include <stdio.h>
#include <stdlib.h>
int main()
{
int i;
int upper=0,lower=0;
char ch[100];
printf("Enter the String:\n");
gets(ch);
for(i=0; ch[i]!=0; i++){
if(ch[i]>='A' && ch[i]<='Z'){
upper++;
}
else if(ch[i]>='a' && ch[i]<='z'){
lower++;
}
}
printf("lowercase letters: %d",lower);
printf("\nuppercase letters: %d",upper);
getch();
return 0;
}
2)ARMSTRONG
#include<stdio.h>
int main()
{
int n,r,sum=0,temp;
printf("enter the number=");
scanf("%d",&n);
temp=n;
while(n>0)
{
r=n%10;
sum=sum+(r*r*r);
n=n/10;
}
if(temp==sum)
printf("armstrong number ");
else
printf("not armstrong number");
return 0;
}
3)BINARY TO DECIMAL
#include <stdio.h>
#include <conio.h>
void main()
{
// declaration of variables
int num, binary_num, decimal_num = 0, base = 1, rem;
printf (" Enter a binary number with the combination of 0s and 1s \n");
scanf (" %d", &num);
binary_num = num;
while ( num > 0)
{
rem = num % 10;
decimal_num = decimal_num + rem * base;
num = num / 10;
base = base * 2;
}
4)AVERAGE MARKS
#include <stdio.h>
#include <stdlib.h>
int main()
{
int m1,m2,m3;
float avg;
printf("Enter marks for 3 subjects\n");
scanf("%d%d%d",&m1,&m2,&m3);
if(((m1>=0)&&(m1<=100))&&(((m2>=0)&&(m2<=100)))&&((m3>=0)&&(m3<=100)))
{
avg=(m1+m2+m3)/3.0;
printf("Average marks of %d, %d and %d is %0.2f",m1,m2,m3,avg);
}
else
{
printf("Marks must be in between 0 and 100");
}
return 0;
}
5)EVEN OR ODD
#include <stdio.h>
int main() {
int num;
printf("Enter an integer: ");
scanf("%d", &num);
return 0;
}
6)SWAPING
#include <stdio.h>
int main() {
int num;
printf("Enter an integer: ");
scanf("%d", &num);
return 0;
}
7)Pattern
#include <stdio.h>
int main() {
int i, j, rows;
printf("Enter the number of rows: ");
scanf("%d", &rows);
for (i = 1; i <= rows; ++i) {
for (j = 1; j <= i; ++j) {
printf("* ");
}
printf("\n");
}
return 0;
}
O/P:-
*
* *
* * *
* * * *
* * * * *
8)REVERSE PATTERN
#include <stdio.h>
int main() {
int i, j, rows;
printf("Enter the number of rows: ");
scanf("%d", &rows);
for (i = rows; i >= 1; --i) {
for (j = 1; j <= i; ++j) {
printf("* ");
}
printf("\n");
}
return 0;
}
9)PYRAMID
#include <stdio.h>
int main() {
int i, space, rows, k = 0;
printf("Enter the number of rows: ");
scanf("%d", &rows);
for (i = 1; i <= rows; ++i, k = 0) {
for (space = 1; space <= rows - i; ++space) {
printf(" ");
}
while (k != 2 * i - 1) {
printf("* ");
++k;
}
printf("\n");
}
return 0;
}