CJ3 1
CJ3 1
Ansh Shivhare
0801IT221152
AB22G090
QUESTION 1.Write a program using if-else that takes a 3-digit integer as input and find:
Source code
#include <stdio.h>
int main()
int num;
scanf("%d", &num);
int sum = 0;
temp /= 10;
}
ASSIGNMENT 2
Ansh Shivhare
0801IT221152
AB22G090
else
return 0;
Output
Source code
#include <stdio.h>
int main()
int num;
scanf("%d", &num);
int sum = 0;
else
return 0;
Output
QUESTION 2 Write a program that determines a student’s grade. The program will read three scores and
SOURCE CODE
#include <stdio.h>
ASSIGNMENT 2
Ansh Shivhare
0801IT221152
AB22G090
int main()
double average;
char grade;
scanf("%lf", &score1);
scanf("%lf", &score2);
scanf("%lf", &score3);
grade = 'A';
grade = 'B';
grade = 'C';
}
ASSIGNMENT 2
Ansh Shivhare
0801IT221152
AB22G090
grade = 'D';
else
grade = 'F';
printf("The average score is %.2f and the grade is %c\n", average, grade);
return 0;
Output
QUESTION 3 . Write a C program using if-else and switch to accept a character from the keyboard and
print ‘A Vowel’ if it is a vowel otherwise prints ‘A Consonant’.
Source code
ASSIGNMENT 2
Ansh Shivhare
0801IT221152
AB22G090
#include <stdio.h>
int main()
char ch;
scanf("%c", &ch);
if ((ch >= 'A' && ch <= 'Z') || (ch >= 'a' && ch <= 'z'))
switch (ch)
case 'A':
case 'E':
case 'I':
case 'O':
case 'U':
printf("vowel\n");
break;
case 'a':
case 'e':
case 'i':
case 'o':
case 'u':
printf("vowel\n");
ASSIGNMENT 2
Ansh Shivhare
0801IT221152
AB22G090
break;
default:
printf("consonant\n");
else
return 0;
Output
QUESTION 4 An Internet Service Provider company charges its domestic customers as follows:
201 - 400 Rs. 150 plus Rs. 0.15 per unit if exceed 200
ASSIGNMENT 2
Ansh Shivhare
0801IT221152
AB22G090
401 - 600 Rs. 270 plus Rs. 0.60 per unit if exceed 400
and above Rs. 425 plus Rs. 0.95 per unit if exceed 600
The program reads the data usage consumed and prints the amount to be paid by the customer.
Implement using if-else and switch.
Source code
#include <stdio.h>
int main()
int usage;
float charge;
scanf("%d", &usage);
{
ASSIGNMENT 2
Ansh Shivhare
0801IT221152
AB22G090
else
case 0:
break;
case 1:
break;
case 2:
break;
default:
break;
return 0;
Output
QUESTION 5. Write a program to convert number into roman number. Roman letters will be written in
the combinations of seven letters.
Source code
#include <stdio.h>
char *symbols[] = {"M", "CM", "D", "CD", "C", "XC", "L", "XL", "X", "IX", "V", "IV", "I"};
int values[] = {1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1};
{
ASSIGNMENT 2
Ansh Shivhare
0801IT221152
AB22G090
printf("%s", symbols[i]);
num -= values[i];
printf("\n");
int main()
int num;
scanf("%d", &num);
return -1;
convertToRoman(num);
ASSIGNMENT 2
Ansh Shivhare
0801IT221152
AB22G090
return 0;
Output