You are on page 1of 3

INPUT AND OUTPUT STATEMENT

1.We can store string in two dimensional character array in three ways:-
A.Direct initialisation B.Assignment C.Through keyboard(stdin)
A.Direct initialisation is a way/method/technique in which string can be initialise in all rows at a time
using the syntax given below:-
char array_name[row][col]={{“string1”},{“string2”},{“string3”}};
char array_name[row][col]={{‘s’,’t’,’r’,’i’,’n’,’g’,’\0’},{‘s’,’t’,’r’,’i’,’n’,’g’,’2’,’\0’}};
B.Assignment:-We can assign string string in two dim.character array character by character in the
fillowing format:-
Syn:-array_name[r][c]=’c’;
C.Through keyboard:-In two dimensional character array any statement written in the form of
array_name[index] is internally interpreted by compiler as follows:-
(array_name+index*total nos of column),which gives the base address of each row from where string expand
till ‘\0’ is not assigned.
Syn:-for(r=0;r<r_size;r++)
{
printf(“Enter string no.%d:-”,r+1);
gets(array_name[r]);
//(arrayname+r*nos.of columns); input:-for(r=0;r<r_size;r++)
{
printf(“Enter the string %d:-”,r+1);
gets(arrayname[r]);
}
Output:-We can print the value stored in two dimensional array in two ways:-
1.Complete string once 2.Character by character
1.To print the string stored in two dimensional array, use format specifier %s with library function printf( ) in
the following format.
for(r-0;r<row_size;r++)
printf(“\n%s”,arrayname[r]);
2.To printf the string stored in two dimensional array, use the format specifier %c with arrayname followed by
row and column index respectively with library function printf( ) in the following format:-
for(r=0;r<r_size;r++)
{
printf(“\n”);
for(c=0;array_name[r][c]!=’\0’,c++)
printf(“%c”,array_name[r][c]);
}
Ques:-1.Wap in c to enter month name in two dim.character array and print the same.
Ques:-2.Wap in c to enter weekday and print the same.
Ques:-3Wap in c to enter month name and print the each month in the ffollowing format:-
Length of month january:-7
Length of month february:-8
---------------------------
Length of month december:-8
Ques:-4.Wap in c to initialise weekday,calculate and print the length of each weekday in the
following format:-
Length of weekday SUNDAY=6
----------------------------------
Length of weekday SATURDAY=81.//complete string once
#include<stdio.h>
#include<conio.h>
void main() {
char month[12][10];
int r;
clrscr();
printf(“Please enter the month name:\n”);
for(r=0;r<12;r++) {
printf(“Enter the month %d:-”,r+1);
gets(month[r]); }
clrscr();
printf(“The month you entered is given below:”);
for(r=0;r<12;r++)
printf(“\n%s”,month[r]);
getch(); }
//character by character
#include<stdio.h>
#include<conio.h>
void main( ) {
char month[12][10];
int r,c;
clrscr();
printf(“Please enter the month name:\n”);
for(r=0;r<12;r++) {
printf(“Enter the month %d:-”,r+1);
gets(month[r]); }
clrscr();
printf(“The month you entered is given below:”);
for(r=0;r<12;r++) {
printf(“\n”);
for(c=0;month[r][c]!=’\0';c++)
printf(“%c”,month[r][c]); }
getch(); }
2.
//PRINT WEEKDAY COMPLETE ONCE.
#include<stdio.h>
#include<conio.h>
void main() {
char wday[7][10];
int r;
clrscr();
for(r=0;r<7;r++) {
printf(“Enter the week_day %d:-”,r+1);
scanf(“%s”,&wday[r]); }
printf(“\nThe days of week is given below:”);
for(r=0;r<7;r++)
printf(“\n%s”,wday[r]);
getch(); }

//PRINT WEEKDAY CHARACTER BY CHARACTER


#include<stdio.h>
#include<conio.h>
void main() {
char wday[7][10];
int r,c;
clrscr();
for(r=0;r<7;r++) {
printf(“Enter the week_day %d:-”,r+1);
scanf(“%s”,&wday[r]); }
printf(“\nThe days of week is given below:”);
for(r=0;r<7;r++){
printf(“\n”);
for(c=0;wday[r][c]!=’\0';c++)
printf(“%c”,wday[r][c]); }
getch(); }

3.#include<stdio.h>
#include<conio.h>
void main() {
char month[12][10];
int r,c;
clrscr();
printf(“Please enter the month name:\n”);
for(r=0;r<12;r++) {
printf(“Enter the month %d:-”,r+1);
gets(month[r]); }
clrscr();
printf(“The month you entered is given below:”);
for(r=0;r<12;r++) {
for(c=0;month[r][c]!=’\0';c++);
printf(“\nThe length of the month %s=%d”,month[r],c); }
getch(); }
4.#include<stdio.h>
#include<conio.h>
void main()
{
char wday[7][10]={{“Sunday”},{“Monday”},{“Tuesday”},{“Wednesday”},{“Thursday”},{“Friday”},
{“Saturday”}};
int r,c;
clrscr();
printf(“The weekday you entered is given below:”);
for(r=0;r<7;r++)
{
for(c=0;wday[r][c]!=’\0';c++);
printf(“\nThe length of the week day %s=%d”,wday[r],c);
}
getch();
}

You might also like